From 58768072effe299da7d121fa69e92ed579c3c9ad Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 15 Jan 2019 23:32:18 -0800 Subject: [PATCH] perf: Ensure canInsertSemicolon is always called last It does a lot of checks and a regex test --- packages/babel-parser/src/parser/expression.js | 11 ++++++----- packages/babel-parser/src/plugins/flow.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 7a485837b2..b65d057470 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -869,9 +869,9 @@ export default class ExpressionParser extends LValParser { return this.parseFunction(node, false, false, true); } else if ( canBeArrow && - !this.canInsertSemicolon() && id.name === "async" && - this.match(tt.name) + this.match(tt.name) && + !this.canInsertSemicolon() ) { const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters; const oldInAsync = this.state.inAsync; @@ -886,7 +886,8 @@ export default class ExpressionParser extends LValParser { return node; } - if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) { + if (canBeArrow && this.match(tt.arrow) && !this.canInsertSemicolon()) { + this.next(); const oldYOAIPAP = this.state.yieldOrAwaitInPossibleArrowParameters; this.state.yieldOrAwaitInPossibleArrowParameters = null; this.parseArrowExpression(node, [id]); @@ -2076,8 +2077,8 @@ export default class ExpressionParser extends LValParser { this.next(); if ( this.match(tt.semi) || - this.canInsertSemicolon() || - (!this.match(tt.star) && !this.state.type.startsExpr) + (!this.match(tt.star) && !this.state.type.startsExpr) || + this.canInsertSemicolon() ) { node.delegate = false; node.argument = null; diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index e0a729334a..878cc4c308 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -1398,7 +1398,7 @@ export default (superClass: Class): Class => const startPos = this.state.start, startLoc = this.state.startLoc; let type = this.flowParsePrimaryType(); - while (!this.canInsertSemicolon() && this.match(tt.bracketL)) { + while (this.match(tt.bracketL) && !this.canInsertSemicolon()) { const node = this.startNodeAt(startPos, startLoc); node.elementType = type; this.expect(tt.bracketL);