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

Function parseObjectProperty

packages/babel-parser/src/parser/expression.ts:2316–2368  ·  view source on GitHub ↗
(
    this: Parser,
    prop: Undone<N.ObjectProperty>,
    startLoc: Position | undefined | null,
    isPattern: boolean,
    refExpressionErrors?: ExpressionErrors | null,
  )

Source from the content-addressed store, hash-verified

2314 // if `isPattern` is true, parse https://tc39.es/ecma262/#prod-BindingProperty
2315 // else https://tc39.es/ecma262/#prod-PropertyDefinition
2316 parseObjectProperty(
2317 this: Parser,
2318 prop: Undone<N.ObjectProperty>,
2319 startLoc: Position | undefined | null,
2320 isPattern: boolean,
2321 refExpressionErrors?: ExpressionErrors | null,
2322 ): N.ObjectProperty | undefined | null {
2323 prop.shorthand = false;
2324
2325 if (this.eat(tt.colon)) {
2326 prop.value = isPattern
2327 ? this.parseMaybeDefault(this.state.startLoc)
2328 : this.parseMaybeAssignAllowInOrVoidPattern(
2329 tt.braceR,
2330 refExpressionErrors,
2331 );
2332
2333 return this.finishObjectProperty(prop);
2334 }
2335
2336 if (!prop.computed && prop.key.type === "Identifier") {
2337 // PropertyDefinition:
2338 // IdentifierReference
2339 // CoverInitializedName
2340 // Note: `{ eval } = {}` will be checked in `checkLVal` later.
2341 this.checkReservedWord(prop.key.name, prop.key.start!, true, false);
2342
2343 if (isPattern) {
2344 prop.value = this.parseMaybeDefault(
2345 startLoc,
2346 this.cloneIdentifier(prop.key),
2347 );
2348 } else if (this.match(tt.eq)) {
2349 const shorthandAssignLoc = this.state.startLoc;
2350 if (refExpressionErrors != null) {
2351 if (refExpressionErrors.shorthandAssignLoc === null) {
2352 refExpressionErrors.shorthandAssignLoc = shorthandAssignLoc;
2353 }
2354 } else {
2355 this.raise(Errors.InvalidCoverInitializedName, shorthandAssignLoc);
2356 }
2357 prop.value = this.parseMaybeDefault(
2358 startLoc,
2359 this.cloneIdentifier(prop.key),
2360 );
2361 } else {
2362 prop.value = this.cloneIdentifier(prop.key);
2363 }
2364 prop.shorthand = true;
2365
2366 return this.finishObjectProperty(prop);
2367 }
2368 }
2369
2370 finishObjectProperty(node: Undone<N.ObjectProperty>) {
2371 return this.finishNode(node, "ObjectProperty");

Callers

nothing calls this directly

Calls 5

finishObjectPropertyMethod · 0.80
matchMethod · 0.80
parseMaybeDefaultMethod · 0.45
checkReservedWordMethod · 0.45
cloneIdentifierMethod · 0.45

Tested by

no test coverage detected