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

Method parseMethod

packages/babel-parser/src/plugins/estree.ts:256–336  ·  view source on GitHub ↗
(
      node: Undone<T>,
      isGenerator: boolean,
      isAsync: boolean,
      isConstructor: boolean,
      allowDirectSuper: boolean,
      type: T["type"],
      inClassScope: boolean = false,
    )

Source from the content-addressed store, hash-verified

254
255 // @ts-expect-error plugin may override interfaces
256 parseMethod<
257 T extends N.ClassPrivateMethod | N.ObjectMethod | N.ClassMethod,
258 >(
259 node: Undone<T>,
260 isGenerator: boolean,
261 isAsync: boolean,
262 isConstructor: boolean,
263 allowDirectSuper: boolean,
264 type: T["type"],
265 inClassScope: boolean = false,
266 ):
267 | N.EstreeProperty
268 | N.EstreeMethodDefinition
269 | N.EstreeTSAbstractMethodDefinition {
270 let funcNode = this.startNode<N.MethodLike>();
271 funcNode.kind = node.kind; // provide kind, so super method correctly sets state
272 funcNode = super.parseMethod(
273 // @ts-expect-error estree plugin change node types
274 funcNode,
275 isGenerator,
276 isAsync,
277 isConstructor,
278 allowDirectSuper,
279 type,
280 inClassScope,
281 );
282 // @ts-expect-error delete non-optional properties
283 delete funcNode.kind;
284 const { typeParameters } = node;
285 if (typeParameters) {
286 delete node.typeParameters;
287 funcNode.typeParameters = typeParameters;
288 this.resetStartLocationFromNode(funcNode, typeParameters);
289 }
290 const valueNode = this.castNodeTo(
291 funcNode as N.MethodLike,
292 // @ts-expect-error test if body in funcNode and cast to different node types
293 this.hasPlugin("typescript") && !funcNode.body
294 ? "TSEmptyBodyFunctionExpression"
295 : "FunctionExpression",
296 );
297 (
298 node as unknown as Undone<
299 | N.EstreeProperty
300 | N.EstreeMethodDefinition
301 | N.EstreeTSAbstractMethodDefinition
302 >
303 ).value = valueNode;
304 if (type === "ClassPrivateMethod") {
305 node.computed = false;
306 }
307 if (this.hasPlugin("typescript")) {
308 // @ts-expect-error todo(flow->ts) property not defined for all types in union
309 if (node.abstract) {
310 // @ts-expect-error remove abstract from TSAbstractMethodDefinition
311 delete node.abstract;
312 return this.finishNode(
313 // @ts-expect-error cast methods to estree types

Callers 3

pushClassMethodFunction · 0.45
pushClassPrivateMethodFunction · 0.45
parseObjectMethodFunction · 0.45

Calls 3

castNodeToMethod · 0.95
finishNodeMethod · 0.95
hasPluginMethod · 0.80

Tested by

no test coverage detected