| [9af201e] | 1 | "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _flow = require('../plugins/flow');
|
|---|
| 2 | var _typescript = require('../plugins/typescript');
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | var _index = require('../tokenizer/index');
|
|---|
| 11 | var _keywords = require('../tokenizer/keywords');
|
|---|
| 12 | var _types = require('../tokenizer/types');
|
|---|
| 13 | var _base = require('./base');
|
|---|
| 14 | var _expression = require('./expression');
|
|---|
| 15 | var _util = require('./util');
|
|---|
| 16 |
|
|---|
| 17 | function parseSpread() {
|
|---|
| 18 | _index.next.call(void 0, );
|
|---|
| 19 | _expression.parseMaybeAssign.call(void 0, false);
|
|---|
| 20 | } exports.parseSpread = parseSpread;
|
|---|
| 21 |
|
|---|
| 22 | function parseRest(isBlockScope) {
|
|---|
| 23 | _index.next.call(void 0, );
|
|---|
| 24 | parseBindingAtom(isBlockScope);
|
|---|
| 25 | } exports.parseRest = parseRest;
|
|---|
| 26 |
|
|---|
| 27 | function parseBindingIdentifier(isBlockScope) {
|
|---|
| 28 | _expression.parseIdentifier.call(void 0, );
|
|---|
| 29 | markPriorBindingIdentifier(isBlockScope);
|
|---|
| 30 | } exports.parseBindingIdentifier = parseBindingIdentifier;
|
|---|
| 31 |
|
|---|
| 32 | function parseImportedIdentifier() {
|
|---|
| 33 | _expression.parseIdentifier.call(void 0, );
|
|---|
| 34 | _base.state.tokens[_base.state.tokens.length - 1].identifierRole = _index.IdentifierRole.ImportDeclaration;
|
|---|
| 35 | } exports.parseImportedIdentifier = parseImportedIdentifier;
|
|---|
| 36 |
|
|---|
| 37 | function markPriorBindingIdentifier(isBlockScope) {
|
|---|
| 38 | let identifierRole;
|
|---|
| 39 | if (_base.state.scopeDepth === 0) {
|
|---|
| 40 | identifierRole = _index.IdentifierRole.TopLevelDeclaration;
|
|---|
| 41 | } else if (isBlockScope) {
|
|---|
| 42 | identifierRole = _index.IdentifierRole.BlockScopedDeclaration;
|
|---|
| 43 | } else {
|
|---|
| 44 | identifierRole = _index.IdentifierRole.FunctionScopedDeclaration;
|
|---|
| 45 | }
|
|---|
| 46 | _base.state.tokens[_base.state.tokens.length - 1].identifierRole = identifierRole;
|
|---|
| 47 | } exports.markPriorBindingIdentifier = markPriorBindingIdentifier;
|
|---|
| 48 |
|
|---|
| 49 | // Parses lvalue (assignable) atom.
|
|---|
| 50 | function parseBindingAtom(isBlockScope) {
|
|---|
| 51 | switch (_base.state.type) {
|
|---|
| 52 | case _types.TokenType._this: {
|
|---|
| 53 | // In TypeScript, "this" may be the name of a parameter, so allow it.
|
|---|
| 54 | const oldIsType = _index.pushTypeContext.call(void 0, 0);
|
|---|
| 55 | _index.next.call(void 0, );
|
|---|
| 56 | _index.popTypeContext.call(void 0, oldIsType);
|
|---|
| 57 | return;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | case _types.TokenType._yield:
|
|---|
| 61 | case _types.TokenType.name: {
|
|---|
| 62 | _base.state.type = _types.TokenType.name;
|
|---|
| 63 | parseBindingIdentifier(isBlockScope);
|
|---|
| 64 | return;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | case _types.TokenType.bracketL: {
|
|---|
| 68 | _index.next.call(void 0, );
|
|---|
| 69 | parseBindingList(_types.TokenType.bracketR, isBlockScope, true /* allowEmpty */);
|
|---|
| 70 | return;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | case _types.TokenType.braceL:
|
|---|
| 74 | _expression.parseObj.call(void 0, true, isBlockScope);
|
|---|
| 75 | return;
|
|---|
| 76 |
|
|---|
| 77 | default:
|
|---|
| 78 | _util.unexpected.call(void 0, );
|
|---|
| 79 | }
|
|---|
| 80 | } exports.parseBindingAtom = parseBindingAtom;
|
|---|
| 81 |
|
|---|
| 82 | function parseBindingList(
|
|---|
| 83 | close,
|
|---|
| 84 | isBlockScope,
|
|---|
| 85 | allowEmpty = false,
|
|---|
| 86 | allowModifiers = false,
|
|---|
| 87 | contextId = 0,
|
|---|
| 88 | ) {
|
|---|
| 89 | let first = true;
|
|---|
| 90 |
|
|---|
| 91 | let hasRemovedComma = false;
|
|---|
| 92 | const firstItemTokenIndex = _base.state.tokens.length;
|
|---|
| 93 |
|
|---|
| 94 | while (!_index.eat.call(void 0, close) && !_base.state.error) {
|
|---|
| 95 | if (first) {
|
|---|
| 96 | first = false;
|
|---|
| 97 | } else {
|
|---|
| 98 | _util.expect.call(void 0, _types.TokenType.comma);
|
|---|
| 99 | _base.state.tokens[_base.state.tokens.length - 1].contextId = contextId;
|
|---|
| 100 | // After a "this" type in TypeScript, we need to set the following comma (if any) to also be
|
|---|
| 101 | // a type token so that it will be removed.
|
|---|
| 102 | if (!hasRemovedComma && _base.state.tokens[firstItemTokenIndex].isType) {
|
|---|
| 103 | _base.state.tokens[_base.state.tokens.length - 1].isType = true;
|
|---|
| 104 | hasRemovedComma = true;
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 | if (allowEmpty && _index.match.call(void 0, _types.TokenType.comma)) {
|
|---|
| 108 | // Empty item; nothing further to parse for this item.
|
|---|
| 109 | } else if (_index.eat.call(void 0, close)) {
|
|---|
| 110 | break;
|
|---|
| 111 | } else if (_index.match.call(void 0, _types.TokenType.ellipsis)) {
|
|---|
| 112 | parseRest(isBlockScope);
|
|---|
| 113 | parseAssignableListItemTypes();
|
|---|
| 114 | // Support rest element trailing commas allowed by TypeScript <2.9.
|
|---|
| 115 | _index.eat.call(void 0, _types.TokenType.comma);
|
|---|
| 116 | _util.expect.call(void 0, close);
|
|---|
| 117 | break;
|
|---|
| 118 | } else {
|
|---|
| 119 | parseAssignableListItem(allowModifiers, isBlockScope);
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 | } exports.parseBindingList = parseBindingList;
|
|---|
| 123 |
|
|---|
| 124 | function parseAssignableListItem(allowModifiers, isBlockScope) {
|
|---|
| 125 | if (allowModifiers) {
|
|---|
| 126 | _typescript.tsParseModifiers.call(void 0, [
|
|---|
| 127 | _keywords.ContextualKeyword._public,
|
|---|
| 128 | _keywords.ContextualKeyword._protected,
|
|---|
| 129 | _keywords.ContextualKeyword._private,
|
|---|
| 130 | _keywords.ContextualKeyword._readonly,
|
|---|
| 131 | _keywords.ContextualKeyword._override,
|
|---|
| 132 | ]);
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | parseMaybeDefault(isBlockScope);
|
|---|
| 136 | parseAssignableListItemTypes();
|
|---|
| 137 | parseMaybeDefault(isBlockScope, true /* leftAlreadyParsed */);
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | function parseAssignableListItemTypes() {
|
|---|
| 141 | if (_base.isFlowEnabled) {
|
|---|
| 142 | _flow.flowParseAssignableListItemTypes.call(void 0, );
|
|---|
| 143 | } else if (_base.isTypeScriptEnabled) {
|
|---|
| 144 | _typescript.tsParseAssignableListItemTypes.call(void 0, );
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | // Parses assignment pattern around given atom if possible.
|
|---|
| 149 | function parseMaybeDefault(isBlockScope, leftAlreadyParsed = false) {
|
|---|
| 150 | if (!leftAlreadyParsed) {
|
|---|
| 151 | parseBindingAtom(isBlockScope);
|
|---|
| 152 | }
|
|---|
| 153 | if (!_index.eat.call(void 0, _types.TokenType.eq)) {
|
|---|
| 154 | return;
|
|---|
| 155 | }
|
|---|
| 156 | const eqIndex = _base.state.tokens.length - 1;
|
|---|
| 157 | _expression.parseMaybeAssign.call(void 0, );
|
|---|
| 158 | _base.state.tokens[eqIndex].rhsEndIndex = _base.state.tokens.length;
|
|---|
| 159 | } exports.parseMaybeDefault = parseMaybeDefault;
|
|---|