-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Left-value parsing cleanup #17160
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
Left-value parsing cleanup #17160
Conversation
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
"throws": "Unexpected token (1:7)" | ||
} |
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 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 ( |
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.
Nice, did you check how this improves perf?
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.
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.
c732e54
to
e51529e
Compare
e51529e
to
565b6d5
Compare
* 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
Further clean up the left-value parsing. This PR can be reviewed by commits.