From 343c2bbdc532de4b9980fe7a463d060464b2bf03 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Fri, 24 May 2019 06:03:27 +0800 Subject: [PATCH] fix destructuring rest with template literal (#10013) * fix destructuring rest with template literal * update test --- src/index.js | 2 ++ test/fixtures/destructuring/issue-9834/input.js | 10 ++++++++++ test/fixtures/destructuring/issue-9834/output.js | 10 ++++++++++ 3 files changed, 22 insertions(+) create mode 100644 test/fixtures/destructuring/issue-9834/input.js create mode 100644 test/fixtures/destructuring/issue-9834/output.js diff --git a/src/index.js b/src/index.js index 4213aa5517e9..04cb37b4afa9 100644 --- a/src/index.js +++ b/src/index.js @@ -203,6 +203,8 @@ export default declare((api, options) => { const key = prop.key; if (t.isIdentifier(key) && !prop.computed) { keys.push(t.stringLiteral(key.name)); + } else if (t.isTemplateLiteral(prop.key)) { + keys.push(t.cloneNode(prop.key)); } else if (t.isLiteral(key)) { keys.push(t.stringLiteral(String(key.value))); } else { diff --git a/test/fixtures/destructuring/issue-9834/input.js b/test/fixtures/destructuring/issue-9834/input.js new file mode 100644 index 000000000000..66679d7f052d --- /dev/null +++ b/test/fixtures/destructuring/issue-9834/input.js @@ -0,0 +1,10 @@ +const input = {}; + +const { + given_name: givenName, + 'last_name': lastName, + [`country`]: country, + [prefix + 'state']: state, + [`${prefix}consents`]: consents, + ...rest +} = input; diff --git a/test/fixtures/destructuring/issue-9834/output.js b/test/fixtures/destructuring/issue-9834/output.js new file mode 100644 index 000000000000..a830257bda3c --- /dev/null +++ b/test/fixtures/destructuring/issue-9834/output.js @@ -0,0 +1,10 @@ +var input = {}; + +var _ref = prefix + 'state', + _ref2 = `${prefix}consents`, + givenName = input.given_name, + lastName = input['last_name'], + country = input[`country`], + state = input[_ref], + consents = input[_ref2], + rest = babelHelpers.objectWithoutProperties(input, ["given_name", "last_name", `country`, _ref, _ref2].map(babelHelpers.toPropertyKey));