Skip to content

Conversation

@liuxingbaoyu
Copy link
Member

Q                       A
Fixed Issues? Fixes #17547
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass?
Documentation PR Link
Any Dependency Changes?
License MIT

I initially tried to port the TS implementation, but failed.
Maybe I should try again.

@liuxingbaoyu liuxingbaoyu changed the title fix: arrows/async in conditional expressions for TS fix: arrow/async in conditional expressions for TS Oct 25, 2025
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 25, 2025

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60120

Comment on lines +3416 to +3426
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);
}
Copy link
Member Author

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 25, 2025

Open in StackBlitz

commit: 7414d5d

@@ -0,0 +1 @@
true ? async (): true;
Copy link
Contributor

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?

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[preset-typescript] Ternaries that call a function named async fail to parse

4 participants