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

Add better parser error when using jsx #11722

Merged
merged 6 commits into from Jun 22, 2020
Merged

Conversation

penguingovernor
Copy link
Contributor

@penguingovernor penguingovernor commented Jun 16, 2020

Q                       A
Fixed Issues? Fixes #11499
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? No
License MIT

Added tests to babel-parser to check when the < symbol is used in the following circumstances:

  1. No jsx plugin is loaded
  2. When valid JS code is used (ie "use strict" < div)
  3. When type parameters are used.

This PR also address issue #11499 and adds a tt.relational test case in parseExprAtom.
If that test case is triggered then a expectOnePlugin(["jsx", "flow", "typescript"]) error is thrown.

*  No {jsx,flow,typescript} plugin

* Type parameter

* Valid JS Code
@babel-bot
Copy link
Collaborator

babel-bot commented Jun 16, 2020

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 16, 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 4357684:

Sandbox Source
peaceful-bush-gnkyw Configuration
intelligent-keller-uvni0 Configuration

@@ -0,0 +1 @@
<div></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add the following test case?

<div>{name}</div>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and done (:

Test parser with no plugins and when jsx is given with a js expression
@nicolo-ribaudo nicolo-ribaudo added area: errors pkg: parser PR: Polish 💅 A type of pull request used for our changelog categories labels Jun 17, 2020
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -0,0 +1,4 @@
{
"plugins": [],
Copy link
Contributor

@JLHwung JLHwung Jun 18, 2020

Choose a reason for hiding this comment

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

Can you add only jsx here? I think it will still throw syntax error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does throw that error

SyntaxError: Unexpected token (1:13)
    > 1 | <div>() => {}
        |              ^

What would the correct error message (if any) be in that case?

Copy link
Member

Choose a reason for hiding this comment

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

If we can throw something like "expected closing JSX element" it's better, otherwise Unexpected token is ok for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, pushing that final test

@existentialism
Copy link
Member

Should we retarget this onto main?

@nicolo-ribaudo nicolo-ribaudo changed the base branch from master to main June 22, 2020 15:03
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Thanks.

@JLHwung JLHwung merged commit beca7e2 into babel:main Jun 22, 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 Sep 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: errors outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Polish 💅 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better parser error when using jsx
5 participants