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

Function parseProgram

packages/babel-parser/src/parser/statement.ts:221–254  ·  view source on GitHub ↗
(
    this: Parser,
    program: Undone<N.Program>,
    end: TokenType,
    sourceType: SourceType,
  )

Source from the content-addressed store, hash-verified

219 }
220
221 parseProgram(
222 this: Parser,
223 program: Undone<N.Program>,
224 end: TokenType,
225 sourceType: SourceType,
226 ): N.Program {
227 program.sourceType = sourceType;
228 program.interpreter = this.parseInterpreterDirective();
229 this.parseBlockBody(program, true, true, end);
230 if (this.inModule) {
231 if (
232 !(this.optionFlags & OptionFlags.AllowUndeclaredExports) &&
233 this.scope.undefinedExports.size > 0
234 ) {
235 for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
236 this.raise(Errors.ModuleExportUndefined, at, { localName });
237 }
238 }
239 this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
240 }
241 let finishedProgram: N.Program;
242 if (end === tt.eof) {
243 // finish at eof for top level program
244 finishedProgram = this.finishNode(program, "Program");
245 } else {
246 // finish immediately before the end token
247 finishedProgram = this.finishNodeAt(
248 program,
249 "Program",
250 createPositionWithColumnOffset(this.state.startLoc, -1),
251 );
252 }
253 return finishedProgram;
254 }
255
256 /**
257 * 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