Fix parsing ts type casts and nested patterns in destructuring#14500
Fix parsing ts type casts and nested patterns in destructuring#14500nicolo-ribaudo merged 14 commits intobabel:mainfrom
Conversation
| expression.type, | ||
| hasParenthesizedAncestor || expression.extra?.parenthesized, | ||
| !(hasParenthesizedAncestor || expression.extra?.parenthesized) && | ||
| ancestor.type === "AssignmentExpression", |
There was a problem hiding this comment.
This code was needed to disallow a as b = c, however we must now make sure to not disallow [a as b] = c.
There was a problem hiding this comment.
Can you add a new test case?
for (a as b of []);It is disallowed in 7.16.2 but tsc allows it, and it seems this PR also fixes this one, too.
| "SyntaxError: Invalid left-hand side in assignment expression. (1:0)", | ||
| "SyntaxError: Invalid left-hand side in assignment expression. (2:6)", | ||
| "SyntaxError: Invalid left-hand side in object destructuring pattern. (2:6)" | ||
| "SyntaxError: Invalid left-hand side in assignment expression. (2:6)" |
There was a problem hiding this comment.
These two errors were at the same location.
It would be better to only keep the "object destructuring pattern" rather than "assignment expression", but it's quite complex because it requires delaying errors until we know what the outer object is (destructuring or object). I might improve it in a follow-up PR.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51815/ |
| expression.type, | ||
| hasParenthesizedAncestor || expression.extra?.parenthesized, | ||
| !(hasParenthesizedAncestor || expression.extra?.parenthesized) && | ||
| ancestor.type === "AssignmentExpression", |
There was a problem hiding this comment.
Can you add a new test case?
for (a as b of []);It is disallowed in 7.16.2 but tsc allows it, and it seems this PR also fixes this one, too.
I'm going to push a few more commits for the new comments in #14498
|
@thorn0 I would appreciate if you could check if there is any missing new test! |
|
|
|
|
|
Thanks, fixed! |
| @@ -162,11 +171,10 @@ export default class LValParser extends NodeUtils { | |||
| } | |||
|
|
|||
| case "SpreadElement": { | |||
There was a problem hiding this comment.
We can handle SpreadElement in toAssignableObjectExpressionProp and toAssignableList, so we don't need to track isInObjectPattern anymore.
| "properties": [ | ||
| { | ||
| "type": "SpreadElement", | ||
| "type": "RestElement", |
There was a problem hiding this comment.
This is a slight improvement, since it gives a better shape to the recovered AST (the input code is ({ ...rest, x } = {}).
4cbc10d to
69719e4
Compare
The function sometimes mutated its argument, sometimes it returned a new node. However, almost all usages didn't handle the "new node" case: this commit removes it, and the function always mutates its argument.
72cc585 to
8be7c27
Compare
Uh oh!
There was an error while loading. Please reload this page.