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

fix: throw expect jsx plugin error when an idStart or > is seen #11774

Merged
merged 3 commits into from Jul 1, 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
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)"
}