Skip to content

Commit

Permalink
refactor: improve tsParseTypePredicateAsserts
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 9, 2019
1 parent e6bf63e commit f7b1b38
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1008,23 +1008,24 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

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;
Expand Down

0 comments on commit f7b1b38

Please sign in to comment.