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:
Huáng Jùnliàng 2020-07-01 15:17:05 -04:00 committed by GitHub
parent b1b21e5c03
commit d67629b114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 36 additions and 1 deletions

View File

@ -1179,7 +1179,13 @@ export default class ExpressionParser extends LValParser {
// fall through
case tt.relational: {
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

View File

@ -0,0 +1 @@
<!--bar-->

View File

@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "Unexpected token (1:0)"
}

View File

@ -0,0 +1,5 @@
function foo () {
return (
<>Hello</>
);
}

View File

@ -0,0 +1,4 @@
{
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (3:4)",
"plugins": []
}

View File

@ -0,0 +1,5 @@
<
𠮷
></
𠮷
>

View File

@ -0,0 +1,4 @@
{
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)",
"plugins": []
}

View File

@ -0,0 +1 @@
<!--a

View File

@ -0,0 +1,5 @@
{
"sourceType": "module",
"plugins": ["jsx", "flow"],
"throws": "Unexpected token (1:0)"
}