(fileName: string, className: string)
| 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 | |
| 590 | class AugmentedCompilerHost extends NgtscTestCompilerHost { |
no test coverage detected