()
| 1146 | } |
| 1147 | |
| 1148 | private parsePrimary(): AST { |
| 1149 | const start = this.inputIndex; |
| 1150 | if (this.isArrowFunction()) { |
| 1151 | return this.parseArrowFunction(start); |
| 1152 | } else if (this.consumeOptionalCharacter(chars.$LPAREN)) { |
| 1153 | this.rparensExpected++; |
| 1154 | const result = this.parsePipe(); |
| 1155 | if (!this.consumeOptionalCharacter(chars.$RPAREN)) { |
| 1156 | this.error('Missing closing parentheses'); |
| 1157 | // Calling into `error` above will attempt to recover up until the next closing paren. |
| 1158 | // If that's the case, consume it so we can partially recover the expression. |
| 1159 | this.consumeOptionalCharacter(chars.$RPAREN); |
| 1160 | } |
| 1161 | this.rparensExpected--; |
| 1162 | return new ParenthesizedExpression(this.span(start), this.sourceSpan(start), result); |
| 1163 | } else if (this.next.isKeywordNull()) { |
| 1164 | this.advance(); |
| 1165 | return new LiteralPrimitive(this.span(start), this.sourceSpan(start), null); |
| 1166 | } else if (this.next.isKeywordUndefined()) { |
| 1167 | this.advance(); |
| 1168 | return new LiteralPrimitive(this.span(start), this.sourceSpan(start), undefined); |
| 1169 | } else if (this.next.isKeywordTrue()) { |
| 1170 | this.advance(); |
| 1171 | return new LiteralPrimitive(this.span(start), this.sourceSpan(start), true); |
| 1172 | } else if (this.next.isKeywordFalse()) { |
| 1173 | this.advance(); |
| 1174 | return new LiteralPrimitive(this.span(start), this.sourceSpan(start), false); |
| 1175 | } else if (this.next.isKeywordThis()) { |
| 1176 | this.advance(); |
| 1177 | return new ThisReceiver(this.span(start), this.sourceSpan(start)); |
| 1178 | } else if (this.consumeOptionalCharacter(chars.$LBRACKET)) { |
| 1179 | return this.parseLiteralArray(start); |
| 1180 | } else if (this.next.isCharacter(chars.$LBRACE)) { |
| 1181 | return this.parseLiteralMap(); |
| 1182 | } else if (this.next.isIdentifier()) { |
| 1183 | return this.parseAccessMember( |
| 1184 | new ImplicitReceiver(this.span(start), this.sourceSpan(start)), |
| 1185 | start, |
| 1186 | false, |
| 1187 | ); |
| 1188 | } else if (this.next.isNumber()) { |
| 1189 | const value = this.next.toNumber(); |
| 1190 | this.advance(); |
| 1191 | return new LiteralPrimitive(this.span(start), this.sourceSpan(start), value); |
| 1192 | } else if (this.next.isTemplateLiteralEnd()) { |
| 1193 | return this.parseNoInterpolationTemplateLiteral(); |
| 1194 | } else if (this.next.isTemplateLiteralPart()) { |
| 1195 | return this.parseTemplateLiteral(); |
| 1196 | } else if (this.next.isString() && this.next.kind === StringTokenKind.Plain) { |
| 1197 | const literalValue = this.next.toString(); |
| 1198 | this.advance(); |
| 1199 | return new LiteralPrimitive(this.span(start), this.sourceSpan(start), literalValue); |
| 1200 | } else if (this.next.isPrivateIdentifier()) { |
| 1201 | this._reportErrorForPrivateIdentifier(this.next, null); |
| 1202 | return new EmptyExpr(this.span(start), this.sourceSpan(start)); |
| 1203 | } else if (this.next.isRegExpBody()) { |
| 1204 | return this.parseRegularExpressionLiteral(); |
| 1205 | } else if (this.index >= this.tokens.length) { |
no test coverage detected