UNPKG

1.7 kBTypeScriptView Raw
1import type NameManager from "../NameManager";
2import type TokenProcessor from "../TokenProcessor";
3import Transformer from "./Transformer";
4/**
5 * Transformer supporting the optional chaining and nullish coalescing operators.
6 *
7 * Tech plan here:
8 * https://github.com/alangpierce/sucrase/wiki/Sucrase-Optional-Chaining-and-Nullish-Coalescing-Technical-Plan
9 *
10 * The prefix and suffix code snippets are handled by TokenProcessor, and this transformer handles
11 * the operators themselves.
12 */
13export default class OptionalChainingNullishTransformer extends Transformer {
14 readonly tokens: TokenProcessor;
15 readonly nameManager: NameManager;
16 constructor(tokens: TokenProcessor, nameManager: NameManager);
17 process(): boolean;
18 /**
19 * Determine if the current token is the last of its chain, so that we know whether it's eligible
20 * to have a delete op inserted.
21 *
22 * We can do this by walking forward until we determine one way or another. Each
23 * isOptionalChainStart token must be paired with exactly one isOptionalChainEnd token after it in
24 * a nesting way, so we can track depth and walk to the end of the chain (the point where the
25 * depth goes negative) and see if any other subscript token is after us in the chain.
26 */
27 isLastSubscriptInChain(): boolean;
28 /**
29 * Determine if we are the open-paren in an expression like super.a()?.b.
30 *
31 * We can do this by walking backward to find the previous subscript. If that subscript was
32 * preceded by a super, then we must be the subscript after it, so if this is a call expression,
33 * we'll need to attach the right context.
34 */
35 justSkippedSuper(): boolean;
36}