Visitar URL original
rescan gt/lt token after TsAsExpression is parsed by JLHwung · Pull Request #11912 · babel/babel · GitHub
Skip to content

rescan gt/lt token after TsAsExpression is parsed - #11912

Merged
JLHwung merged 3 commits into
babel:mainfrom
JLHwung:fix-11446
Aug 4, 2020
Merged

JLHwung merged 3 commits into
babel:mainfrom
JLHwung:fix-11446

Conversation

@JLHwung

@JLHwung JLHwung commented Aug 4, 2020 •

Copy link
Copy Markdown
Contributor
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

codesandbox-ci Bot commented Aug 4, 2020

Copy link
Copy Markdown

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
Copy Markdown
Collaborator

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

@existentialism existentialism left a comment

Copy link
Copy Markdown
Member

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