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

Function parseObjectLike

packages/babel-parser/src/parser/expression.ts:2091–2132  ·  view source on GitHub ↗
(
    this: Parser,
    close: TokenType,
    isPattern: boolean,
    refExpressionErrors?: ExpressionErrors | null,
  )

Source from the content-addressed store, hash-verified

2089 refExpressionErrors?: ExpressionErrors | null,
2090 ): N.ObjectExpression;
2091 parseObjectLike<T extends N.ObjectPattern | N.ObjectExpression>(
2092 this: Parser,
2093 close: TokenType,
2094 isPattern: boolean,
2095 refExpressionErrors?: ExpressionErrors | null,
2096 ): T {
2097 let sawProto = false;
2098 let first = true;
2099 const node = this.startNode<N.ObjectExpression | N.ObjectPattern>();
2100
2101 node.properties = [];
2102 this.next();
2103
2104 while (!this.match(close)) {
2105 if (first) {
2106 first = false;
2107 } else {
2108 this.expect(tt.comma);
2109 if (this.match(close)) {
2110 this.addTrailingCommaExtraToNode(node);
2111 break;
2112 }
2113 }
2114
2115 let prop;
2116 if (isPattern) {
2117 prop = this.parseBindingProperty();
2118 } else {
2119 prop = this.parsePropertyDefinition(refExpressionErrors);
2120 sawProto = this.checkProto(prop, sawProto, refExpressionErrors);
2121 }
2122
2123 // @ts-expect-error Fixme: refine typings
2124 node.properties.push(prop);
2125 }
2126
2127 this.next();
2128
2129 const type = isPattern ? "ObjectPattern" : "ObjectExpression";
2130 // @ts-expect-error type is well defined
2131 return this.finishNode(node, type);
2132 }
2133
2134 addTrailingCommaExtraToNode(node: Undone<N.Node>): void {
2135 this.addExtra(node, "trailingComma", this.state.lastTokStartLoc!.index);

Callers

nothing calls this directly

Calls 4

nextMethod · 0.80
matchMethod · 0.80
finishNodeMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected