UNPKG

2.88 kBTypeScriptView Raw
1import type { HelperManager } from "./HelperManager";
2import type { Token } from "./parser/tokenizer";
3import type { ContextualKeyword } from "./parser/tokenizer/keywords";
4import { TokenType } from "./parser/tokenizer/types";
5export interface TokenProcessorSnapshot {
6 resultCode: string;
7 tokenIndex: number;
8}
9export default class TokenProcessor {
10 readonly code: string;
11 readonly tokens: Array<Token>;
12 readonly isFlowEnabled: boolean;
13 readonly disableESTransforms: boolean;
14 readonly helperManager: HelperManager;
15 private resultCode;
16 private tokenIndex;
17 constructor(code: string, tokens: Array<Token>, isFlowEnabled: boolean, disableESTransforms: boolean, helperManager: HelperManager);
18 /**
19 * Make a new TokenProcessor for things like lookahead.
20 */
21 snapshot(): TokenProcessorSnapshot;
22 restoreToSnapshot(snapshot: TokenProcessorSnapshot): void;
23 getResultCodeIndex(): number;
24 reset(): void;
25 matchesContextualAtIndex(index: number, contextualKeyword: ContextualKeyword): boolean;
26 identifierNameAtIndex(index: number): string;
27 identifierName(): string;
28 identifierNameForToken(token: Token): string;
29 rawCodeForToken(token: Token): string;
30 stringValueAtIndex(index: number): string;
31 stringValue(): string;
32 stringValueForToken(token: Token): string;
33 matches1AtIndex(index: number, t1: TokenType): boolean;
34 matches2AtIndex(index: number, t1: TokenType, t2: TokenType): boolean;
35 matches3AtIndex(index: number, t1: TokenType, t2: TokenType, t3: TokenType): boolean;
36 matches1(t1: TokenType): boolean;
37 matches2(t1: TokenType, t2: TokenType): boolean;
38 matches3(t1: TokenType, t2: TokenType, t3: TokenType): boolean;
39 matches4(t1: TokenType, t2: TokenType, t3: TokenType, t4: TokenType): boolean;
40 matches5(t1: TokenType, t2: TokenType, t3: TokenType, t4: TokenType, t5: TokenType): boolean;
41 matchesContextual(contextualKeyword: ContextualKeyword): boolean;
42 matchesContextIdAndLabel(type: TokenType, contextId: number): boolean;
43 previousWhitespaceAndComments(): string;
44 replaceToken(newCode: string): void;
45 replaceTokenTrimmingLeftWhitespace(newCode: string): void;
46 removeInitialToken(): void;
47 removeToken(): void;
48 copyExpectedToken(tokenType: TokenType): void;
49 copyToken(): void;
50 copyTokenWithPrefix(prefix: string): void;
51 private appendTokenPrefix;
52 private appendTokenSuffix;
53 appendCode(code: string): void;
54 currentToken(): Token;
55 currentTokenCode(): string;
56 tokenAtRelativeIndex(relativeIndex: number): Token;
57 currentIndex(): number;
58 /**
59 * Move to the next token. Only suitable in preprocessing steps. When
60 * generating new code, you should use copyToken or removeToken.
61 */
62 nextToken(): void;
63 previousToken(): void;
64 finish(): string;
65 isAtEnd(): boolean;
66}