[proposal-object-rest-spread] fix templateLiteral in extractNormalizedKeys (#9628)

Added additional check in extractNormalizedKeys function to handle templates differently than string.
This commit is contained in:
piotr 2019-03-13 21:39:50 +01:00 committed by Nicolò Ribaudo
parent 29cd27b545
commit a64bf63639
5 changed files with 39 additions and 0 deletions

View File

@ -76,6 +76,8 @@ export default declare((api, opts) => {
if (t.isIdentifier(prop.key) && !prop.computed) { if (t.isIdentifier(prop.key) && !prop.computed) {
// since a key {a: 3} is equivalent to {"a": 3}, use the latter // since a key {a: 3} is equivalent to {"a": 3}, use the latter
keys.push(t.stringLiteral(prop.key.name)); keys.push(t.stringLiteral(prop.key.name));
} else if (t.isTemplateLiteral(prop.key)) {
keys.push(t.cloneNode(prop.key));
} else if (t.isLiteral(prop.key)) { } else if (t.isLiteral(prop.key)) {
keys.push(t.stringLiteral(String(prop.key.value))); keys.push(t.stringLiteral(String(prop.key.value)));
} else { } else {

View File

@ -0,0 +1,10 @@
const input = {};
const {
given_name: givenName,
'last_name': lastName,
[`country`]: country,
[prefix + 'state']: state,
[`${prefix}consents`]: consents,
...rest
} = input;

View File

@ -0,0 +1,12 @@
const input = {};
const _ref = prefix + 'state',
_ref2 = `${prefix}consents`,
{
given_name: givenName,
'last_name': lastName,
[`country`]: country,
[_ref]: state,
[_ref2]: consents
} = input,
rest = babelHelpers.objectWithoutProperties(input, ["given_name", "last_name", `country`, _ref, _ref2].map(babelHelpers.toPropertyKey));

View File

@ -0,0 +1,8 @@
const input = {};
const {
given_name: givenName,
'last_name': lastName,
[`country`]: country,
...rest
} = input;

View File

@ -0,0 +1,7 @@
const input = {};
const {
given_name: givenName,
'last_name': lastName,
[`country`]: country
} = input,
rest = babelHelpers.objectWithoutProperties(input, ["given_name", "last_name", `country`]);