-
-
Notifications
You must be signed in to change notification settings - Fork 511
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(js_parser): desambigaute JSX and const type param of arrow function #845
fix(js_parser): desambigaute JSX and const type param of arrow function #845
Conversation
Parser conformance results onjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
🔥 Regression (1):
|
38a29ab
to
bfc622c
Compare
bfc622c
to
8441d2e
Compare
8441d2e
to
7bef185
Compare
if JsSyntaxFeature::Jsx.is_supported(p) { | ||
// Disambiguate between JSX and type parameters | ||
// Type parameters of arrow functions accept only the `const` modifier. | ||
let n = if p.nth(n + 1) == T![const] { n + 1 } else { n }; |
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.
nit:
You can use p.nth_at
here.
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.
Thanks for the suggestion. By the way, why do we have this helper? Using nth(<n>) = <kind>
looks cleaner?
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.
Certainly, we can discuss this. I'm inclined to use one specific approach. However, I was under the impression that using nth_at would be preferable. I'm open to hearing your thoughts on this.
p.nth(T![abstract]) && p.nth(T![class])
p.cur() == T![abstract] && p.cur() == T![class]
p.nth_at(n, T![abstract]) && p.nth_at(n + 1, T![class])
p.nth(n) == T![abstract] && p.nth(n + 1) == T![class]
matches!(p.nth(n), T![abstract] | T![const]) && matches!(p.nth(n + 1), T![class] | T![const)
p.nth_at_ts(n, FIRST_SET) && p.nth_at_ts(n + 1, SECOND_SET)
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.
Yeah for consistency I updated the code. However, I think we should remove this helper: we actually end with more characters and a layer of indirection (in a future PR)...
@Conaclos Is the regression expected? |
No. I updated the code to avoid the regression. However, the post seems not updated yet? |
7bef185
to
4238aa1
Compare
4238aa1
to
e1058c2
Compare
@ematipico Taking a closer look to the regression it is expected. In fact TypeScript expects an error because the tag |
Summary
Fix #846.
This fixes a parsing error that rejected the following valid code when TypeScript and JSX are both enabled:
See these two comments for some context:
Test Plan
I added tests and updated snapshots.