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

Class NapiAnalyzer

packages/compiler-cli/preprocessor/src/analyzer_napi.ts:13–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import type {IAnalyzer} from './hybrid_compiler.js';
12
13export class NapiAnalyzer implements IAnalyzer {
14 private analyzer: nga.Analyzer | nga.TestAnalyzer;
15
16 constructor(analyzer: nga.Analyzer | nga.TestAnalyzer) {
17 this.analyzer = analyzer;
18 }
19
20 /**
21 * Creates an analyzer, resolving whichever engine is available.
22 *
23 * Retained for compatibility; prefer `loadAnalyzer` from `./analyzer_loader.js`,
24 * whose options are richer and whose return type reflects that the result may be
25 * wasm-backed rather than N-API-backed.
26 *
27 * The loader is reached through a dynamic `import()` so that merely importing this
28 * module does not pull engine resolution into module evaluation.
29 */
30 public static async create(
31 tsconfigPath: string,
32 options: import('./analyzer_loader.js').LoadAnalyzerOptions = {},
33 ): Promise<IAnalyzer> {
34 const {loadAnalyzer} = await import('./analyzer_loader.js');
35 return loadAnalyzer(tsconfigPath, options);
36 }
37
38 private async *consumeIterator(iterator: {
39 next(): Promise<nga.CompilationChunk | null | undefined>;
40 }): AsyncGenerator<nga.CompilationChunk, void, unknown> {
41 while (true) {
42 const res = await iterator.next();
43 if (res === null || res === undefined) {
44 break;
45 }
46 yield res;
47 }
48 }
49
50 analyze(): AsyncGenerator<nga.CompilationChunk, void, unknown> {
51 return this.consumeIterator(this.analyzer.analyze());
52 }
53
54 analyzeOptimized(): AsyncGenerator<nga.CompilationChunk, void, unknown> {
55 return this.consumeIterator(this.analyzer.analyzeOptimized());
56 }
57
58 analyzeDelta(): AsyncGenerator<nga.CompilationChunk, void, unknown> {
59 return this.consumeIterator(this.analyzer.analyzeDelta());
60 }
61
62 analyzeOptimizedDelta(): AsyncGenerator<nga.CompilationChunk, void, unknown> {
63 return this.consumeIterator(this.analyzer.analyzeOptimizedDelta());
64 }
65
66 async getMetadataForFile(filePath: string): Promise<nga.AnalysisResult | null> {
67 return this.analyzer.getMetadataForFile(filePath) ?? null;
68 }
69
70 async updateFileContent(updates: {filePath: string; content: string}[]): Promise<string[]> {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected