Add better parser error when using jsx (#11722)
* Add "<" parser tests
* No {jsx,flow,typescript} plugin
* Type parameter
* Valid JS Code
* Add: better parser error when using jsx
Address #11499
* Add: babel parser test
Test parser with no plugins and when jsx is given with a js expression
* Add: no flow but with typescript test
* Add: type paramter test with no plugins (no flow)
* Add: unclosed jsx element test
This commit is contained in:
parent
601c824873
commit
beca7e2d8e
@ -1177,6 +1177,12 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
}
|
||||
// fall through
|
||||
case tt.relational: {
|
||||
if (this.state.value === "<") {
|
||||
throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
|
||||
}
|
||||
}
|
||||
// fall through
|
||||
default:
|
||||
throw this.unexpected();
|
||||
}
|
||||
|
||||
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div>{name}</div>
|
||||
4
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-jsx-expression/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [],
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)"
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict"
|
||||
<div
|
||||
36
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/output.json
vendored
Normal file
36
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-no-jsx/output.json
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
|
||||
"expression": {
|
||||
"type": "BinaryExpression",
|
||||
"start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":4}},
|
||||
"left": {
|
||||
"type": "StringLiteral",
|
||||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
|
||||
"extra": {
|
||||
"rawValue": "use strict",
|
||||
"raw": "\"use strict\""
|
||||
},
|
||||
"value": "use strict"
|
||||
},
|
||||
"operator": "<",
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"start":14,"end":17,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":4},"identifierName":"div"},
|
||||
"name": "div"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div>() => {}
|
||||
3
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["typescript"]
|
||||
}
|
||||
42
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json
vendored
Normal file
42
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param-no-flow/output.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":11,"end":13,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":13}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
},
|
||||
"typeParameters": {
|
||||
"type": "TSTypeParameterDeclaration",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||
"params": [
|
||||
{
|
||||
"type": "TSTypeParameter",
|
||||
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}},
|
||||
"name": "div"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div>() => {}
|
||||
43
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/output.json
vendored
Normal file
43
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/output.json
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"expression": {
|
||||
"type": "ArrowFunctionExpression",
|
||||
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
|
||||
"id": null,
|
||||
"generator": false,
|
||||
"async": false,
|
||||
"params": [],
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start":11,"end":13,"loc":{"start":{"line":1,"column":11},"end":{"line":1,"column":13}},
|
||||
"body": [],
|
||||
"directives": []
|
||||
},
|
||||
"typeParameters": {
|
||||
"type": "TypeParameterDeclaration",
|
||||
"start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}},
|
||||
"params": [
|
||||
{
|
||||
"type": "TypeParameter",
|
||||
"start":1,"end":4,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":4}},
|
||||
"name": "div",
|
||||
"variance": null
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div>() => {}
|
||||
4
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-type-param/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [],
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div></div>
|
||||
4
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)",
|
||||
"plugins": []
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<div>() => {}
|
||||
4
packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/jsx/errors/unclosed-jsx-element/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": ["jsx"],
|
||||
"throws": "Unexpected token (1:13)"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user