fix: throw expect jsx plugin error when an idStart or > is seen (#11774)
* fix: throw expect jsx plugin error when an idStart or > is seen * fix: avoid throwing undefined * add test case
This commit is contained in:
parent
b1b21e5c03
commit
d67629b114
@ -1179,7 +1179,13 @@ export default class ExpressionParser extends LValParser {
|
|||||||
// fall through
|
// fall through
|
||||||
case tt.relational: {
|
case tt.relational: {
|
||||||
if (this.state.value === "<") {
|
if (this.state.value === "<") {
|
||||||
throw this.expectOnePlugin(["jsx", "flow", "typescript"]);
|
const lookaheadCh = this.input.codePointAt(this.nextTokenStart());
|
||||||
|
if (
|
||||||
|
isIdentifierStart(lookaheadCh) || // Element/Type Parameter <foo>
|
||||||
|
lookaheadCh === charCodes.greaterThan // Fragment <>
|
||||||
|
) {
|
||||||
|
this.expectOnePlugin(["jsx", "flow", "typescript"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fall through
|
// fall through
|
||||||
|
|||||||
1
packages/babel-parser/test/fixtures/es2015/modules/invalid-xml-comment-in-module/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/es2015/modules/invalid-xml-comment-in-module/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<!--bar-->
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"throws": "Unexpected token (1:0)"
|
||||||
|
}
|
||||||
5
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-fragment/input.js
vendored
Normal file
5
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-fragment/input.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function foo () {
|
||||||
|
return (
|
||||||
|
<>Hello</>
|
||||||
|
);
|
||||||
|
}
|
||||||
4
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-fragment/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-fragment/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' (3:4)",
|
||||||
|
"plugins": []
|
||||||
|
}
|
||||||
5
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin-non-BMP-identifier/input.js
vendored
Normal file
5
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin-non-BMP-identifier/input.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<
|
||||||
|
𠮷
|
||||||
|
></
|
||||||
|
𠮷
|
||||||
|
>
|
||||||
4
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin-non-BMP-identifier/options.json
vendored
Normal file
4
packages/babel-parser/test/fixtures/jsx/errors/_no_plugin-non-BMP-identifier/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/html-comment-module/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/jsx/errors/html-comment-module/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<!--a
|
||||||
5
packages/babel-parser/test/fixtures/jsx/errors/html-comment-module/options.json
vendored
Normal file
5
packages/babel-parser/test/fixtures/jsx/errors/html-comment-module/options.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": ["jsx", "flow"],
|
||||||
|
"throws": "Unexpected token (1:0)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user