Don't recover from "adjacent jsx elements" parser error (#10682)
This commit is contained in:
parent
c2bace4b73
commit
0287c0f02f
@ -484,18 +484,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
node.closingElement = closingElement;
|
node.closingElement = closingElement;
|
||||||
}
|
}
|
||||||
node.children = children;
|
node.children = children;
|
||||||
while (this.isRelational("<")) {
|
if (this.isRelational("<")) {
|
||||||
// In case we encounter an lt token here it will always be the start of
|
throw this.raise(
|
||||||
// jsx as the lt sign is not allowed in places that expect an expression
|
|
||||||
this.finishToken(tt.jsxTagStart);
|
|
||||||
|
|
||||||
this.raise(
|
|
||||||
this.state.start,
|
this.state.start,
|
||||||
"Adjacent JSX elements must be wrapped in an enclosing tag. " +
|
"Adjacent JSX elements must be wrapped in an enclosing tag. " +
|
||||||
"Did you want a JSX fragment <>...</>?",
|
"Did you want a JSX fragment <>...</>?",
|
||||||
);
|
);
|
||||||
|
|
||||||
this.jsxParseElement();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return isFragment(openingElement)
|
return isFragment(openingElement)
|
||||||
|
|||||||
3
packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (1:22)"
|
||||||
|
}
|
||||||
@ -1,189 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "File",
|
|
||||||
"start": 0,
|
|
||||||
"end": 37,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 37
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"errors": [
|
|
||||||
"SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (1:22)"
|
|
||||||
],
|
|
||||||
"program": {
|
|
||||||
"type": "Program",
|
|
||||||
"start": 0,
|
|
||||||
"end": 37,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 37
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sourceType": "script",
|
|
||||||
"interpreter": null,
|
|
||||||
"body": [
|
|
||||||
{
|
|
||||||
"type": "VariableDeclaration",
|
|
||||||
"start": 0,
|
|
||||||
"end": 37,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 37
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"declarations": [
|
|
||||||
{
|
|
||||||
"type": "VariableDeclarator",
|
|
||||||
"start": 4,
|
|
||||||
"end": 36,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 4
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 36
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"id": {
|
|
||||||
"type": "Identifier",
|
|
||||||
"start": 4,
|
|
||||||
"end": 5,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 4
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 5
|
|
||||||
},
|
|
||||||
"identifierName": "x"
|
|
||||||
},
|
|
||||||
"name": "x"
|
|
||||||
},
|
|
||||||
"init": {
|
|
||||||
"type": "JSXElement",
|
|
||||||
"start": 8,
|
|
||||||
"end": 36,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 8
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 36
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"openingElement": {
|
|
||||||
"type": "JSXOpeningElement",
|
|
||||||
"start": 8,
|
|
||||||
"end": 13,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 8
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 13
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "JSXIdentifier",
|
|
||||||
"start": 9,
|
|
||||||
"end": 12,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 9
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 12
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"name": "div"
|
|
||||||
},
|
|
||||||
"attributes": [],
|
|
||||||
"selfClosing": false
|
|
||||||
},
|
|
||||||
"closingElement": {
|
|
||||||
"type": "JSXClosingElement",
|
|
||||||
"start": 16,
|
|
||||||
"end": 22,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 16
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 22
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "JSXIdentifier",
|
|
||||||
"start": 18,
|
|
||||||
"end": 21,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 18
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 21
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"name": "div"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"children": [
|
|
||||||
{
|
|
||||||
"type": "JSXText",
|
|
||||||
"start": 13,
|
|
||||||
"end": 16,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 13
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 16
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"extra": {
|
|
||||||
"rawValue": "one",
|
|
||||||
"raw": "one"
|
|
||||||
},
|
|
||||||
"value": "one"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"kind": "var"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"directives": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user