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

Function parseProgram

packages/babel-parser/src/parser/statement.ts:102–135  ·  view source on GitHub ↗
(
    this: Parser,
    program: Undone<N.Program>,
    end: TokenType,
    sourceType: N.Program["sourceType"],
  )

Source from the content-addressed store, hash-verified

100 }
101
102 parseProgram(
103 this: Parser,
104 program: Undone<N.Program>,
105 end: TokenType,
106 sourceType: N.Program["sourceType"],
107 ): N.Program {
108 program.sourceType = sourceType;
109 program.interpreter = this.parseInterpreterDirective();
110 this.parseBlockBody(program, true, true, end);
111 if (this.inModule) {
112 if (
113 !(this.optionFlags & OptionFlags.AllowUndeclaredExports) &&
114 this.scope.undefinedExports.size > 0
115 ) {
116 for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
117 this.raise(Errors.ModuleExportUndefined, at, { localName });
118 }
119 }
120 this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
121 }
122 let finishedProgram: N.Program;
123 if (end === tt.eof) {
124 // finish at eof for top level program
125 finishedProgram = this.finishNode(program, "Program");
126 } else {
127 // finish immediately before the end token
128 finishedProgram = this.finishNodeAt(
129 program,
130 "Program",
131 createPositionWithColumnOffset(this.state.startLoc, -1),
132 );
133 }
134 return finishedProgram;
135 }
136
137 /**
138 * cast a Statement to a Directive. This method mutates input statement.

Callers

nothing calls this directly

Calls 4

parseBlockBodyMethod · 0.80
finishNodeMethod · 0.80
finishNodeAtMethod · 0.45

Tested by

no test coverage detected