-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix: arrow/async in conditional expressions for TS #17572
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
base: main
Are you sure you want to change the base?
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60120 |
| if (!this.eat(tt.colon)) { | ||
| state.noArrowAt = this.state.noArrowAt; | ||
| if (state.noArrowAt.length <= 3) { | ||
| state.noArrowAt = [state.noArrowAt[0]]; | ||
| } else { | ||
| state.noArrowAt = state.noArrowAt.slice(3); | ||
| } | ||
| this.state = state; | ||
| node.consequent = this.parseMaybeAssignAllowIn(); | ||
| this.expect(tt.colon); | ||
| } |
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 was inspired by the Flow plugin, thanks to @nicolo-ribaudo.
The current implementation doesn't look reliable at all, but it passes all the tests.🤦♂️
If we try them one by one, it will be more reliable, but slower.
|
commit: |
| @@ -0,0 +1 @@ | |||
| true ? async (): 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.
Although it is valid JavaScript, tsc does not support it either:
https://www.typescriptlang.org/play/?#code/C4JwrgpgBA-FCGBnAngOwMZQBQEoBcUokA3EA
Could we skip this test temporarily and enable it when we align to the tsc behaviour?
nicolo-ribaudo
left a comment
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.
I don;t love this, but it looks ok. It'd be great to see some benchmarks, but we should prioritize correctness over performance anyway.
I initially tried to port the TS implementation, but failed.
Maybe I should try again.