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

Function parsePropertyName

packages/babel-parser/src/parser/expression.ts:2406–2460  ·  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

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

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