Remove input and length from state (#9646)

This commit is contained in:
Daniel Tschinder
2019-03-11 00:42:42 -07:00
committed by GitHub
parent ec318d01fa
commit cf4bd8bb8d
11 changed files with 147 additions and 182 deletions

View File

@@ -1137,7 +1137,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
node.types = [];
this.expect(tt.bracketL);
// We allow trailing commas
while (this.state.pos < this.state.length && !this.match(tt.bracketR)) {
while (this.state.pos < this.length && !this.match(tt.bracketR)) {
node.types.push(this.flowParseType());
if (this.match(tt.bracketR)) break;
this.expect(tt.comma);
@@ -1938,7 +1938,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// ensure that inside flow types, we bypass the jsx parser plugin
getTokenFromCode(code: number): void {
const next = this.state.input.charCodeAt(this.state.pos + 1);
const next = this.input.charCodeAt(this.state.pos + 1);
if (code === charCodes.leftCurlyBrace && next === charCodes.verticalBar) {
return this.finishOp(tt.braceBarL, 2);
} else if (
@@ -2710,7 +2710,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
readToken_mult_modulo(code: number): void {
const next = this.state.input.charCodeAt(this.state.pos + 1);
const next = this.input.charCodeAt(this.state.pos + 1);
if (
code === charCodes.asterisk &&
next === charCodes.slash &&
@@ -2726,7 +2726,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
readToken_pipe_amp(code: number): void {
const next = this.state.input.charCodeAt(this.state.pos + 1);
const next = this.input.charCodeAt(this.state.pos + 1);
if (
code === charCodes.verticalBar &&
next === charCodes.rightCurlyBrace
@@ -2762,7 +2762,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
if (this.state.hasFlowComment) {
const end = this.state.input.indexOf("*-/", (this.state.pos += 2));
const end = this.input.indexOf("*-/", (this.state.pos += 2));
if (end === -1) this.raise(this.state.pos - 2, "Unterminated comment");
this.state.pos = end + 3;
return;
@@ -2776,22 +2776,20 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let shiftToFirstNonWhiteSpace = 2;
while (
[charCodes.space, charCodes.tab].includes(
this.state.input.charCodeAt(pos + shiftToFirstNonWhiteSpace),
this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace),
)
) {
shiftToFirstNonWhiteSpace++;
}
const ch2 = this.state.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
const ch3 = this.state.input.charCodeAt(
shiftToFirstNonWhiteSpace + pos + 1,
);
const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
if (ch2 === charCodes.colon && ch3 === charCodes.colon) {
return shiftToFirstNonWhiteSpace + 2; // check for /*::
}
if (
this.state.input.slice(
this.input.slice(
shiftToFirstNonWhiteSpace + pos,
shiftToFirstNonWhiteSpace + pos + 12,
) === "flow-include"
@@ -2805,7 +2803,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
hasFlowCommentCompletion(): void {
const end = this.state.input.indexOf("*/", this.state.pos);
const end = this.input.indexOf("*/", this.state.pos);
if (end === -1) {
this.raise(this.state.pos, "Unterminated comment");
}

View File

@@ -81,11 +81,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let out = "";
let chunkStart = this.state.pos;
for (;;) {
if (this.state.pos >= this.state.length) {
if (this.state.pos >= this.length) {
this.raise(this.state.start, "Unterminated JSX contents");
}
const ch = this.state.input.charCodeAt(this.state.pos);
const ch = this.input.charCodeAt(this.state.pos);
switch (ch) {
case charCodes.lessThan:
@@ -97,18 +97,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
return super.getTokenFromCode(ch);
}
out += this.state.input.slice(chunkStart, this.state.pos);
out += this.input.slice(chunkStart, this.state.pos);
return this.finishToken(tt.jsxText, out);
case charCodes.ampersand:
out += this.state.input.slice(chunkStart, this.state.pos);
out += this.input.slice(chunkStart, this.state.pos);
out += this.jsxReadEntity();
chunkStart = this.state.pos;
break;
default:
if (isNewLine(ch)) {
out += this.state.input.slice(chunkStart, this.state.pos);
out += this.input.slice(chunkStart, this.state.pos);
out += this.jsxReadNewLine(true);
chunkStart = this.state.pos;
} else {
@@ -119,12 +119,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
jsxReadNewLine(normalizeCRLF: boolean): string {
const ch = this.state.input.charCodeAt(this.state.pos);
const ch = this.input.charCodeAt(this.state.pos);
let out;
++this.state.pos;
if (
ch === charCodes.carriageReturn &&
this.state.input.charCodeAt(this.state.pos) === charCodes.lineFeed
this.input.charCodeAt(this.state.pos) === charCodes.lineFeed
) {
++this.state.pos;
out = normalizeCRLF ? "\n" : "\r\n";
@@ -141,25 +141,25 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let out = "";
let chunkStart = ++this.state.pos;
for (;;) {
if (this.state.pos >= this.state.length) {
if (this.state.pos >= this.length) {
this.raise(this.state.start, "Unterminated string constant");
}
const ch = this.state.input.charCodeAt(this.state.pos);
const ch = this.input.charCodeAt(this.state.pos);
if (ch === quote) break;
if (ch === charCodes.ampersand) {
out += this.state.input.slice(chunkStart, this.state.pos);
out += this.input.slice(chunkStart, this.state.pos);
out += this.jsxReadEntity();
chunkStart = this.state.pos;
} else if (isNewLine(ch)) {
out += this.state.input.slice(chunkStart, this.state.pos);
out += this.input.slice(chunkStart, this.state.pos);
out += this.jsxReadNewLine(false);
chunkStart = this.state.pos;
} else {
++this.state.pos;
}
}
out += this.state.input.slice(chunkStart, this.state.pos++);
out += this.input.slice(chunkStart, this.state.pos++);
return this.finishToken(tt.string, out);
}
@@ -167,11 +167,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let str = "";
let count = 0;
let entity;
let ch = this.state.input[this.state.pos];
let ch = this.input[this.state.pos];
const startPos = ++this.state.pos;
while (this.state.pos < this.state.length && count++ < 10) {
ch = this.state.input[this.state.pos++];
while (this.state.pos < this.length && count++ < 10) {
ch = this.input[this.state.pos++];
if (ch === ";") {
if (str[0] === "#") {
if (str[1] === "x") {
@@ -210,11 +210,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
let ch;
const start = this.state.pos;
do {
ch = this.state.input.charCodeAt(++this.state.pos);
ch = this.input.charCodeAt(++this.state.pos);
} while (isIdentifierChar(ch) || ch === charCodes.dash);
return this.finishToken(
tt.jsxName,
this.state.input.slice(start, this.state.pos),
this.input.slice(start, this.state.pos),
);
}
@@ -510,8 +510,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return this.jsxParseElement();
} else if (
this.isRelational("<") &&
this.state.input.charCodeAt(this.state.pos) !==
charCodes.exclamationMark
this.input.charCodeAt(this.state.pos) !== charCodes.exclamationMark
) {
// In case we encounter an lt token here it will always be the start of
// jsx as the lt sign is not allowed in places that expect an expression
@@ -552,8 +551,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (
code === charCodes.lessThan &&
this.state.exprAllowed &&
this.state.input.charCodeAt(this.state.pos + 1) !==
charCodes.exclamationMark
this.input.charCodeAt(this.state.pos + 1) !== charCodes.exclamationMark
) {
++this.state.pos;
return this.finishToken(tt.jsxTagStart);

View File

@@ -82,8 +82,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
getTokenFromCode(code: number) {
if (
code === charCodes.percentSign &&
this.state.input.charCodeAt(this.state.pos + 1) ===
charCodes.percentSign
this.input.charCodeAt(this.state.pos + 1) === charCodes.percentSign
) {
return this.finishOp(tt.placeholder, 2);
}