UNPKG

1.9 kBTypeScriptView Raw
1import { Token } from "./index";
2import { ContextualKeyword } from "./keywords";
3import { TokenType } from "./types";
4export declare class Scope {
5 startTokenIndex: number;
6 endTokenIndex: number;
7 isFunctionScope: boolean;
8 constructor(startTokenIndex: number, endTokenIndex: number, isFunctionScope: boolean);
9}
10export declare class StateSnapshot {
11 readonly potentialArrowAt: number;
12 readonly noAnonFunctionType: boolean;
13 readonly tokensLength: number;
14 readonly scopesLength: number;
15 readonly pos: number;
16 readonly type: TokenType;
17 readonly contextualKeyword: ContextualKeyword;
18 readonly start: number;
19 readonly end: number;
20 readonly isType: boolean;
21 readonly scopeDepth: number;
22 readonly error: Error | null;
23 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);
24}
25export default class State {
26 potentialArrowAt: number;
27 noAnonFunctionType: boolean;
28 tokens: Array<Token>;
29 scopes: Array<Scope>;
30 pos: number;
31 type: TokenType;
32 contextualKeyword: ContextualKeyword;
33 start: number;
34 end: number;
35 isType: boolean;
36 scopeDepth: number;
37 /**
38 * If the parser is in an error state, then the token is always tt.eof and all functions can
39 * keep executing but should be written so they don't get into an infinite loop in this situation.
40 *
41 * This approach, combined with the ability to snapshot and restore state, allows us to implement
42 * backtracking without exceptions and without needing to explicitly propagate error states
43 * everywhere.
44 */
45 error: Error | null;
46 snapshot(): StateSnapshot;
47 restoreFromSnapshot(snapshot: StateSnapshot): void;
48}