Skip to content

Commit

Permalink
fix: throw expect jsx plugin error when an idStart or > is seen (#11774)
Browse files Browse the repository at this point in the history
* fix: throw expect jsx plugin error when an idStart or > is seen

* fix: avoid throwing undefined

* add test case
  • Loading branch information
JLHwung committed Jul 1, 2020
1 parent b1b21e5 commit d67629b
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -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
Expand Down
@@ -0,0 +1 @@
<!--bar-->
@@ -0,0 +1,4 @@
{
"sourceType": "module",
"throws": "Unexpected token (1:0)"
}
@@ -0,0 +1,5 @@
function foo () {
return (
<>Hello</>
);
}
@@ -0,0 +1,4 @@
{
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (3:4)",
"plugins": []
}
@@ -0,0 +1,5 @@
<
𠮷
></
𠮷
>
@@ -0,0 +1,4 @@
{
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'jsx, flow, typescript' (1:0)",
"plugins": []
}
@@ -0,0 +1 @@
<!--a
@@ -0,0 +1,5 @@
{
"sourceType": "module",
"plugins": ["jsx", "flow"],
"throws": "Unexpected token (1:0)"
}

0 comments on commit d67629b

Please sign in to comment.