UNPKG

1.77 kBJavaScriptView Raw
1"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _index = require('../tokenizer/index');
2var _types = require('../tokenizer/types');
3var _base = require('../traverser/base');
4var _expression = require('../traverser/expression');
5var _flow = require('./flow');
6var _typescript = require('./typescript');
7
8/**
9 * Common parser code for TypeScript and Flow.
10 */
11
12// An apparent conditional expression could actually be an optional parameter in an arrow function.
13 function typedParseConditional(noIn) {
14 // If we see ?:, this can't possibly be a valid conditional. typedParseParenItem will be called
15 // later to finish off the arrow parameter. We also need to handle bare ? tokens for optional
16 // parameters without type annotations, i.e. ?, and ?) .
17 if (_index.match.call(void 0, _types.TokenType.question)) {
18 const nextType = _index.lookaheadType.call(void 0, );
19 if (nextType === _types.TokenType.colon || nextType === _types.TokenType.comma || nextType === _types.TokenType.parenR) {
20 return;
21 }
22 }
23 _expression.baseParseConditional.call(void 0, noIn);
24} exports.typedParseConditional = typedParseConditional;
25
26// Note: These "type casts" are *not* valid TS expressions.
27// But we parse them here and change them when completing the arrow function.
28 function typedParseParenItem() {
29 if (_index.eat.call(void 0, _types.TokenType.question)) {
30 _base.state.tokens[_base.state.tokens.length - 1].isType = true;
31 }
32 if (_index.match.call(void 0, _types.TokenType.colon)) {
33 if (_base.isTypeScriptEnabled) {
34 _typescript.tsParseTypeAnnotation.call(void 0, );
35 } else if (_base.isFlowEnabled) {
36 _flow.flowParseTypeAnnotation.call(void 0, );
37 }
38 }
39} exports.typedParseParenItem = typedParseParenItem;