From f44c93add2e190a66640548cb1a093d47eb128a6 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Wed, 29 Apr 2015 17:55:26 -0400 Subject: [PATCH] fix reference check for shorthand properties --- src/babel/types/validators.js | 3 ++- .../spec.function-name/assignment/expected.js | 14 ++++++++++++-- .../undeclared-shorthand-property/exec.js | 1 + .../undeclared-shorthand-property/options.json | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/exec.js create mode 100644 test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/options.json diff --git a/src/babel/types/validators.js b/src/babel/types/validators.js index 2c57deac1d..13be3caa8e 100644 --- a/src/babel/types/validators.js +++ b/src/babel/types/validators.js @@ -26,10 +26,11 @@ export function isReferenced(node: Object, parent: Object): boolean { return false; // yes: { [NODE]: "" } + // yes: { NODE } // no: { NODE: "" } case "Property": if (parent.key === node) { - return parent.computed; + return parent.computed || parent.shorthand; } // no: var NODE = init; diff --git a/test/core/fixtures/transformation/spec.function-name/assignment/expected.js b/test/core/fixtures/transformation/spec.function-name/assignment/expected.js index 3c4aa618fd..b1083c7cc8 100644 --- a/test/core/fixtures/transformation/spec.function-name/assignment/expected.js +++ b/test/core/fixtures/transformation/spec.function-name/assignment/expected.js @@ -14,9 +14,19 @@ var i = (function (_i) { i = 5; }); -var j = function j() { +var j = (function (_j) { + function j() { + return _j.apply(this, arguments); + } + + j.toString = function () { + return _j.toString(); + }; + + return j; +})(function () { var _ = 5; j = _.j; ; -}; +}); diff --git a/test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/exec.js b/test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/exec.js new file mode 100644 index 0000000000..ee11821ed0 --- /dev/null +++ b/test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/exec.js @@ -0,0 +1 @@ +({foo}) diff --git a/test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/options.json b/test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/options.json new file mode 100644 index 0000000000..a661ffc703 --- /dev/null +++ b/test/core/fixtures/transformation/validation.undeclared-variable-check/undeclared-shorthand-property/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Reference to undeclared variable" +}