From 8d3a7acbd1ab1b60744964bd25cef22c24b7d04c Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 16 Mar 2015 02:00:10 +1100 Subject: [PATCH] add symbol check to defineProperty helper - fixes #1010 --- .../transformation/templates/define-property.js | 2 +- .../argument/expected.js | 4 +--- .../assignment/expected.js | 4 +--- .../es6-properties.computed/method/expected.js | 6 ++---- .../es6-properties.computed/mixed/expected.js | 17 +++++------------ .../multiple/expected.js | 11 +++-------- .../es6-properties.computed/options.json | 3 +++ .../es6-properties.computed/single/expected.js | 4 +--- .../es6-properties.computed/this/expected.js | 4 +--- .../es6-properties.computed/two/expected.js | 6 ++---- .../variable/expected.js | 4 +--- .../method-computed/expected.js | 6 ++---- .../method-computed/options.json | 3 +++ 13 files changed, 26 insertions(+), 48 deletions(-) create mode 100644 test/fixtures/transformation/es6-properties.computed/options.json create mode 100644 test/fixtures/transformation/es6-properties.shorthand/method-computed/options.json diff --git a/src/babel/transformation/templates/define-property.js b/src/babel/transformation/templates/define-property.js index dca42eeabb..c7587d180a 100644 --- a/src/babel/transformation/templates/define-property.js +++ b/src/babel/transformation/templates/define-property.js @@ -1,7 +1,7 @@ (function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, - enumerable: true, + enumerable: key == null || typeof Symbol == "undefined" || key.constructor !== Symbol, configurable: true, writable: true }); diff --git a/test/fixtures/transformation/es6-properties.computed/argument/expected.js b/test/fixtures/transformation/es6-properties.computed/argument/expected.js index 0846d43ac3..6bc0ebf221 100644 --- a/test/fixtures/transformation/es6-properties.computed/argument/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/argument/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - -foo(_defineProperty({}, bar, "foobar")); \ No newline at end of file +foo(babelHelpers.defineProperty({}, bar, "foobar")); diff --git a/test/fixtures/transformation/es6-properties.computed/assignment/expected.js b/test/fixtures/transformation/es6-properties.computed/assignment/expected.js index 0519057c40..8ec8aae33e 100644 --- a/test/fixtures/transformation/es6-properties.computed/assignment/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/assignment/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - -foo = _defineProperty({}, bar, "foobar"); \ No newline at end of file +foo = babelHelpers.defineProperty({}, bar, "foobar"); diff --git a/test/fixtures/transformation/es6-properties.computed/method/expected.js b/test/fixtures/transformation/es6-properties.computed/method/expected.js index 79dca450d3..440ed65220 100644 --- a/test/fixtures/transformation/es6-properties.computed/method/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/method/expected.js @@ -1,7 +1,5 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - -var obj = _defineProperty({}, foobar, function () { +var obj = babelHelpers.defineProperty({}, foobar, function () { return "foobar"; -}); \ No newline at end of file +}); diff --git a/test/fixtures/transformation/es6-properties.computed/mixed/expected.js b/test/fixtures/transformation/es6-properties.computed/mixed/expected.js index 35cd829c19..f8f870ed3e 100644 --- a/test/fixtures/transformation/es6-properties.computed/mixed/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/mixed/expected.js @@ -1,17 +1,10 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - var obj = (function () { var _obj = {}; - - _defineProperty(_obj, "x" + foo, "heh"); - - _defineProperty(_obj, "y" + bar, "noo"); - - _defineProperty(_obj, "foo", "foo"); - - _defineProperty(_obj, "bar", "bar"); - + babelHelpers.defineProperty(_obj, "x" + foo, "heh"); + babelHelpers.defineProperty(_obj, "y" + bar, "noo"); + babelHelpers.defineProperty(_obj, "foo", "foo"); + babelHelpers.defineProperty(_obj, "bar", "bar"); return _obj; -})(); \ No newline at end of file +})(); diff --git a/test/fixtures/transformation/es6-properties.computed/multiple/expected.js b/test/fixtures/transformation/es6-properties.computed/multiple/expected.js index 04c9c32c5d..2dda4c9afc 100644 --- a/test/fixtures/transformation/es6-properties.computed/multiple/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/multiple/expected.js @@ -1,13 +1,8 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - var obj = (function () { var _obj = {}; - - _defineProperty(_obj, "x" + foo, "heh"); - - _defineProperty(_obj, "y" + bar, "noo"); - + babelHelpers.defineProperty(_obj, "x" + foo, "heh"); + babelHelpers.defineProperty(_obj, "y" + bar, "noo"); return _obj; -})(); \ No newline at end of file +})(); diff --git a/test/fixtures/transformation/es6-properties.computed/options.json b/test/fixtures/transformation/es6-properties.computed/options.json new file mode 100644 index 0000000000..7d6e6cda1c --- /dev/null +++ b/test/fixtures/transformation/es6-properties.computed/options.json @@ -0,0 +1,3 @@ +{ + "externalHelpers": true +} diff --git a/test/fixtures/transformation/es6-properties.computed/single/expected.js b/test/fixtures/transformation/es6-properties.computed/single/expected.js index 937caa1d20..396ee17f25 100644 --- a/test/fixtures/transformation/es6-properties.computed/single/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/single/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - -var obj = _defineProperty({}, "x" + foo, "heh"); \ No newline at end of file +var obj = babelHelpers.defineProperty({}, "x" + foo, "heh"); diff --git a/test/fixtures/transformation/es6-properties.computed/this/expected.js b/test/fixtures/transformation/es6-properties.computed/this/expected.js index c8aa05c062..71edef2562 100644 --- a/test/fixtures/transformation/es6-properties.computed/this/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/this/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - -var obj = _defineProperty({}, "x" + foo.bar, "heh"); \ No newline at end of file +var obj = babelHelpers.defineProperty({}, "x" + foo.bar, "heh"); diff --git a/test/fixtures/transformation/es6-properties.computed/two/expected.js b/test/fixtures/transformation/es6-properties.computed/two/expected.js index 567304d624..86a0871d8a 100644 --- a/test/fixtures/transformation/es6-properties.computed/two/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/two/expected.js @@ -1,6 +1,4 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - -var obj = _defineProperty({ - first: "first" }, "second", "second"); \ No newline at end of file +var obj = babelHelpers.defineProperty({ + first: "first" }, "second", "second"); diff --git a/test/fixtures/transformation/es6-properties.computed/variable/expected.js b/test/fixtures/transformation/es6-properties.computed/variable/expected.js index c59c5d07b9..53abd07fc8 100644 --- a/test/fixtures/transformation/es6-properties.computed/variable/expected.js +++ b/test/fixtures/transformation/es6-properties.computed/variable/expected.js @@ -1,5 +1,3 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - -var foo = _defineProperty({}, bar, "foobar"); \ No newline at end of file +var foo = babelHelpers.defineProperty({}, bar, "foobar"); diff --git a/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js b/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js index 7973f269f7..8e53405970 100644 --- a/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js +++ b/test/fixtures/transformation/es6-properties.shorthand/method-computed/expected.js @@ -1,10 +1,8 @@ "use strict"; -var _defineProperty = function (obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); }; - var x = "y"; var valueSet; -var obj = Object.defineProperties({}, _defineProperty({}, x, { +var obj = Object.defineProperties({}, babelHelpers.defineProperty({}, x, { get: function () { return 1; }, @@ -15,4 +13,4 @@ var obj = Object.defineProperties({}, _defineProperty({}, x, { enumerable: true })); obj.y = "foo"; -obj.y === 1 && valueSet === "foo"; \ No newline at end of file +obj.y === 1 && valueSet === "foo"; diff --git a/test/fixtures/transformation/es6-properties.shorthand/method-computed/options.json b/test/fixtures/transformation/es6-properties.shorthand/method-computed/options.json new file mode 100644 index 0000000000..7d6e6cda1c --- /dev/null +++ b/test/fixtures/transformation/es6-properties.shorthand/method-computed/options.json @@ -0,0 +1,3 @@ +{ + "externalHelpers": true +}