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

Method parseSubscript

packages/babel-parser/src/plugins/flow/index.ts:3342–3396  ·  view source on GitHub ↗
(
      base: N.Expression,
      startLoc: Position,
      noCalls: boolean | undefined | null,
      subscriptState: N.ParseSubscriptState,
    )

Source from the content-addressed store, hash-verified

3340 }
3341
3342 parseSubscript(
3343 base: N.Expression,
3344 startLoc: Position,
3345 noCalls: boolean | undefined | null,
3346 subscriptState: N.ParseSubscriptState,
3347 ): N.Expression {
3348 if (this.match(tt.questionDot) && this.isLookaheadToken_lt()) {
3349 subscriptState.optionalChainMember = true;
3350 if (noCalls) {
3351 subscriptState.stop = true;
3352 return base;
3353 }
3354 this.next();
3355 const node = this.startNodeAt<N.OptionalCallExpression>(startLoc);
3356 node.callee = base;
3357 node.typeArguments =
3358 this.flowParseTypeParameterInstantiationInExpression();
3359 this.expect(tt.parenL);
3360 node.arguments = this.parseCallExpressionArguments();
3361 node.optional = true;
3362 return this.finishCallExpression(node, /* optional */ true);
3363 } else if (
3364 !noCalls &&
3365 this.shouldParseTypes() &&
3366 (this.match(tt.lt) ||
3367 // also handles `new C<<T>`
3368 this.match(tt.bitShiftL))
3369 ) {
3370 const node = this.startNodeAt<
3371 N.OptionalCallExpression | N.CallExpression
3372 >(startLoc);
3373 node.callee = base;
3374
3375 const result = this.tryParse(() => {
3376 node.typeArguments =
3377 this.flowParseTypeParameterInstantiationCallOrNew();
3378 this.expect(tt.parenL);
3379 node.arguments = super.parseCallExpressionArguments();
3380 if (subscriptState.optionalChainMember) {
3381 (node as Undone<N.OptionalCallExpression>).optional = false;
3382 }
3383 return this.finishCallExpression(
3384 node,
3385 subscriptState.optionalChainMember,
3386 );
3387 });
3388
3389 if (result.node) {
3390 if (result.error) this.state = result.failState;
3391 return result.node;
3392 }
3393 }
3394
3395 return super.parseSubscript(base, startLoc, noCalls, subscriptState);
3396 }
3397
3398 parseNewCallee(node: N.NewExpression): void {
3399 super.parseNewCallee(node);

Callers 1

parseSubscriptsFunction · 0.45

Calls 7

isLookaheadToken_ltMethod · 0.95
shouldParseTypesMethod · 0.95
matchMethod · 0.80
nextMethod · 0.80
finishCallExpressionMethod · 0.80

Tested by

no test coverage detected