1 | import {eat, lookaheadType, match} from "../tokenizer/index";
|
2 | import {TokenType as tt} from "../tokenizer/types";
|
3 | import {isFlowEnabled, isTypeScriptEnabled, state} from "../traverser/base";
|
4 | import {baseParseConditional} from "../traverser/expression";
|
5 | import {flowParseTypeAnnotation} from "./flow";
|
6 | import {tsParseTypeAnnotation} from "./typescript";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export function typedParseConditional(noIn) {
|
14 |
|
15 |
|
16 |
|
17 | if (match(tt.question)) {
|
18 | const nextType = lookaheadType();
|
19 | if (nextType === tt.colon || nextType === tt.comma || nextType === tt.parenR) {
|
20 | return;
|
21 | }
|
22 | }
|
23 | baseParseConditional(noIn);
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 | export function typedParseParenItem() {
|
29 | if (eat(tt.question)) {
|
30 | state.tokens[state.tokens.length - 1].isType = true;
|
31 | }
|
32 | if (match(tt.colon)) {
|
33 | if (isTypeScriptEnabled) {
|
34 | tsParseTypeAnnotation();
|
35 | } else if (isFlowEnabled) {
|
36 | flowParseTypeAnnotation();
|
37 | }
|
38 | }
|
39 | }
|