[proposal-object-rest-spread] fix templateLiteral in extractNormalizedKeys #9628
[proposal-object-rest-spread] fix templateLiteral in extractNormalizedKeys #9628nicolo-ribaudo merged 7 commits intobabel:masterfrom pnowak:master
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10442/ |
| // since a key {a: 3} is equivalent to {"a": 3}, use the latter | ||
| keys.push(t.stringLiteral(prop.key.name)); | ||
| } else if (t.isTemplateLiteral(prop.key)) { | ||
| keys.push(t.templateLiteral(prop.key.quasis, prop.key.expressions)); |
There was a problem hiding this comment.
Since this is the same as doing t.cloneNode(prop.key), you can use that function. Note that this shouldn't set allLiteral to false (because templates are always strings), so it shouldn't be merged with the last else block.
There was a problem hiding this comment.
Do you think something like check isLiteral and not isTemplateLiteral?
| given_name: givenName, | ||
| 'last_name': lastName, | ||
| [`country`]: country, | ||
| [prefix + 'state']: state, |
There was a problem hiding this comment.
Could you also add a test without this line, so that allLiterals will be true?
There was a problem hiding this comment.
Ok, I will remove this BinaryExpression.
There was a problem hiding this comment.
Could you add this test, to test the last changes?
…without BinaryExpression #9563
| // since a key {a: 3} is equivalent to {"a": 3}, use the latter | ||
| keys.push(t.stringLiteral(prop.key.name)); | ||
| } else if (t.isLiteral(prop.key)) { | ||
| } else if (t.isLiteral(prop.key) && !t.isTemplateLiteral(prop.key)) { |
There was a problem hiding this comment.
This will set allLiterals to false for template literals, but it isn't needed.
You can do something like
| } else if (t.isLiteral(prop.key) && !t.isTemplateLiteral(prop.key)) { | |
| } else if (t.isTemplateLiteral(prop.key)) { | |
| keys.push(t.cloneNode(prop.key)); | |
| } else if (t.isLiteral(prop.key)) { |
|
I meant to create a new test, to test both the const {
given_name: givenName,
'last_name': lastName,
[`country`]: country,
[prefix + 'state']: state,
[`${prefix}consents`]: consents,
...rest
} = input;const {
given_name: givenName,
'last_name': lastName,
[`country`]: country,
...rest
} = input; |
|
Thank you! |
|
Hi @nicolo-ribaudo. |
* master: (58 commits) Remove dependency on home-or-tmp package (babel#9678) [proposal-object-rest-spread] fix templateLiteral in extractNormalizedKeys (babel#9628) Partial application plugin (babel#9474) Private Static Class Methods (Stage 3) (babel#9446) gulp-uglify@3.0.2 rollup@1.6.0 eslint@5.15.1 jest@24.5.0 regexpu-core@4.5.4 Remove input and length from state (babel#9646) Switch from rollup-stream to rollup and update deps (babel#9640) System modules - Hoist classes like other variables (babel#9639) fix: Don't transpile ES2018 symbol properties (babel#9650) Add WarningsToErrorsPlugin to webpack to avoid missing build problems on CI (babel#9647) Update regexpu-core dependency (babel#9642) Add placeholders support to @babel/types and @babel/generator (babel#9542) Generate plugins file Make babel-standalone an ESModule and enable flow (babel#9025) Reorganize token types and use a map for them (babel#9645) [TS] Allow context type annotation on getters/setters (babel#9641) ...
Added additional check in extractNormalizedKeys function to handle templates differently than string.