-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw errors for invalid left-hand side assignment #10416
Conversation
This is valid TypeScript. Looks like a bug in Babel. Prettier pr-10416 --parser babel-ts Input: (a as b) = c; Output: SyntaxError: Invalid parenthesized assignment pattern (1:1)
> 1 | (a as b) = c;
| ^ |
4 | | ||
> 5 | (this.configuration as any) = (this.editor as any) = (this | ||
| ^ | ||
6 | .editorBody as any) = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird. Babel supports this since long ago: babel/babel#7098
Why do we get an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out this is because of createParenthesizedExpressions: true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened babel/babel#12932
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disabling createParenthesizedExpressions
for babel-ts
is a solution.
# Conflicts: # src/language-js/parser-babel.js
Oops. This shouldn't parse: Prettier pr-10416 --parser babel-ts Input: a as any = x; Output: (a as any) = x; |
This should parse, but Prettier breaks it (AST isn't aligned with typescript-estree): Prettier pr-10416 --parser babel-ts Input: [a as any] = x; Output: [a: any] = x; |
Shouldn't parse. Prettier pr-10416 --parser babel-ts Input: ({a: b as any = 2} = x); Output: ({ a: b as any = 2 } = x); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The things I found are all separate issues in Babel or Prettier. This PR is good.
I opened babel/babel#13070 and #10635.
Description
Fixes #10412
Checklist
docs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨