Skip to content

Commit 6be6e04

Browse files
authored
fix: parsing of JSXText following JSXSpreadChild (#14974)
fix
1 parent 7c6ecb5 commit 6be6e04

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

packages/babel-parser/src/plugins/jsx/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export default (superClass: typeof Parser) =>
354354
jsxParseSpreadChild(node: Undone<N.JSXSpreadChild>): N.JSXSpreadChild {
355355
this.next(); // ellipsis
356356
node.expression = this.parseExpression();
357-
this.setContext(tc.j_oTag);
357+
this.setContext(tc.j_expr);
358358
this.state.canStartJSXElement = true;
359359
this.expect(tt.braceR);
360360

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a>{ ...b }c</a>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}},
7+
"sourceType": "script",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "ExpressionStatement",
12+
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}},
13+
"expression": {
14+
"type": "JSXElement",
15+
"start":0,"end":16,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":16,"index":16}},
16+
"openingElement": {
17+
"type": "JSXOpeningElement",
18+
"start":0,"end":3,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":3,"index":3}},
19+
"name": {
20+
"type": "JSXIdentifier",
21+
"start":1,"end":2,"loc":{"start":{"line":1,"column":1,"index":1},"end":{"line":1,"column":2,"index":2}},
22+
"name": "a"
23+
},
24+
"attributes": [],
25+
"selfClosing": false
26+
},
27+
"closingElement": {
28+
"type": "JSXClosingElement",
29+
"start":12,"end":16,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":16,"index":16}},
30+
"name": {
31+
"type": "JSXIdentifier",
32+
"start":14,"end":15,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":15,"index":15}},
33+
"name": "a"
34+
}
35+
},
36+
"children": [
37+
{
38+
"type": "JSXSpreadChild",
39+
"start":3,"end":11,"loc":{"start":{"line":1,"column":3,"index":3},"end":{"line":1,"column":11,"index":11}},
40+
"expression": {
41+
"type": "Identifier",
42+
"start":8,"end":9,"loc":{"start":{"line":1,"column":8,"index":8},"end":{"line":1,"column":9,"index":9},"identifierName":"b"},
43+
"name": "b"
44+
}
45+
},
46+
{
47+
"type": "JSXText",
48+
"start":11,"end":12,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":12,"index":12}},
49+
"extra": {
50+
"rawValue": "c",
51+
"raw": "c"
52+
},
53+
"value": "c"
54+
}
55+
]
56+
}
57+
}
58+
],
59+
"directives": []
60+
}
61+
}

0 commit comments

Comments
 (0)