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

Function parsePropertyDefinition

packages/babel-parser/src/parser/expression.ts:2155–2236  ·  view source on GitHub ↗
(
    this: Parser,
    refExpressionErrors?: ExpressionErrors | null,
  )

Source from the content-addressed store, hash-verified

2153
2154 // https://tc39.es/ecma262/#prod-PropertyDefinition
2155 parsePropertyDefinition(
2156 this: Parser,
2157 refExpressionErrors?: ExpressionErrors | null,
2158 ): N.ObjectMember | N.SpreadElement {
2159 const decorators = [];
2160 const decoratorsStartLoc = this.state.startLoc;
2161 if (this.match(tt.at)) {
2162 if (this.hasPlugin("decorators")) {
2163 this.raise(Errors.UnsupportedPropertyDecorator, decoratorsStartLoc);
2164 }
2165
2166 // we needn't check if decorators (stage 0) plugin is enabled since it's checked by
2167 // the call to this.parseDecorator
2168 while (this.match(tt.at)) {
2169 decorators.push(this.parseDecorator());
2170 }
2171 }
2172
2173 if (this.match(tt.ellipsis)) {
2174 if (decorators.length) this.unexpected();
2175 return this.parseSpread();
2176 }
2177
2178 const prop = this.startNodeAt<N.ObjectProperty | N.ObjectMethod>(
2179 decoratorsStartLoc,
2180 );
2181 let isAsync = false;
2182 let isAccessor = false;
2183
2184 if (decorators.length) {
2185 prop.decorators = decorators;
2186 }
2187
2188 // @ts-expect-error todo: Undocumented property for ESTree compatibility.
2189 // Consider move to the ESTree plugin
2190 prop.method = false;
2191
2192 const startLoc = this.state.startLoc;
2193
2194 let isGenerator = this.eat(tt.star);
2195 this.parsePropertyNamePrefixOperator(prop);
2196 const containsEsc = this.state.containsEsc;
2197 this.parsePropertyName(prop, refExpressionErrors);
2198
2199 if (!isGenerator && !containsEsc && this.maybeAsyncOrAccessorProp(prop)) {
2200 const { key } = prop;
2201 const keyName = key.name;
2202 // https://tc39.es/ecma262/#prod-AsyncMethod
2203 // https://tc39.es/ecma262/#prod-AsyncGeneratorMethod
2204 if (keyName === "async" && !this.hasPrecedingLineBreak()) {
2205 isAsync = true;
2206 this.resetPreviousNodeTrailingComments(key);
2207 isGenerator = this.eat(tt.star);
2208 this.parsePropertyName(prop);
2209 }
2210 // get PropertyName[?Yield, ?Await] () { FunctionBody[~Yield, ~Await] }
2211 // set PropertyName[?Yield, ?Await] ( PropertySetParameterList ) { FunctionBody[~Yield, ~Await] }
2212 if (keyName === "get" || keyName === "set") {

Callers

nothing calls this directly

Calls 8

matchMethod · 0.80
hasPluginMethod · 0.80
curPositionMethod · 0.80
nextMethod · 0.80
pushMethod · 0.45
parseObjPropValueMethod · 0.45

Tested by

no test coverage detected