MCPcopy Create free account
hub / github.com/babel/babel / parsePropertyName

Function parsePropertyName

packages/babel-parser/src/parser/expression.ts:2405–2459  ·  view source on GitHub ↗
(
    this: Parser,
    prop:
      | Undone<N.ObjectOrClassMember | N.ClassMember>
      | N.TSPropertySignature
      | N.TSMethodSignature,
    refExpressionErrors?: ExpressionErrors | null,
  )

Source from the content-addressed store, hash-verified

2403 // when refExpressionErrors presents, it will parse private name
2404 // and record the position of the first private name
2405 parsePropertyName(
2406 this: Parser,
2407 prop:
2408 | Undone<N.ObjectOrClassMember | N.ClassMember>
2409 | N.TSPropertySignature
2410 | N.TSMethodSignature,
2411 refExpressionErrors?: ExpressionErrors | null,
2412 ): void {
2413 if (this.eat(tt.bracketL)) {
2414 (prop as Undone<N.ObjectOrClassMember>).computed = true;
2415 prop.key = this.parseMaybeAssignAllowIn();
2416 this.expect(tt.bracketR);
2417 } else {
2418 // We check if it's valid for it to be a private name when we push it.
2419 const { type, value } = this.state;
2420 let key;
2421 // most un-computed property names are identifiers
2422 if (tokenIsKeywordOrIdentifier(type)) {
2423 key = this.parseIdentifier(true);
2424 } else {
2425 switch (type) {
2426 case tt.num:
2427 key = this.parseNumericLiteral(value);
2428 break;
2429 case tt.string:
2430 key = this.parseStringLiteral(value);
2431 break;
2432 case tt.bigint:
2433 key = this.parseBigIntLiteral(value);
2434 break;
2435 case tt.privateName: {
2436 // the class private key has been handled in parseClassElementName
2437 const privateKeyLoc = this.state.startLoc;
2438 if (refExpressionErrors != null) {
2439 if (refExpressionErrors.privateKeyLoc === null) {
2440 refExpressionErrors.privateKeyLoc = privateKeyLoc;
2441 }
2442 } else {
2443 this.raise(Errors.UnexpectedPrivateField, privateKeyLoc);
2444 }
2445 key = this.parsePrivateName();
2446 break;
2447 }
2448 default:
2449 throw this.unexpected();
2450 }
2451 }
2452 prop.key = key;
2453 if (type !== tt.privateName) {
2454 // @ts-expect-error todo: computed is not defined on TSPropertySignature
2455 // ClassPrivateProperty is never computed, so we don't assign in that case.
2456 prop.computed = false;
2457 }
2458 }
2459 }
2460
2461 // Initialize empty function node.
2462

Callers

nothing calls this directly

Calls 6

parseIdentifierMethod · 0.80
parseNumericLiteralMethod · 0.80
parseStringLiteralMethod · 0.80
parseBigIntLiteralMethod · 0.80
parsePrivateNameMethod · 0.80

Tested by

no test coverage detected