From 320a39f4c4a5c63641689c05251e2fc2998907e7 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 5 Apr 2015 02:52:14 +1000 Subject: [PATCH] fix computed properties in es7 object rest/spread - thanks @AluisioASG! --- src/babel/transformation/transformers/es6/destructuring.js | 2 +- .../transformation/es6.destructuring/es7-object-rest/actual.js | 1 + .../es6.destructuring/es7-object-rest/expected.js | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index 48d7e16c09..510eebfee7 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -332,7 +332,7 @@ class DestructuringTransformer { if (t.isSpreadProperty(prop)) continue; var key = prop.key; - if (t.isIdentifier(key)) key = t.literal(prop.key.name); + if (t.isIdentifier(key) && !prop.computed) key = t.literal(prop.key.name); keys.push(key); } diff --git a/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/actual.js b/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/actual.js index 7c3ed3f0b6..a0fd177921 100644 --- a/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/actual.js +++ b/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/actual.js @@ -1,4 +1,5 @@ var z = {}; var { ...x } = z; var { x, ...y } = z; +var { [x]: x, ...y } = z; (function({ x, ...y }) { }) diff --git a/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/expected.js b/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/expected.js index 50c04d383a..a8aaeee8f7 100644 --- a/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/expected.js +++ b/test/core/fixtures/transformation/es6.destructuring/es7-object-rest/expected.js @@ -4,6 +4,8 @@ var z = {}; var x = babelHelpers.objectWithoutProperties(z, []); var x = z.x; var y = babelHelpers.objectWithoutProperties(z, ["x"]); +var x = z[x]; +var y = babelHelpers.objectWithoutProperties(z, [x]); (function (_ref) { var x = _ref.x;