GT2/Ejectable/node_modules/sucrase/dist/parser/tokenizer/state.d.ts

49 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-08-16 00:14:59 +00:00
import type { Token } from "./index";
import { ContextualKeyword } from "./keywords";
import { TokenType } from "./types";
export declare class Scope {
startTokenIndex: number;
endTokenIndex: number;
isFunctionScope: boolean;
constructor(startTokenIndex: number, endTokenIndex: number, isFunctionScope: boolean);
}
export declare class StateSnapshot {
readonly potentialArrowAt: number;
readonly noAnonFunctionType: boolean;
readonly tokensLength: number;
readonly scopesLength: number;
readonly pos: number;
readonly type: TokenType;
readonly contextualKeyword: ContextualKeyword;
readonly start: number;
readonly end: number;
readonly isType: boolean;
readonly scopeDepth: number;
readonly error: Error | null;
constructor(potentialArrowAt: number, noAnonFunctionType: boolean, tokensLength: number, scopesLength: number, pos: number, type: TokenType, contextualKeyword: ContextualKeyword, start: number, end: number, isType: boolean, scopeDepth: number, error: Error | null);
}
export default class State {
potentialArrowAt: number;
noAnonFunctionType: boolean;
tokens: Array<Token>;
scopes: Array<Scope>;
pos: number;
type: TokenType;
contextualKeyword: ContextualKeyword;
start: number;
end: number;
isType: boolean;
scopeDepth: number;
/**
* If the parser is in an error state, then the token is always tt.eof and all functions can
* keep executing but should be written so they don't get into an infinite loop in this situation.
*
* This approach, combined with the ability to snapshot and restore state, allows us to implement
* backtracking without exceptions and without needing to explicitly propagate error states
* everywhere.
*/
error: Error | null;
snapshot(): StateSnapshot;
restoreFromSnapshot(snapshot: StateSnapshot): void;
}