fix: disallow JSX tag after non-null assertion (#13449)

This commit is contained in:
Huáng Jùnliàng
2021-06-10 15:07:47 -04:00
committed by GitHub
parent f04406f24f
commit b1fe831e4a
4 changed files with 69 additions and 0 deletions

View File

@@ -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(