fix: disallow JSX tag after non-null assertion (#13449)
This commit is contained in:
parent
f04406f24f
commit
b1fe831e4a
@ -2043,6 +2043,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
state: N.ParseSubscriptState,
|
||||
): N.Expression {
|
||||
if (!this.hasPrecedingLineBreak() && this.match(tt.bang)) {
|
||||
// When ! is consumed as a postfix operator (non-null assertion),
|
||||
// disallow JSX tag forming after. e.g. When parsing `p! < n.p!`
|
||||
// `<n.p` can not be a start of JSX tag
|
||||
this.state.exprAllowed = false;
|
||||
this.next();
|
||||
|
||||
const nonNullExpression: N.TsNonNullExpression = this.startNodeAt(
|
||||
|
||||
1
packages/babel-parser/test/fixtures/typescript/cast/null-assertion-and-relational/input.ts
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/cast/null-assertion-and-relational/input.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
x.v! < y.v!;
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"plugins": ["typescript", "jsx"]
|
||||
}
|
||||
60
packages/babel-parser/test/fixtures/typescript/cast/null-assertion-and-relational/output.json
vendored
Normal file
60
packages/babel-parser/test/fixtures/typescript/cast/null-assertion-and-relational/output.json
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start":0,"end":12,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":12}},
|
||||
"expression": {
|
||||
"type": "BinaryExpression",
|
||||
"start":0,"end":11,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":11}},
|
||||
"left": {
|
||||
"type": "TSNonNullExpression",
|
||||
"start":0,"end":4,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":4}},
|
||||
"expression": {
|
||||
"type": "MemberExpression",
|
||||
"start":0,"end":3,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":3}},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"start":0,"end":1,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":1},"identifierName":"x"},
|
||||
"name": "x"
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":2,"end":3,"loc":{"start":{"line":1,"column":2},"end":{"line":1,"column":3},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
}
|
||||
},
|
||||
"operator": "<",
|
||||
"right": {
|
||||
"type": "TSNonNullExpression",
|
||||
"start":7,"end":11,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":11}},
|
||||
"expression": {
|
||||
"type": "MemberExpression",
|
||||
"start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}},
|
||||
"object": {
|
||||
"type": "Identifier",
|
||||
"start":7,"end":8,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":8},"identifierName":"y"},
|
||||
"name": "y"
|
||||
},
|
||||
"computed": false,
|
||||
"property": {
|
||||
"type": "Identifier",
|
||||
"start":9,"end":10,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":10},"identifierName":"v"},
|
||||
"name": "v"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user