UNPKG

sucrase

Version:

Super-fast alternative to Babel for when you can target modern JS runtimes

53 lines (52 loc) 2.01 kB
import { Token } from "../sucrase-babylon/tokenizer"; export declare type TokenProcessorSnapshot = { resultCode: string; tokenIndex: number; }; export default class TokenProcessor { readonly code: string; readonly tokens: Array<Token>; private resultCode; private tokenIndex; constructor(code: string, tokens: Array<Token>); /** * Make a new TokenProcessor for things like lookahead. */ snapshot(): TokenProcessorSnapshot; restoreToSnapshot(snapshot: TokenProcessorSnapshot): void; getResultCodeIndex(): number; getCodeInsertedSinceIndex(initialResultCodeIndex: number): string; reset(): void; matchesAtIndex(index: number, tagLabels: Array<string>): boolean; matchesNameAtIndex(index: number, name: string): boolean; matchesNameAtRelativeIndex(relativeIndex: number, name: string): boolean; matchesAtRelativeIndex(relativeIndex: number, tagLabels: Array<string>): boolean; matches(tagLabels: Array<string>): boolean; matchesName(name: string): boolean; /** * Check if this is a "real" instance of the keyword rather than an object key or property access. */ matchesKeyword(name: string): boolean; matchesContextIdAndLabel(label: string, contextId: number): boolean; previousWhitespace(): string; replaceToken(newCode: string): void; replaceTokenTrimmingLeftWhitespace(newCode: string): void; removeInitialToken(): void; removeToken(): void; copyExpectedToken(label: string): void; copyToken(): void; appendCode(code: string): void; currentToken(): Token; currentTokenCode(): string; tokenAtRelativeIndex(relativeIndex: number): Token; currentIndex(): number; /** * Move to the next token. Only suitable in preprocessing steps. When * generating new code, you should use copyToken or removeToken. */ nextToken(): void; previousToken(): void; expectToken(label: string): void; finish(): string; isAtEnd(): boolean; }