Avoid unnecessary work during lookahead (#9982)
* Do not call pushComment when doing lookahead * Do no updateContext when doing lookahead * Do not clone contexts anymore
This commit is contained in:
parent
47eb1ddfe0
commit
4da7a01aa9
@ -226,11 +226,9 @@ export default class Tokenizer extends LocationParser {
|
||||
loc: new SourceLocation(startLoc, endLoc),
|
||||
};
|
||||
|
||||
if (!this.isLookahead) {
|
||||
if (this.options.tokens) this.state.tokens.push(comment);
|
||||
this.state.comments.push(comment);
|
||||
this.addComment(comment);
|
||||
}
|
||||
if (this.options.tokens) this.state.tokens.push(comment);
|
||||
this.state.comments.push(comment);
|
||||
this.addComment(comment);
|
||||
}
|
||||
|
||||
skipBlockComment(): void {
|
||||
@ -250,6 +248,10 @@ export default class Tokenizer extends LocationParser {
|
||||
this.state.lineStart = match.index + match[0].length;
|
||||
}
|
||||
|
||||
// If we are doing a lookahead right now we need to advance the position (above code)
|
||||
// but we do not want to push the comment to the state.
|
||||
if (this.isLookahead) return;
|
||||
|
||||
this.pushComment(
|
||||
true,
|
||||
this.input.slice(start + 2, end),
|
||||
@ -276,6 +278,10 @@ export default class Tokenizer extends LocationParser {
|
||||
}
|
||||
}
|
||||
|
||||
// If we are doing a lookahead right now we need to advance the position (above code)
|
||||
// but we do not want to push the comment to the state.
|
||||
if (this.isLookahead) return;
|
||||
|
||||
this.pushComment(
|
||||
false,
|
||||
this.input.slice(start + startSkip, this.state.pos),
|
||||
@ -350,7 +356,7 @@ export default class Tokenizer extends LocationParser {
|
||||
this.state.type = type;
|
||||
this.state.value = val;
|
||||
|
||||
this.updateContext(prevType);
|
||||
if (!this.isLookahead) this.updateContext(prevType);
|
||||
}
|
||||
|
||||
// ### Token reading
|
||||
|
||||
@ -170,7 +170,7 @@ export default class State {
|
||||
// $FlowIgnore
|
||||
let val = this[key];
|
||||
|
||||
if ((!skipArrays || key === "context") && Array.isArray(val)) {
|
||||
if (!skipArrays && Array.isArray(val)) {
|
||||
val = val.slice();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user