diff --git a/packages/babel-parser/src/plugins/jsx/index.js b/packages/babel-parser/src/plugins/jsx/index.js index 523702f0dd84..2aba709267f2 100644 --- a/packages/babel-parser/src/plugins/jsx/index.js +++ b/packages/babel-parser/src/plugins/jsx/index.js @@ -484,18 +484,12 @@ export default (superClass: Class): Class => node.closingElement = closingElement; } node.children = children; - while (this.isRelational("<")) { - // In case we encounter an lt token here it will always be the start of - // jsx as the lt sign is not allowed in places that expect an expression - this.finishToken(tt.jsxTagStart); - - this.raise( + if (this.isRelational("<")) { + throw this.raise( this.state.start, "Adjacent JSX elements must be wrapped in an enclosing tag. " + "Did you want a JSX fragment <>...?", ); - - this.jsxParseElement(); } return isFragment(openingElement) diff --git a/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json b/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json new file mode 100644 index 000000000000..9835a882e99c --- /dev/null +++ b/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...? (1:22)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/output.json b/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/output.json deleted file mode 100644 index b657e0982552..000000000000 --- a/packages/babel-parser/test/fixtures/jsx/errors/adjacent-tags/output.json +++ /dev/null @@ -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": [] - } -} \ No newline at end of file