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

Method driveHmr

packages/compiler-cli/test/ngtsc/env.ts:534–587  ·  view source on GitHub ↗
(fileName: string, className: string)

Source from the content-addressed store, hash-verified

532 }
533
534 driveHmr(fileName: string, className: string): string | null {
535 const {rootNames, options} = readNgcCommandLineAndConfiguration(this.commandLineArgs);
536
537 if (isNgpTestMode()) {
538 const tsconfigPath = this.fs.resolve(this.basePath, 'tsconfig.json');
539 const result = performNgpCompilationSync({
540 fs: this.fs,
541 basePath: this.basePath,
542 tsconfigPath,
543 rootNames,
544 options,
545 emit: false,
546 closeAnalyzer: false,
547 });
548 try {
549 const filePath = toPosixPath(this.fs.resolve(this.basePath, fileName));
550 const source = runNgpSync(
551 result.compiler.emitHmrUpdateModule(filePath, className),
552 result.compiler.analyzer,
553 );
554 if (source === null) {
555 return null;
556 }
557 const output = ts.transpileModule(source, {
558 compilerOptions: {
559 ...options,
560 module: ts.ModuleKind.ES2022,
561 target: ts.ScriptTarget.ES2022,
562 } as ts.CompilerOptions,
563 fileName,
564 reportDiagnostics: false,
565 }).outputText;
566 return normalizeNgpOutputFile(output);
567 } finally {
568 result.compiler.analyzer.close();
569 }
570 }
571
572 const host = createCompilerHost({options});
573 const program = createProgram({rootNames, host, options});
574 const sourceFile = program.getTsProgram().getSourceFile(fileName);
575
576 if (sourceFile == null) {
577 throw new Error(`Cannot find file at "${fileName}"`);
578 }
579
580 for (const node of sourceFile.statements) {
581 if (ts.isClassDeclaration(node) && node.name != null && node.name.text === className) {
582 return (program as NgtscProgram).compiler.emitHmrUpdateModule(node);
583 }
584 }
585
586 throw new Error(`Cannot find class with name "${className}" in "${fileName}"`);
587 }
588}
589
590class AugmentedCompilerHost extends NgtscTestCompilerHost {

Callers 1

hmr_spec.tsFile · 0.80

Calls 13

isNgpTestModeFunction · 0.90
toPosixPathFunction · 0.90
runNgpSyncFunction · 0.90
normalizeNgpOutputFileFunction · 0.90
createCompilerHostFunction · 0.85
resolveMethod · 0.65
closeMethod · 0.65
getTsProgramMethod · 0.65
createProgramFunction · 0.50
emitHmrUpdateModuleMethod · 0.45

Tested by

no test coverage detected