diff --git a/packages/babel-parser/src/plugins/typescript/index.js b/packages/babel-parser/src/plugins/typescript/index.js index 448c62c94abe..8df9d4e7b239 100644 --- a/packages/babel-parser/src/plugins/typescript/index.js +++ b/packages/babel-parser/src/plugins/typescript/index.js @@ -1008,23 +1008,24 @@ export default (superClass: Class): Class => } tsParseTypePredicateAsserts(): boolean { - if (!this.tsIsIdentifier()) { + if ( + !this.match(tt.name) || + this.state.value !== "asserts" || + this.hasPrecedingLineBreak() + ) { return false; } - const containsEsc = this.state.containsEsc; - - const id = this.parseIdentifier(); - if ( - id.name !== "asserts" || - this.hasPrecedingLineBreak() || - (!this.tsIsIdentifier() && !this.match(tt._this)) - ) { + this.next(); + if (!this.match(tt.name) && !this.match(tt._this)) { return false; } if (containsEsc) { - this.raise(id.start, "Escape sequence in keyword asserts"); + this.raise( + this.state.lastTokStart, + "Escape sequence in keyword asserts", + ); } return true;