Skip to content
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

rescan gt/lt token after TsAsExpression is parsed #11912

Merged
merged 3 commits into from Aug 4, 2020

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Aug 4, 2020

Q                       A
Fixed Issues? Fixes #11446
Patch: Bug Fix? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

When parsing mixture of BinaryExpression and TsAsExpression, e.g.

a as boolean <= b

The <= is read when we are parsing TsType boolean, thus it is read as a single < (tt.relational) token instead of a compound of <=. Here we introduce a reScan_lt_gt method and re-scan </> so <= can be correctly tokenized. Note that the TypeScript compiler adopted the same approach here:

https://github.com/microsoft/TypeScript/blob/624736418132374a6213bd4c66310017ee17d38a/src/compiler/parser.ts#L4329

This PR also fixes the following issue

a as boolean ?? b

because ?? is read as a pair of ? questional instead of nullishCoalescing. Since it is used in Flow exclusively (#8115), I moved the code path to the flow plugin.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser area: typescript labels Aug 4, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 4, 2020

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 169d6ce:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

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

Copy link
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@JLHwung JLHwung merged commit a1eabb8 into babel:main Aug 4, 2020
@JLHwung JLHwung deleted the fix-11446 branch August 4, 2020 21:00
fisker added a commit to fisker/prettier that referenced this pull request Aug 5, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 4, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binary operator after TypeScript as assertion causes wrong SyntaxError
4 participants