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

Function parseObjectProperty

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

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