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

Function parseStatementContent

packages/babel-parser/src/parser/statement.ts:406–611  ·  view source on GitHub ↗
(
    this: Parser,
    flags: ParseStatementFlag,
    decorators?: N.Decorator[] | null,
  )

Source from the content-addressed store, hash-verified

404 }
405
406 parseStatementContent(
407 this: Parser,
408 flags: ParseStatementFlag,
409 decorators?: N.Decorator[] | null,
410 ): N.Statement {
411 const startType = this.state.type;
412 const node = this.startNode();
413 const allowDeclaration = !!(flags & ParseStatementFlag.AllowDeclaration);
414 const allowFunctionDeclaration = !!(
415 flags & ParseStatementFlag.AllowFunctionDeclaration
416 );
417 const topLevel = flags & ParseStatementFlag.AllowImportExport;
418
419 // Most types of statements are recognized by the keyword they
420 // start with. Many are trivial to parse, some require a bit of
421 // complexity.
422
423 switch (startType) {
424 case tt._break:
425 return this.parseBreakContinueStatement(node, /* isBreak */ true);
426 case tt._continue:
427 return this.parseBreakContinueStatement(node, /* isBreak */ false);
428 case tt._debugger:
429 return this.parseDebuggerStatement(node);
430 case tt._do:
431 return this.parseDoWhileStatement(node);
432 case tt._for:
433 return this.parseForStatement(node);
434 case tt._function:
435 if (this.lookaheadCharCode() === charCodes.dot) break;
436 if (!allowFunctionDeclaration) {
437 this.raise(
438 this.state.strict
439 ? Errors.StrictFunction
440 : this.options.annexB
441 ? Errors.SloppyFunctionAnnexB
442 : Errors.SloppyFunction,
443 this.state.startLoc,
444 );
445 }
446 return this.parseFunctionStatement(node, false, flags);
447 case tt._class:
448 if (!allowDeclaration) this.unexpected();
449 return this.parseClass(
450 this.maybeTakeDecorators(
451 decorators,
452 node as Undone<N.ClassDeclaration>,
453 ),
454 true,
455 );
456 case tt._struct:
457 if (!this.state.containsEsc && this.nextTokenIsIdentifierOnSameLine()) {
458 this.expectPlugin("structs");
459 if (!allowDeclaration) this.unexpected();
460 return this.parseStructDeclaration(node, false);
461 }
462 break;
463 case tt._if:

Callers

nothing calls this directly

Calls 11

tokenIsIdentifierFunction · 0.90
nextMethod · 0.80
parseVarStatementMethod · 0.80
parseBlockMethod · 0.80
parseIdentifierMethod · 0.80
parseClassMethod · 0.45
parseImportMethod · 0.45
parseExportMethod · 0.45

Tested by

no test coverage detected