Left-value parsing cleanup#17160
Merged
nicolo-ribaudo merged 6 commits intobabel:mainfrom Mar 3, 2025
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58802 |
The current logic is taken from the flow plugin
cb806d3 to
1996132
Compare
JLHwung
commented
Mar 3, 2025
| "throws": "Unexpected token (1:8)" | ||
| } No newline at end of file | ||
| "throws": "Unexpected token (1:7)" | ||
| } |
Contributor
Author
There was a problem hiding this comment.
The input is async(x?), previously we threw on ) now we throw on ?.
| // These tokens cannot start an expression, so if one of them follows | ||
| // ? then we are probably in an arrow function parameters list and we | ||
| // don't parse the conditional expression. | ||
| if ( |
Member
There was a problem hiding this comment.
Nice, did you check how this improves perf?
Contributor
Author
There was a problem hiding this comment.
Just added a benchmark case, here is the result on my machine:
baseline 256 nested conditional expressions with typescript: 7_828 ops/sec ±0.4% (0.128ms)
baseline 512 nested conditional expressions with typescript: 3_740 ops/sec ±0.2% (0.267ms)
baseline 1024 nested conditional expressions with typescript: 1_875 ops/sec ±0.16% (0.533ms)
baseline 2048 nested conditional expressions with typescript: 0 ops/sec ±0% (0ms)
current 256 nested conditional expressions with typescript: 8_108 ops/sec ±0.42% (0.123ms)
current 512 nested conditional expressions with typescript: 4_036 ops/sec ±0.29% (0.248ms)
current 1024 nested conditional expressions with typescript: 1_977 ops/sec ±0.23% (0.506ms)
current 2048 nested conditional expressions with typescript: 947 ops/sec ±0.45% (1.056ms)
It is 8% faster than the baseline. It turns out the baseline can't handle 2048 nested conditional expressions within parentheses, probably it hits certain memory limit, while the new approach works well.
nicolo-ribaudo
approved these changes
Mar 3, 2025
liuxingbaoyu
approved these changes
Mar 3, 2025
c732e54 to
e51529e
Compare
e51529e to
565b6d5
Compare
nicolo-ribaudo
approved these changes
Mar 3, 2025
laine-hallot
pushed a commit
to laine-hallot/uwu-parser
that referenced
this pull request
Mar 31, 2025
* cleanup * refactor: simplify checkProto implementation * rename test * refactor: avoid second scan in type cast transform * refactor: simplify ts parseConditional The current logic is taken from the flow plugin * add benchmark cases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Further clean up the left-value parsing. This PR can be reviewed by commits.