MCPcopy Create free account
hub / github.com/angular/angular / emit

Method emit

packages/compiler-cli/src/ngtsc/program.ts:278–387  ·  view source on GitHub ↗
(
    opts?: api.EmitOptions<CbEmitRes> | undefined,
  )

Source from the content-addressed store, hash-verified

276 }
277
278 emit<CbEmitRes extends ts.EmitResult>(
279 opts?: api.EmitOptions<CbEmitRes> | undefined,
280 ): ts.EmitResult {
281 // Check if emission of the i18n messages bundle was requested.
282 if (
283 opts !== undefined &&
284 opts.emitFlags !== undefined &&
285 opts.emitFlags & api.EmitFlags.I18nBundle
286 ) {
287 this.emitXi18n();
288
289 // `api.EmitFlags` is a View Engine compiler concept. We only pay attention to the absence of
290 // the other flags here if i18n emit was requested (since this is usually done in the xi18n
291 // flow, where we don't want to emit JS at all).
292 if (!(opts.emitFlags & api.EmitFlags.JS)) {
293 return {
294 diagnostics: [],
295 emitSkipped: true,
296 emittedFiles: [],
297 };
298 }
299 }
300
301 const forceEmit = opts?.forceEmit ?? false;
302
303 this.compiler.perfRecorder.memory(PerfCheckpoint.PreEmit);
304
305 const res = this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptEmit, () => {
306 const {transformers} = this.compiler.prepareEmit();
307 const ignoreFiles = this.compiler.ignoreForEmit;
308 const emitCallback = (opts?.emitCallback ??
309 defaultEmitCallback) as api.TsEmitCallback<CbEmitRes>;
310
311 const writeFile: ts.WriteFileCallback = (
312 fileName: string,
313 data: string,
314 writeByteOrderMark: boolean,
315 onError: ((message: string) => void) | undefined,
316 sourceFiles: ReadonlyArray<ts.SourceFile> | undefined,
317 ) => {
318 if (sourceFiles !== undefined) {
319 // Record successful writes for any `ts.SourceFile` (that's not a declaration file)
320 // that's an input to this write.
321 for (const writtenSf of sourceFiles) {
322 if (writtenSf.isDeclarationFile) {
323 continue;
324 }
325
326 this.compiler.incrementalCompilation.recordSuccessfulEmit(writtenSf);
327 }
328 }
329 this.host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
330 };
331
332 const customTransforms = opts && opts.customTransformers;
333 const beforeTransforms = transformers.before || [];
334 const afterDeclarationsTransforms = transformers.afterDeclarations;
335

Callers

nothing calls this directly

Calls 12

emitXi18nMethod · 0.95
getFileSystemFunction · 0.90
prepareEmitMethod · 0.80
safeToSkipEmitMethod · 0.80
memoryMethod · 0.65
inPhaseMethod · 0.65
hasMethod · 0.65
eventCountMethod · 0.65
writeFileMethod · 0.65
resolveMethod · 0.65
pushMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected