Remove input and length from state (#9646)
This commit is contained in:
@@ -16,6 +16,10 @@ export default class BaseParser {
|
||||
|
||||
// Initialized by Tokenizer
|
||||
state: State;
|
||||
// input and length are not in state as they are constant and we do
|
||||
// not want to ever copy them, which happens if state gets cloned
|
||||
input: string;
|
||||
length: number;
|
||||
|
||||
hasPlugin(name: string): boolean {
|
||||
return this.plugins.has(name);
|
||||
|
||||
@@ -725,7 +725,7 @@ export default class ExpressionParser extends LValParser {
|
||||
base.name === "async" &&
|
||||
this.state.lastTokEnd === base.end &&
|
||||
!this.canInsertSemicolon() &&
|
||||
this.state.input.slice(base.start, base.end) === "async"
|
||||
this.input.slice(base.start, base.end) === "async"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1164,11 +1164,7 @@ export default class ExpressionParser extends LValParser {
|
||||
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
this.addExtra(node, "rawValue", value);
|
||||
this.addExtra(
|
||||
node,
|
||||
"raw",
|
||||
this.state.input.slice(startPos, this.state.end),
|
||||
);
|
||||
this.addExtra(node, "raw", this.input.slice(startPos, this.state.end));
|
||||
node.value = value;
|
||||
this.next();
|
||||
return this.finishNode(node, type);
|
||||
@@ -1390,7 +1386,7 @@ export default class ExpressionParser extends LValParser {
|
||||
}
|
||||
}
|
||||
elem.value = {
|
||||
raw: this.state.input
|
||||
raw: this.input
|
||||
.slice(this.state.start, this.state.end)
|
||||
.replace(/\r\n?/g, "\n"),
|
||||
cooked: this.state.value,
|
||||
@@ -2028,8 +2024,7 @@ export default class ExpressionParser extends LValParser {
|
||||
if (
|
||||
(name === "class" || name === "function") &&
|
||||
(this.state.lastTokEnd !== this.state.lastTokStart + 1 ||
|
||||
this.state.input.charCodeAt(this.state.lastTokStart) !==
|
||||
charCodes.dot)
|
||||
this.input.charCodeAt(this.state.lastTokStart) !== charCodes.dot)
|
||||
) {
|
||||
this.state.context.pop();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export default class LocationParser extends CommentsParser {
|
||||
code?: string,
|
||||
} = {},
|
||||
): empty {
|
||||
const loc = getLineInfo(this.state.input, pos);
|
||||
const loc = getLineInfo(this.input, pos);
|
||||
message += ` (${loc.line}:${loc.column})`;
|
||||
// $FlowIgnore
|
||||
const err: SyntaxError & { pos: number, loc: Position } = new SyntaxError(
|
||||
|
||||
@@ -73,7 +73,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.state.input.slice(expr.start, expr.end);
|
||||
const raw = this.input.slice(expr.start, expr.end);
|
||||
const val = (directiveLiteral.value = raw.slice(1, -1)); // remove quotes
|
||||
|
||||
this.addExtra(directiveLiteral, "raw", raw);
|
||||
@@ -105,10 +105,10 @@ export default class StatementParser extends ExpressionParser {
|
||||
return false;
|
||||
}
|
||||
skipWhiteSpace.lastIndex = this.state.pos;
|
||||
const skip = skipWhiteSpace.exec(this.state.input);
|
||||
const skip = skipWhiteSpace.exec(this.input);
|
||||
// $FlowIgnore
|
||||
const next = this.state.pos + skip[0].length;
|
||||
const nextCh = this.state.input.charCodeAt(next);
|
||||
const nextCh = this.input.charCodeAt(next);
|
||||
// For ambiguous cases, determine if a LexicalDeclaration (or only a
|
||||
// Statement) is allowed here. If context is not empty then only a Statement
|
||||
// is allowed. However, `let [` is an explicit negative lookahead for
|
||||
@@ -120,10 +120,10 @@ export default class StatementParser extends ExpressionParser {
|
||||
|
||||
if (isIdentifierStart(nextCh)) {
|
||||
let pos = next + 1;
|
||||
while (isIdentifierChar(this.state.input.charCodeAt(pos))) {
|
||||
while (isIdentifierChar(this.input.charCodeAt(pos))) {
|
||||
++pos;
|
||||
}
|
||||
const ident = this.state.input.slice(next, pos);
|
||||
const ident = this.input.slice(next, pos);
|
||||
if (!keywordRelationalOperator.test(ident)) return true;
|
||||
}
|
||||
return false;
|
||||
@@ -649,9 +649,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
parseThrowStatement(node: N.ThrowStatement): N.ThrowStatement {
|
||||
this.next();
|
||||
if (
|
||||
lineBreak.test(
|
||||
this.state.input.slice(this.state.lastTokEnd, this.state.start),
|
||||
)
|
||||
lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))
|
||||
) {
|
||||
this.raise(this.state.lastTokEnd, "Illegal newline after throw");
|
||||
}
|
||||
@@ -1747,19 +1745,20 @@ export default class StatementParser extends ExpressionParser {
|
||||
isAsyncFunction(): boolean {
|
||||
if (!this.isContextual("async")) return false;
|
||||
|
||||
const { input, pos, length } = this.state;
|
||||
const { pos } = this.state;
|
||||
|
||||
skipWhiteSpace.lastIndex = pos;
|
||||
const skip = skipWhiteSpace.exec(input);
|
||||
const skip = skipWhiteSpace.exec(this.input);
|
||||
|
||||
if (!skip || !skip.length) return false;
|
||||
|
||||
const next = pos + skip[0].length;
|
||||
|
||||
return (
|
||||
!lineBreak.test(input.slice(pos, next)) &&
|
||||
input.slice(next, next + 8) === "function" &&
|
||||
(next + 8 === length || !isIdentifierChar(input.charCodeAt(next + 8)))
|
||||
!lineBreak.test(this.input.slice(pos, next)) &&
|
||||
this.input.slice(next, next + 8) === "function" &&
|
||||
(next + 8 === this.length ||
|
||||
!isIdentifierChar(this.input.charCodeAt(next + 8)))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ export default class UtilParser extends Tokenizer {
|
||||
|
||||
hasPrecedingLineBreak(): boolean {
|
||||
return lineBreak.test(
|
||||
this.state.input.slice(this.state.lastTokEnd, this.state.start),
|
||||
this.input.slice(this.state.lastTokEnd, this.state.start),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ export default class UtilParser extends Tokenizer {
|
||||
// Try to find string literal.
|
||||
skipWhiteSpace.lastIndex = start;
|
||||
// $FlowIgnore
|
||||
start += skipWhiteSpace.exec(this.state.input)[0].length;
|
||||
const match = literal.exec(this.state.input.slice(start));
|
||||
start += skipWhiteSpace.exec(this.input)[0].length;
|
||||
const match = literal.exec(this.input.slice(start));
|
||||
if (!match) break;
|
||||
if (match[2] === "use strict") return true;
|
||||
start += match[0].length;
|
||||
@@ -189,8 +189,8 @@ export default class UtilParser extends Tokenizer {
|
||||
// Skip semicolon, if any.
|
||||
skipWhiteSpace.lastIndex = start;
|
||||
// $FlowIgnore
|
||||
start += skipWhiteSpace.exec(this.state.input)[0].length;
|
||||
if (this.state.input[start] === ";") {
|
||||
start += skipWhiteSpace.exec(this.input)[0].length;
|
||||
if (this.input[start] === ";") {
|
||||
start++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user