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
Fix %==
parsing in hack pipes
#13536
Fix %==
parsing in hack pipes
#13536
Conversation
%==
parsing in hack pipes
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d668a78:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/47344/ |
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Co-authored-by: J. S. Choi <jschoi@jschoi.org>
|
||
this.state.value = "%"; | ||
this.state.type = tt.modulo; | ||
this.state.pos--; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
// reparse it as %. | ||
// The next readToken() call will start parsing from =. | ||
|
||
this.state.value = "%"; |
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.
We could skip this step since this.state.value
is not used.
Wouldn't this be better handled wholly in the tokenizer? I mean, when the tokenizer sees
|
Uh that's a really good point. |
@lightmare |
Is assignment to topic reference allowed? And if not, can it be an early error? Assuming |
@lightmare: Assignment to If we pursue handling everything in tokenizer.js, then should that be changed in this pull request or in another pull request after this? |
As @JLHwung pointed out, handling everything in tokenizer is not feasible, because the tokenizer doesn't have enough information to decide whether |
Yes. We should implement early errors for cases like
and descend to |
@JLHwung: The current implementation in However, the errors usually are just generic “unexpected token” errors. Do you mean that we should make special error cases with more descriptive messages? And would this count as a breaking change? |
@js-choi I checked the
However, it seems to me the current spec does not forbid such composition, because we lost the
So we can allow parenthesized arrow expressions / yield expressions x |> (async (x = %) => {})
x |> ((x = %) => {})
(function* () { x |> (yield %) }) but this rule still forbid
Yes if we parse PipeExpression in restricted grammar as defined in the spec, we surely can not recover from many cases. As an early proposal I tend to prioritize on the correctness and then we can always improve the error handling later when the proposal gets advanced. |
I think the right place to forbid topic assignment is in AssignmentTargetType. |
We would still have to rewind the state and transform it to two tokens, because our parser needs to be able to recover from early errors and continue parsing. |
Merging with the proposal author (@js-choi) 's approval and mine. |
* Fix `%==` parsing in hack pipes * Use custom token type * Update packages/babel-parser/src/parser/expression.js Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> * Apply suggestions from code review Co-authored-by: J. S. Choi <jschoi@jschoi.org> Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> Co-authored-by: J. S. Choi <jschoi@jschoi.org>
* Fix `%==` parsing in hack pipes * Use custom token type * Update packages/babel-parser/src/parser/expression.js Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> * Apply suggestions from code review Co-authored-by: J. S. Choi <jschoi@jschoi.org> Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com> Co-authored-by: J. S. Choi <jschoi@jschoi.org>
b9c1884 removed
exprAllowed
usage from the main parser. However, it was used by the %followed by a token starting with
=. This PR modify the parser to re-interpret
%=as
%` when parsing it in an expression position if hack pipes are enabled.cc @js-choi (please review!)