From ae154c86edd9dfed4337b4079e8a03b3e0f3ef0e Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 15 Jan 2019 00:03:39 -0800 Subject: [PATCH 01/21] perf: Minor optimizations --- packages/babel-parser/src/tokenizer/index.js | 39 +++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 368ffb6866..3a7312b486 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -311,6 +311,11 @@ export default class Tokenizer extends LocationParser { loop: while (this.state.pos < this.input.length) { const ch = this.input.charCodeAt(this.state.pos); switch (ch) { + case charCodes.space: + case charCodes.nonBreakingSpace: + case charCodes.tab: + ++this.state.pos; + break; case charCodes.carriageReturn: if ( this.input.charCodeAt(this.state.pos + 1) === charCodes.lineFeed @@ -651,10 +656,6 @@ export default class Tokenizer extends LocationParser { getTokenFromCode(code: number): void { switch (code) { - case charCodes.numberSign: - this.readToken_numberSign(); - return; - // The interpretation of a dot depends on whether it is followed // by a digit or another two dots. @@ -720,10 +721,6 @@ export default class Tokenizer extends LocationParser { case charCodes.questionMark: this.readToken_question(); return; - case charCodes.atSign: - ++this.state.pos; - this.finishToken(tt.at); - return; case charCodes.graveAccent: ++this.state.pos; @@ -809,6 +806,15 @@ export default class Tokenizer extends LocationParser { case charCodes.tilde: this.finishOp(tt.tilde, 1); return; + + case charCodes.atSign: + ++this.state.pos; + this.finishToken(tt.at); + return; + + case charCodes.numberSign: + this.readToken_numberSign(); + return; } this.raise( @@ -1266,10 +1272,11 @@ export default class Tokenizer extends LocationParser { // as a micro-optimization. readWord1(): string { + let word = ""; this.state.containsEsc = false; - let word = "", - first = true, - chunkStart = this.state.pos; + const start = this.state.pos; + let chunkStart = this.state.pos; + while (this.state.pos < this.input.length) { const ch = this.input.codePointAt(this.state.pos); if (isIdentifierChar(ch)) { @@ -1281,6 +1288,8 @@ export default class Tokenizer extends LocationParser { word += this.input.slice(chunkStart, this.state.pos); const escStart = this.state.pos; + const identifierCheck = + this.state.pos === start ? isIdentifierStart : isIdentifierChar; if (this.input.charCodeAt(++this.state.pos) !== charCodes.lowercaseU) { this.raise( @@ -1291,8 +1300,11 @@ export default class Tokenizer extends LocationParser { ++this.state.pos; const esc = this.readCodePoint(true); - // $FlowFixMe (thinks esc may be null, but throwOnInvalid is true) - if (!(first ? isIdentifierStart : isIdentifierChar)(esc, true)) { + + if ( + // $FlowFixMe (thinks esc may be null, but throwOnInvalid is true) + !identifierCheck(esc, true) + ) { this.raise(escStart, "Invalid Unicode escape"); } @@ -1302,7 +1314,6 @@ export default class Tokenizer extends LocationParser { } else { break; } - first = false; } return word + this.input.slice(chunkStart, this.state.pos); } From 2dc1c91955791eac031bdd2eaa79e8f2338ce14e Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Tue, 15 Jan 2019 12:45:36 -0800 Subject: [PATCH 02/21] perf: Move input to state and precalculate length This also fixes a bug with async functions --- packages/babel-parser/src/parser/base.js | 1 - .../babel-parser/src/parser/expression.js | 11 +- packages/babel-parser/src/parser/index.js | 1 - packages/babel-parser/src/parser/location.js | 2 +- packages/babel-parser/src/parser/statement.js | 10 +- packages/babel-parser/src/parser/util.js | 2 +- packages/babel-parser/src/plugins/flow.js | 20 +- .../babel-parser/src/plugins/jsx/index.js | 34 +-- .../babel-parser/src/tokenizer/context.js | 4 +- packages/babel-parser/src/tokenizer/index.js | 197 ++++++++++-------- packages/babel-parser/src/tokenizer/state.js | 2 + .../export-invalid/options.json | 2 +- 12 files changed, 160 insertions(+), 126 deletions(-) diff --git a/packages/babel-parser/src/parser/base.js b/packages/babel-parser/src/parser/base.js index 7c84857752..96fd7fed83 100644 --- a/packages/babel-parser/src/parser/base.js +++ b/packages/babel-parser/src/parser/base.js @@ -16,7 +16,6 @@ export default class BaseParser { // Initialized by Tokenizer state: State; - input: string; isReservedWord(word: string): boolean { if (word === "await") { diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index fb390e1361..12174c78f3 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1146,7 +1146,11 @@ export default class ExpressionParser extends LValParser { const node = this.startNodeAt(startPos, startLoc); this.addExtra(node, "rawValue", value); - this.addExtra(node, "raw", this.input.slice(startPos, this.state.end)); + this.addExtra( + node, + "raw", + this.state.input.slice(startPos, this.state.end), + ); node.value = value; this.next(); return this.finishNode(node, type); @@ -1365,7 +1369,7 @@ export default class ExpressionParser extends LValParser { } } elem.value = { - raw: this.input + raw: this.state.input .slice(this.state.start, this.state.end) .replace(/\r\n?/g, "\n"), cooked: this.state.value, @@ -1967,7 +1971,8 @@ export default class ExpressionParser extends LValParser { if ( (name === "class" || name === "function") && (this.state.lastTokEnd !== this.state.lastTokStart + 1 || - this.input.charCodeAt(this.state.lastTokStart) !== charCodes.dot) + this.state.input.charCodeAt(this.state.lastTokStart) !== + charCodes.dot) ) { this.state.context.pop(); } diff --git a/packages/babel-parser/src/parser/index.js b/packages/babel-parser/src/parser/index.js index 6d6d9cfd8b..35e7e01f6c 100644 --- a/packages/babel-parser/src/parser/index.js +++ b/packages/babel-parser/src/parser/index.js @@ -22,7 +22,6 @@ export default class Parser extends StatementParser { this.options = options; this.inModule = this.options.sourceType === "module"; - this.input = input; this.plugins = pluginsMap(this.options.plugins); this.filename = options.sourceFilename; } diff --git a/packages/babel-parser/src/parser/location.js b/packages/babel-parser/src/parser/location.js index 79db584a49..f73724004b 100644 --- a/packages/babel-parser/src/parser/location.js +++ b/packages/babel-parser/src/parser/location.js @@ -21,7 +21,7 @@ export default class LocationParser extends CommentsParser { code?: string, } = {}, ): empty { - const loc = getLineInfo(this.input, pos); + const loc = getLineInfo(this.state.input, pos); message += ` (${loc.line}:${loc.column})`; // $FlowIgnore const err: SyntaxError & { pos: number, loc: Position } = new SyntaxError( diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index a024411140..6f17c54709 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -44,7 +44,7 @@ export default class StatementParser extends ExpressionParser { const directiveLiteral = this.startNodeAt(expr.start, expr.loc.start); const directive = this.startNodeAt(stmt.start, stmt.loc.start); - const raw = this.input.slice(expr.start, expr.end); + const raw = this.state.input.slice(expr.start, expr.end); const val = (directiveLiteral.value = raw.slice(1, -1)); // remove quotes this.addExtra(directiveLiteral, "raw", raw); @@ -551,7 +551,9 @@ export default class StatementParser extends ExpressionParser { parseThrowStatement(node: N.ThrowStatement): N.ThrowStatement { this.next(); if ( - lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)) + lineBreak.test( + this.state.input.slice(this.state.lastTokEnd, this.state.start), + ) ) { this.raise(this.state.lastTokEnd, "Illegal newline after throw"); } @@ -1521,7 +1523,7 @@ export default class StatementParser extends ExpressionParser { isAsyncFunction() { if (!this.isContextual("async")) return false; - const { input, pos } = this.state; + const { input, pos, length } = this.state; skipWhiteSpace.lastIndex = pos; const skip = skipWhiteSpace.exec(input); @@ -1533,7 +1535,7 @@ export default class StatementParser extends ExpressionParser { return ( !lineBreak.test(input.slice(pos, next)) && input.slice(next, next + 8) === "function" && - (next + 8 === input.length || !isIdentifierChar(input.charAt(next + 8))) + (next + 8 === length || !isIdentifierChar(input.charCodeAt(next + 8))) ); } diff --git a/packages/babel-parser/src/parser/util.js b/packages/babel-parser/src/parser/util.js index d889982f83..6538ee7f1b 100644 --- a/packages/babel-parser/src/parser/util.js +++ b/packages/babel-parser/src/parser/util.js @@ -87,7 +87,7 @@ export default class UtilParser extends Tokenizer { hasPrecedingLineBreak(): boolean { return lineBreak.test( - this.input.slice(this.state.lastTokEnd, this.state.start), + this.state.input.slice(this.state.lastTokEnd, this.state.start), ); } diff --git a/packages/babel-parser/src/plugins/flow.js b/packages/babel-parser/src/plugins/flow.js index 8e190929c6..50e4e7fa3c 100644 --- a/packages/babel-parser/src/plugins/flow.js +++ b/packages/babel-parser/src/plugins/flow.js @@ -1124,7 +1124,7 @@ export default (superClass: Class): Class => node.types = []; this.expect(tt.bracketL); // We allow trailing commas - while (this.state.pos < this.input.length && !this.match(tt.bracketR)) { + while (this.state.pos < this.state.length && !this.match(tt.bracketR)) { node.types.push(this.flowParseType()); if (this.match(tt.bracketR)) break; this.expect(tt.comma); @@ -1934,7 +1934,7 @@ export default (superClass: Class): Class => // ensure that inside flow types, we bypass the jsx parser plugin readToken(code: number): void { - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); if ( this.state.inType && (code === charCodes.greaterThan || code === charCodes.lessThan) @@ -2686,7 +2686,7 @@ export default (superClass: Class): Class => } readToken_mult_modulo(code: number): void { - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); if ( code === charCodes.asterisk && next === charCodes.slash && @@ -2728,7 +2728,7 @@ export default (superClass: Class): Class => } if (this.hasPlugin("flow") && this.state.hasFlowComment) { - const end = this.input.indexOf("*-/", (this.state.pos += 2)); + const end = this.state.input.indexOf("*-/", (this.state.pos += 2)); if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment"); this.state.pos = end + 3; return; @@ -2742,20 +2742,22 @@ export default (superClass: Class): Class => let shiftToFirstNonWhiteSpace = 2; while ( [charCodes.space, charCodes.tab].includes( - this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace), + this.state.input.charCodeAt(pos + shiftToFirstNonWhiteSpace), ) ) { shiftToFirstNonWhiteSpace++; } - const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos); - const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1); + const ch2 = this.state.input.charCodeAt(shiftToFirstNonWhiteSpace + pos); + const ch3 = this.state.input.charCodeAt( + shiftToFirstNonWhiteSpace + pos + 1, + ); if (ch2 === charCodes.colon && ch3 === charCodes.colon) { return shiftToFirstNonWhiteSpace + 2; // check for /*:: } if ( - this.input.slice( + this.state.input.slice( shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12, ) === "flow-include" @@ -2769,7 +2771,7 @@ export default (superClass: Class): Class => } hasFlowCommentCompletion(): void { - const end = this.input.indexOf("*/", this.state.pos); + const end = this.state.input.indexOf("*/", this.state.pos); if (end === -1) { this.raise(this.state.pos, "Unterminated comment"); } diff --git a/packages/babel-parser/src/plugins/jsx/index.js b/packages/babel-parser/src/plugins/jsx/index.js index 0271aeffed..7a814cfbce 100644 --- a/packages/babel-parser/src/plugins/jsx/index.js +++ b/packages/babel-parser/src/plugins/jsx/index.js @@ -79,11 +79,11 @@ export default (superClass: Class): Class => let out = ""; let chunkStart = this.state.pos; for (;;) { - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.state.length) { this.raise(this.state.start, "Unterminated JSX contents"); } - const ch = this.input.charCodeAt(this.state.pos); + const ch = this.state.input.charCodeAt(this.state.pos); switch (ch) { case charCodes.lessThan: @@ -95,18 +95,18 @@ export default (superClass: Class): Class => } return this.getTokenFromCode(ch); } - out += this.input.slice(chunkStart, this.state.pos); + out += this.state.input.slice(chunkStart, this.state.pos); return this.finishToken(tt.jsxText, out); case charCodes.ampersand: - out += this.input.slice(chunkStart, this.state.pos); + out += this.state.input.slice(chunkStart, this.state.pos); out += this.jsxReadEntity(); chunkStart = this.state.pos; break; default: if (isNewLine(ch)) { - out += this.input.slice(chunkStart, this.state.pos); + out += this.state.input.slice(chunkStart, this.state.pos); out += this.jsxReadNewLine(true); chunkStart = this.state.pos; } else { @@ -117,12 +117,12 @@ export default (superClass: Class): Class => } jsxReadNewLine(normalizeCRLF: boolean): string { - const ch = this.input.charCodeAt(this.state.pos); + const ch = this.state.input.charCodeAt(this.state.pos); let out; ++this.state.pos; if ( ch === charCodes.carriageReturn && - this.input.charCodeAt(this.state.pos) === charCodes.lineFeed + this.state.input.charCodeAt(this.state.pos) === charCodes.lineFeed ) { ++this.state.pos; out = normalizeCRLF ? "\n" : "\r\n"; @@ -139,25 +139,25 @@ export default (superClass: Class): Class => let out = ""; let chunkStart = ++this.state.pos; for (;;) { - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.state.length) { this.raise(this.state.start, "Unterminated string constant"); } - const ch = this.input.charCodeAt(this.state.pos); + const ch = this.state.input.charCodeAt(this.state.pos); if (ch === quote) break; if (ch === charCodes.ampersand) { - out += this.input.slice(chunkStart, this.state.pos); + out += this.state.input.slice(chunkStart, this.state.pos); out += this.jsxReadEntity(); chunkStart = this.state.pos; } else if (isNewLine(ch)) { - out += this.input.slice(chunkStart, this.state.pos); + out += this.state.input.slice(chunkStart, this.state.pos); out += this.jsxReadNewLine(false); chunkStart = this.state.pos; } else { ++this.state.pos; } } - out += this.input.slice(chunkStart, this.state.pos++); + out += this.state.input.slice(chunkStart, this.state.pos++); return this.finishToken(tt.string, out); } @@ -165,11 +165,11 @@ export default (superClass: Class): Class => let str = ""; let count = 0; let entity; - let ch = this.input[this.state.pos]; + let ch = this.state.input[this.state.pos]; const startPos = ++this.state.pos; - while (this.state.pos < this.input.length && count++ < 10) { - ch = this.input[this.state.pos++]; + while (this.state.pos < this.state.length && count++ < 10) { + ch = this.state.input[this.state.pos++]; if (ch === ";") { if (str[0] === "#") { if (str[1] === "x") { @@ -208,11 +208,11 @@ export default (superClass: Class): Class => let ch; const start = this.state.pos; do { - ch = this.input.charCodeAt(++this.state.pos); + ch = this.state.input.charCodeAt(++this.state.pos); } while (isIdentifierChar(ch) || ch === charCodes.dash); return this.finishToken( tt.jsxName, - this.input.slice(start, this.state.pos), + this.state.input.slice(start, this.state.pos), ); } diff --git a/packages/babel-parser/src/tokenizer/context.js b/packages/babel-parser/src/tokenizer/context.js index 6bb2b94912..6add1a4cf7 100644 --- a/packages/babel-parser/src/tokenizer/context.js +++ b/packages/babel-parser/src/tokenizer/context.js @@ -107,7 +107,9 @@ tt._function.updateContext = tt._class.updateContext = function(prevType) { prevType !== tt._else && !( prevType === tt._return && - lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start)) + lineBreak.test( + this.state.input.slice(this.state.lastTokEnd, this.state.start), + ) ) && !( (prevType === tt.colon || prevType === tt.braceL) && diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 3a7312b486..558cd069cb 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -185,7 +185,7 @@ export default class Tokenizer extends LocationParser { this.state.pos = this.state.start; while (this.state.pos < this.state.lineStart) { this.state.lineStart = - this.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; + this.state.input.lastIndexOf("\n", this.state.lineStart - 2) + 1; --this.state.curLine; } this.nextToken(); @@ -206,7 +206,7 @@ export default class Tokenizer extends LocationParser { this.state.octalPosition = null; this.state.start = this.state.pos; this.state.startLoc = this.state.curPosition(); - if (this.state.pos >= this.input.length) { + if (this.state.pos >= this.state.length) { this.finishToken(tt.eof); return; } @@ -214,7 +214,7 @@ export default class Tokenizer extends LocationParser { if (curContext.override) { curContext.override(this); } else { - this.readToken(this.input.codePointAt(this.state.pos)); + this.readToken(this.state.input.codePointAt(this.state.pos)); } } @@ -254,14 +254,14 @@ export default class Tokenizer extends LocationParser { skipBlockComment(): void { const startLoc = this.state.curPosition(); const start = this.state.pos; - const end = this.input.indexOf("*/", (this.state.pos += 2)); + const end = this.state.input.indexOf("*/", (this.state.pos += 2)); if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment"); this.state.pos = end + 2; lineBreakG.lastIndex = start; let match; while ( - (match = lineBreakG.exec(this.input)) && + (match = lineBreakG.exec(this.state.input)) && match.index < this.state.pos ) { ++this.state.curLine; @@ -270,7 +270,7 @@ export default class Tokenizer extends LocationParser { this.pushComment( true, - this.input.slice(start + 2, end), + this.state.input.slice(start + 2, end), start, this.state.pos, startLoc, @@ -281,22 +281,22 @@ export default class Tokenizer extends LocationParser { skipLineComment(startSkip: number): void { const start = this.state.pos; const startLoc = this.state.curPosition(); - let ch = this.input.charCodeAt((this.state.pos += startSkip)); - if (this.state.pos < this.input.length) { + let ch = this.state.input.charCodeAt((this.state.pos += startSkip)); + if (this.state.pos < this.state.length) { while ( ch !== charCodes.lineFeed && ch !== charCodes.carriageReturn && ch !== charCodes.lineSeparator && ch !== charCodes.paragraphSeparator && - ++this.state.pos < this.input.length + ++this.state.pos < this.state.length ) { - ch = this.input.charCodeAt(this.state.pos); + ch = this.state.input.charCodeAt(this.state.pos); } } this.pushComment( false, - this.input.slice(start + startSkip, this.state.pos), + this.state.input.slice(start + startSkip, this.state.pos), start, this.state.pos, startLoc, @@ -308,8 +308,8 @@ export default class Tokenizer extends LocationParser { // whitespace and comments, and. skipSpace(): void { - loop: while (this.state.pos < this.input.length) { - const ch = this.input.charCodeAt(this.state.pos); + loop: while (this.state.pos < this.state.length) { + const ch = this.state.input.charCodeAt(this.state.pos); switch (ch) { case charCodes.space: case charCodes.nonBreakingSpace: @@ -318,7 +318,8 @@ export default class Tokenizer extends LocationParser { break; case charCodes.carriageReturn: if ( - this.input.charCodeAt(this.state.pos + 1) === charCodes.lineFeed + this.state.input.charCodeAt(this.state.pos + 1) === + charCodes.lineFeed ) { ++this.state.pos; } @@ -332,7 +333,7 @@ export default class Tokenizer extends LocationParser { break; case charCodes.slash: - switch (this.input.charCodeAt(this.state.pos + 1)) { + switch (this.state.input.charCodeAt(this.state.pos + 1)) { case charCodes.asterisk: this.skipBlockComment(); break; @@ -387,7 +388,7 @@ export default class Tokenizer extends LocationParser { } const nextPos = this.state.pos + 1; - const next = this.input.charCodeAt(nextPos); + const next = this.state.input.charCodeAt(nextPos); if (next >= charCodes.digit0 && next <= charCodes.digit9) { this.raise(this.state.pos, "Unexpected digit after hash token"); } @@ -410,13 +411,13 @@ export default class Tokenizer extends LocationParser { } readToken_dot(): void { - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); if (next >= charCodes.digit0 && next <= charCodes.digit9) { this.readNumber(true); return; } - const next2 = this.input.charCodeAt(this.state.pos + 2); + const next2 = this.state.input.charCodeAt(this.state.pos + 2); if (next === charCodes.dot && next2 === charCodes.dot) { this.state.pos += 3; this.finishToken(tt.ellipsis); @@ -434,7 +435,7 @@ export default class Tokenizer extends LocationParser { return; } - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); if (next === charCodes.equalsTo) { this.finishOp(tt.assign, 2); } else { @@ -443,12 +444,12 @@ export default class Tokenizer extends LocationParser { } readToken_interpreter(): boolean { - if (this.state.pos !== 0 || this.state.input.length < 2) return false; + if (this.state.pos !== 0 || this.state.length < 2) return false; const start = this.state.pos; this.state.pos += 1; - let ch = this.input.charCodeAt(this.state.pos); + let ch = this.state.input.charCodeAt(this.state.pos); if (ch !== charCodes.exclamationMark) return false; while ( @@ -456,12 +457,12 @@ export default class Tokenizer extends LocationParser { ch !== charCodes.carriageReturn && ch !== charCodes.lineSeparator && ch !== charCodes.paragraphSeparator && - ++this.state.pos < this.input.length + ++this.state.pos < this.state.length ) { - ch = this.input.charCodeAt(this.state.pos); + ch = this.state.input.charCodeAt(this.state.pos); } - const value = this.input.slice(start + 2, this.state.pos); + const value = this.state.input.slice(start + 2, this.state.pos); this.finishToken(tt.interpreterDirective, value); @@ -472,13 +473,13 @@ export default class Tokenizer extends LocationParser { // '%*' let type = code === charCodes.asterisk ? tt.star : tt.modulo; let width = 1; - let next = this.input.charCodeAt(this.state.pos + 1); + let next = this.state.input.charCodeAt(this.state.pos + 1); const exprAllowed = this.state.exprAllowed; // Exponentiation operator ** if (code === charCodes.asterisk && next === charCodes.asterisk) { width++; - next = this.input.charCodeAt(this.state.pos + 2); + next = this.state.input.charCodeAt(this.state.pos + 2); type = tt.exponent; } @@ -492,10 +493,12 @@ export default class Tokenizer extends LocationParser { readToken_pipe_amp(code: number): void { // '|&' - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); if (next === code) { - if (this.input.charCodeAt(this.state.pos + 2) === charCodes.equalsTo) { + if ( + this.state.input.charCodeAt(this.state.pos + 2) === charCodes.equalsTo + ) { this.finishOp(tt.assign, 3); } else { this.finishOp( @@ -531,7 +534,7 @@ export default class Tokenizer extends LocationParser { readToken_caret(): void { // '^' - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); if (next === charCodes.equalsTo) { this.finishOp(tt.assign, 2); } else { @@ -541,14 +544,17 @@ export default class Tokenizer extends LocationParser { readToken_plus_min(code: number): void { // '+-' - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); if (next === code) { if ( next === charCodes.dash && !this.inModule && - this.input.charCodeAt(this.state.pos + 2) === charCodes.greaterThan && - lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.pos)) + this.state.input.charCodeAt(this.state.pos + 2) === + charCodes.greaterThan && + lineBreak.test( + this.state.input.slice(this.state.lastTokEnd, this.state.pos), + ) ) { // A `-->` line comment this.skipLineComment(3); @@ -569,16 +575,20 @@ export default class Tokenizer extends LocationParser { readToken_lt_gt(code: number): void { // '<>' - const next = this.input.charCodeAt(this.state.pos + 1); + const next = this.state.input.charCodeAt(this.state.pos + 1); let size = 1; if (next === code) { size = code === charCodes.greaterThan && - this.input.charCodeAt(this.state.pos + 2) === charCodes.greaterThan + this.state.input.charCodeAt(this.state.pos + 2) === + charCodes.greaterThan ? 3 : 2; - if (this.input.charCodeAt(this.state.pos + size) === charCodes.equalsTo) { + if ( + this.state.input.charCodeAt(this.state.pos + size) === + charCodes.equalsTo + ) { this.finishOp(tt.assign, size + 1); return; } @@ -590,8 +600,8 @@ export default class Tokenizer extends LocationParser { next === charCodes.exclamationMark && code === charCodes.lessThan && !this.inModule && - this.input.charCodeAt(this.state.pos + 2) === charCodes.dash && - this.input.charCodeAt(this.state.pos + 3) === charCodes.dash + this.state.input.charCodeAt(this.state.pos + 2) === charCodes.dash && + this.state.input.charCodeAt(this.state.pos + 3) === charCodes.dash ) { // `