parser: don't mutate or clone state arrays when doing a lookahead - fixes #2211
This commit is contained in:
parent
860322f7b8
commit
ac9ee75dac
@ -56,7 +56,9 @@ export default class Tokenizer {
|
||||
// Move to the next token
|
||||
|
||||
next() {
|
||||
this.state.tokens.push(new Token(this.state));
|
||||
if (!this.isLookahead) {
|
||||
this.state.tokens.push(new Token(this.state));
|
||||
}
|
||||
|
||||
this.state.lastTokEnd = this.state.end;
|
||||
this.state.lastTokStart = this.state.start;
|
||||
@ -102,9 +104,13 @@ export default class Tokenizer {
|
||||
|
||||
lookahead() {
|
||||
var old = this.state;
|
||||
this.state = old.clone();
|
||||
this.state = old.clone(true);
|
||||
|
||||
this.isLookahead = true;
|
||||
this.next();
|
||||
var curr = this.state.clone();
|
||||
this.isLookahead = false;
|
||||
|
||||
var curr = this.state.clone(true);
|
||||
this.state = old;
|
||||
return curr;
|
||||
}
|
||||
@ -172,8 +178,10 @@ export default class Tokenizer {
|
||||
range: [start, end]
|
||||
};
|
||||
|
||||
this.state.tokens.push(comment);
|
||||
this.state.comments.push(comment);
|
||||
if (!this.isLookahead) {
|
||||
this.state.tokens.push(comment);
|
||||
this.state.comments.push(comment);
|
||||
}
|
||||
this.addComment(comment);
|
||||
}
|
||||
|
||||
|
||||
@ -70,11 +70,15 @@ export default class State {
|
||||
return new Position(this.curLine, this.pos - this.lineStart);
|
||||
}
|
||||
|
||||
clone() {
|
||||
clone(skipArrays?) {
|
||||
var state = new State;
|
||||
for (var key in this) {
|
||||
var val = this[key];
|
||||
if (Array.isArray(val)) val = val.slice();
|
||||
|
||||
if (!skipArrays && Array.isArray(val)) {
|
||||
val = val.slice();
|
||||
}
|
||||
|
||||
state[key] = val;
|
||||
}
|
||||
return state;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user