Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: defer lookaheadState to Babel 8 #13383

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 24 additions & 12 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -182,17 +182,29 @@ export default class Tokenizer extends ParserErrors {
* @memberof Tokenizer
*/
createLookaheadState(state: State): LookaheadState {
return {
pos: state.pos,
value: null,
type: state.type,
start: state.start,
end: state.end,
lastTokEnd: state.end,
context: [this.curContext()],
exprAllowed: state.exprAllowed,
inType: state.inType,
};
if (process.env.BABEL_8_BREAKING) {
const { pos, type, start, end, exprAllowed, inType } = state;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use destructuring here to avoid double object access (state.end) and redundant object slot initialization, see #13341 (comment)

return {
pos: pos,
value: null,
type: type,
start: start,
end: end,
lastTokEnd: end,
// exprAllowed and inType is only used in readToken_slash
exprAllowed: exprAllowed,
inType: inType,
context: [this.curContext()],
};
} else {
// We observe inconsistent behavior in
// https://github.com/babel/babel/pull/13374
// which is likely a crankshaft bug, we don't expect it
// will be fixed since Node.js 6 reaches EOL.
// Before we drop Node 6 support, we have to clone
// the complete parser state
return state.clone();
}
}

/**
Expand All @@ -213,7 +225,7 @@ export default class Tokenizer extends ParserErrors {
*/
lookahead(): LookaheadState {
const old = this.state;
// For performance we use a simpified tokenizer state structure
// In Babel 8 we use a simpified tokenizer state structure
// $FlowIgnore
this.state = this.createLookaheadState(old);

Expand Down