fix(babel-parser): avoid state.clone() to clone the whole token store (#11029)
* fix(babel-parser): avoid state.clone() to clone the whole token store
Fixed the performance issue on large input when turned on option {tokens: true} and typescript plugin which uses quite a few state.clone().
* test(babel-parser): turn on 2 typescript tests with tokens:true
The output.json is generated by old master to make sure no regression.
* fix(babel-parser): avoid duplicated tokens trapped by mainly typescript/flow plugins
* test(babel-parser): update output.json to latest master result
* chore(babel-parser): improve performance by storing tokensLength in state
This commit is contained in:
committed by
Huáng Jùnliàng
parent
740064ced7
commit
9bc04baeb5
@@ -5,7 +5,6 @@ import * as N from "../types";
|
||||
import { Position } from "../util/location";
|
||||
|
||||
import { types as ct, type TokContext } from "./context";
|
||||
import type { Token } from "./index";
|
||||
import { types as tt, type TokenType } from "./types";
|
||||
|
||||
type TopicContextState = {
|
||||
@@ -93,9 +92,6 @@ export default class State {
|
||||
yieldPos: number = -1;
|
||||
awaitPos: number = -1;
|
||||
|
||||
// Token store.
|
||||
tokens: Array<Token | N.Comment> = [];
|
||||
|
||||
// Comment store.
|
||||
comments: Array<N.Comment> = [];
|
||||
|
||||
@@ -153,6 +149,9 @@ export default class State {
|
||||
// `export default foo;` and `export { foo as default };`.
|
||||
exportedIdentifiers: Array<string> = [];
|
||||
|
||||
// Tokens length in token store
|
||||
tokensLength: number = 0;
|
||||
|
||||
curPosition(): Position {
|
||||
return new Position(this.curLine, this.pos - this.lineStart);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user