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

[babel 8] Report a SyntaxError for } and > in JSX text #12451

Merged
merged 1 commit into from Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/babel-parser/src/plugins/jsx/index.js
Expand Up @@ -123,6 +123,19 @@ export default (superClass: Class<Parser>): Class<Parser> =>
chunkStart = this.state.pos;
break;

case charCodes.greaterThan:
case charCodes.rightCurlyBrace:
if (process.env.BABEL_8_BREAKING) {
const htmlEntity =
ch === charCodes.rightCurlyBrace ? "&rbrace;" : "&gt;";
const char = this.input[this.state.pos];
this.raise(
this.state.pos,
`Unexpected token \`${char}\`. Did you mean \`${htmlEntity}\` or \`{'${char}'}\`?`,
);
}
/* falls through */

default:
Copy link
Member Author

Choose a reason for hiding this comment

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

make prepublish-build generates this code:

        case 62:
        case 125:

        default:

while BABEL_8_BREAKING=true make prepublish-build generates this: (with the first commit of #12447 that fixes the boolean logic in the build process)

        case 62:
        case 125:
          {
            const htmlEntity = ch === 125 ? "&rbrace;" : "&gt;";
            const char = this.input[this.state.pos];
            this.raise(this.state.pos, `Unexpected token \`${char}\`. Did you mean \`${htmlEntity}\` or \`{'${char}'}\`?`);
          }

        default:

if (isNewLine(ch)) {
out += this.input.slice(chunkStart, this.state.pos);
Expand Down
1 change: 0 additions & 1 deletion packages/babel-parser/test/fixtures/jsx/basic/13/input.js

This file was deleted.

105 changes: 0 additions & 105 deletions packages/babel-parser/test/fixtures/jsx/basic/13/output.json

This file was deleted.

@@ -0,0 +1 @@
<div>></div>
@@ -0,0 +1,3 @@
{
"BABEL_8_BREAKING": false
}
@@ -0,0 +1,52 @@
{
"type": "File",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"program": {
"type": "Program",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"expression": {
"type": "JSXElement",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"openingElement": {
"type": "JSXOpeningElement",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
"name": {
"type": "JSXIdentifier",
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}},
"name": "div"
},
"attributes": [],
"selfClosing": false
},
"closingElement": {
"type": "JSXClosingElement",
"start":6,"end":12,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":12}},
"name": {
"type": "JSXIdentifier",
"start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11}},
"name": "div"
}
},
"children": [
{
"type": "JSXText",
"start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}},
"extra": {
"rawValue": ">",
"raw": ">"
},
"value": ">"
}
]
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
<div>{'>'}</div>
@@ -0,0 +1,56 @@
{
"type": "File",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"program": {
"type": "Program",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"expression": {
"type": "JSXElement",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"openingElement": {
"type": "JSXOpeningElement",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
"name": {
"type": "JSXIdentifier",
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}},
"name": "div"
},
"attributes": [],
"selfClosing": false
},
"closingElement": {
"type": "JSXClosingElement",
"start":10,"end":16,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":16}},
"name": {
"type": "JSXIdentifier",
"start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15}},
"name": "div"
}
},
"children": [
{
"type": "JSXExpressionContainer",
"start":5,"end":10,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":10}},
"expression": {
"type": "StringLiteral",
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}},
"extra": {
"rawValue": ">",
"raw": "'>'"
},
"value": ">"
}
}
]
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
<div>}</div>
@@ -0,0 +1,3 @@
{
"BABEL_8_BREAKING": false
}
@@ -0,0 +1,52 @@
{
"type": "File",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"program": {
"type": "Program",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"expression": {
"type": "JSXElement",
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
"openingElement": {
"type": "JSXOpeningElement",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
"name": {
"type": "JSXIdentifier",
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}},
"name": "div"
},
"attributes": [],
"selfClosing": false
},
"closingElement": {
"type": "JSXClosingElement",
"start":6,"end":12,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":12}},
"name": {
"type": "JSXIdentifier",
"start":8,"end":11,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":11}},
"name": "div"
}
},
"children": [
{
"type": "JSXText",
"start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6}},
"extra": {
"rawValue": "}",
"raw": "}"
},
"value": "}"
}
]
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
<div>{'}'}</div>
@@ -0,0 +1,56 @@
{
"type": "File",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"program": {
"type": "Program",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"expression": {
"type": "JSXElement",
"start":0,"end":16,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":16}},
"openingElement": {
"type": "JSXOpeningElement",
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
"name": {
"type": "JSXIdentifier",
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}},
"name": "div"
},
"attributes": [],
"selfClosing": false
},
"closingElement": {
"type": "JSXClosingElement",
"start":10,"end":16,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":16}},
"name": {
"type": "JSXIdentifier",
"start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15}},
"name": "div"
}
},
"children": [
{
"type": "JSXExpressionContainer",
"start":5,"end":10,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":10}},
"expression": {
"type": "StringLiteral",
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9}},
"extra": {
"rawValue": "}",
"raw": "'}'"
},
"value": "}"
}
}
]
}
}
],
"directives": []
}
}
@@ -0,0 +1 @@
<div>></div>
@@ -0,0 +1,3 @@
{
"BABEL_8_BREAKING": true
}