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

Function parseProgram

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

Source from the content-addressed store, hash-verified

112 }
113
114 parseProgram(
115 this: Parser,
116 program: Undone<N.Program>,
117 end: TokenType,
118 sourceType: N.Program["sourceType"],
119 ): N.Program {
120 program.sourceType = sourceType;
121 program.interpreter = this.parseInterpreterDirective();
122 this.parseBlockBody(program, true, true, end);
123 if (this.inModule) {
124 if (
125 !(this.optionFlags & OptionFlags.AllowUndeclaredExports) &&
126 this.scope.undefinedExports.size > 0
127 ) {
128 for (const [localName, at] of Array.from(this.scope.undefinedExports)) {
129 this.raise(Errors.ModuleExportUndefined, at, { localName });
130 }
131 }
132 this.addExtra(program, "topLevelAwait", this.state.hasTopLevelAwait);
133 }
134 let finishedProgram: N.Program;
135 if (end === tt.eof) {
136 // finish at eof for top level program
137 finishedProgram = this.finishNode(program, "Program");
138 } else {
139 // finish immediately before the end token
140 finishedProgram = this.finishNodeAt(
141 program,
142 "Program",
143 createPositionWithColumnOffset(this.state.startLoc, -1),
144 );
145 }
146 return finishedProgram;
147 }
148
149 /**
150 * 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