From e982c0652c0a33a4fd4c2e20938bb03ffc8054b2 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Sat, 17 Jun 2017 17:41:23 +0200 Subject: [PATCH] Fix v8 deopts (#581) --- src/tokenizer/index.js | 10 ++++++---- src/tokenizer/state.js | 2 ++ src/util/location.js | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 460538f838..9854031814 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -78,6 +78,7 @@ export default class Tokenizer extends LocationParser { super(); this.state = new State; this.state.init(options, input); + this.isLookahead = false; } // Move to the next token @@ -127,7 +128,7 @@ export default class Tokenizer extends LocationParser { this.next(); this.isLookahead = false; - const curr = this.state.clone(true); + const curr = this.state; this.state = old; return curr; } @@ -225,9 +226,10 @@ export default class Tokenizer extends LocationParser { const start = this.state.pos; const startLoc = this.state.curPosition(); let ch = this.input.charCodeAt(this.state.pos += startSkip); - while (this.state.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) { - ++this.state.pos; - ch = this.input.charCodeAt(this.state.pos); + if (this.state.pos < this.input.length) { + while (ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233 && ++this.state.pos < this.input.length) { + ch = this.input.charCodeAt(this.state.pos); + } } this.pushComment(false, this.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, this.state.curPosition()); diff --git a/src/tokenizer/state.js b/src/tokenizer/state.js index cb1fedf74c..0a16182af8 100644 --- a/src/tokenizer/state.js +++ b/src/tokenizer/state.js @@ -40,6 +40,8 @@ export default class State { this.trailingComments = []; this.leadingComments = []; this.commentStack = []; + // $FlowIgnore + this.commentPreviousNode = null; this.pos = this.lineStart = 0; this.curLine = options.startLine; diff --git a/src/util/location.js b/src/util/location.js index aaa4ae531c..948c91770d 100644 --- a/src/util/location.js +++ b/src/util/location.js @@ -23,6 +23,7 @@ export class SourceLocation { start: Position; end: Position; filename: string; + identifierName: ?string; constructor(start: Position, end?: Position) { this.start = start;