1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | /// <amd-module name="@angular/compiler-cli/src/ngtsc/core/src/compiler" />
|
---|
9 | import * as ts from 'typescript';
|
---|
10 | import { AbsoluteFsPath } from '../../file_system';
|
---|
11 | import { IncrementalBuildStrategy, IncrementalCompilation, IncrementalState } from '../../incremental';
|
---|
12 | import { IndexedComponent } from '../../indexer';
|
---|
13 | import { ComponentResources, DirectiveMeta, PipeMeta } from '../../metadata';
|
---|
14 | import { ActivePerfRecorder } from '../../perf';
|
---|
15 | import { ProgramDriver } from '../../program_driver';
|
---|
16 | import { DeclarationNode } from '../../reflection';
|
---|
17 | import { OptimizeFor, TemplateTypeChecker } from '../../typecheck/api';
|
---|
18 | import { Xi18nContext } from '../../xi18n';
|
---|
19 | import { LazyRoute, NgCompilerAdapter, NgCompilerOptions } from '../api';
|
---|
20 | /**
|
---|
21 | * Discriminant type for a `CompilationTicket`.
|
---|
22 | */
|
---|
23 | export declare enum CompilationTicketKind {
|
---|
24 | Fresh = 0,
|
---|
25 | IncrementalTypeScript = 1,
|
---|
26 | IncrementalResource = 2
|
---|
27 | }
|
---|
28 | /**
|
---|
29 | * Begin an Angular compilation operation from scratch.
|
---|
30 | */
|
---|
31 | export interface FreshCompilationTicket {
|
---|
32 | kind: CompilationTicketKind.Fresh;
|
---|
33 | options: NgCompilerOptions;
|
---|
34 | incrementalBuildStrategy: IncrementalBuildStrategy;
|
---|
35 | programDriver: ProgramDriver;
|
---|
36 | enableTemplateTypeChecker: boolean;
|
---|
37 | usePoisonedData: boolean;
|
---|
38 | tsProgram: ts.Program;
|
---|
39 | perfRecorder: ActivePerfRecorder;
|
---|
40 | }
|
---|
41 | /**
|
---|
42 | * Begin an Angular compilation operation that incorporates changes to TypeScript code.
|
---|
43 | */
|
---|
44 | export interface IncrementalTypeScriptCompilationTicket {
|
---|
45 | kind: CompilationTicketKind.IncrementalTypeScript;
|
---|
46 | options: NgCompilerOptions;
|
---|
47 | newProgram: ts.Program;
|
---|
48 | incrementalBuildStrategy: IncrementalBuildStrategy;
|
---|
49 | incrementalCompilation: IncrementalCompilation;
|
---|
50 | programDriver: ProgramDriver;
|
---|
51 | enableTemplateTypeChecker: boolean;
|
---|
52 | usePoisonedData: boolean;
|
---|
53 | perfRecorder: ActivePerfRecorder;
|
---|
54 | }
|
---|
55 | export interface IncrementalResourceCompilationTicket {
|
---|
56 | kind: CompilationTicketKind.IncrementalResource;
|
---|
57 | compiler: NgCompiler;
|
---|
58 | modifiedResourceFiles: Set<string>;
|
---|
59 | perfRecorder: ActivePerfRecorder;
|
---|
60 | }
|
---|
61 | /**
|
---|
62 | * A request to begin Angular compilation, either starting from scratch or from a known prior state.
|
---|
63 | *
|
---|
64 | * `CompilationTicket`s are used to initialize (or update) an `NgCompiler` instance, the core of the
|
---|
65 | * Angular compiler. They abstract the starting state of compilation and allow `NgCompiler` to be
|
---|
66 | * managed independently of any incremental compilation lifecycle.
|
---|
67 | */
|
---|
68 | export declare type CompilationTicket = FreshCompilationTicket | IncrementalTypeScriptCompilationTicket | IncrementalResourceCompilationTicket;
|
---|
69 | /**
|
---|
70 | * Create a `CompilationTicket` for a brand new compilation, using no prior state.
|
---|
71 | */
|
---|
72 | export declare function freshCompilationTicket(tsProgram: ts.Program, options: NgCompilerOptions, incrementalBuildStrategy: IncrementalBuildStrategy, programDriver: ProgramDriver, perfRecorder: ActivePerfRecorder | null, enableTemplateTypeChecker: boolean, usePoisonedData: boolean): CompilationTicket;
|
---|
73 | /**
|
---|
74 | * Create a `CompilationTicket` as efficiently as possible, based on a previous `NgCompiler`
|
---|
75 | * instance and a new `ts.Program`.
|
---|
76 | */
|
---|
77 | export declare function incrementalFromCompilerTicket(oldCompiler: NgCompiler, newProgram: ts.Program, incrementalBuildStrategy: IncrementalBuildStrategy, programDriver: ProgramDriver, modifiedResourceFiles: Set<AbsoluteFsPath>, perfRecorder: ActivePerfRecorder | null): CompilationTicket;
|
---|
78 | /**
|
---|
79 | * Create a `CompilationTicket` directly from an old `ts.Program` and associated Angular compilation
|
---|
80 | * state, along with a new `ts.Program`.
|
---|
81 | */
|
---|
82 | export declare function incrementalFromStateTicket(oldProgram: ts.Program, oldState: IncrementalState, newProgram: ts.Program, options: NgCompilerOptions, incrementalBuildStrategy: IncrementalBuildStrategy, programDriver: ProgramDriver, modifiedResourceFiles: Set<AbsoluteFsPath>, perfRecorder: ActivePerfRecorder | null, enableTemplateTypeChecker: boolean, usePoisonedData: boolean): CompilationTicket;
|
---|
83 | export declare function resourceChangeTicket(compiler: NgCompiler, modifiedResourceFiles: Set<string>): IncrementalResourceCompilationTicket;
|
---|
84 | /**
|
---|
85 | * The heart of the Angular Ivy compiler.
|
---|
86 | *
|
---|
87 | * The `NgCompiler` provides an API for performing Angular compilation within a custom TypeScript
|
---|
88 | * compiler. Each instance of `NgCompiler` supports a single compilation, which might be
|
---|
89 | * incremental.
|
---|
90 | *
|
---|
91 | * `NgCompiler` is lazy, and does not perform any of the work of the compilation until one of its
|
---|
92 | * output methods (e.g. `getDiagnostics`) is called.
|
---|
93 | *
|
---|
94 | * See the README.md for more information.
|
---|
95 | */
|
---|
96 | export declare class NgCompiler {
|
---|
97 | private adapter;
|
---|
98 | readonly options: NgCompilerOptions;
|
---|
99 | private inputProgram;
|
---|
100 | readonly programDriver: ProgramDriver;
|
---|
101 | readonly incrementalStrategy: IncrementalBuildStrategy;
|
---|
102 | readonly incrementalCompilation: IncrementalCompilation;
|
---|
103 | readonly enableTemplateTypeChecker: boolean;
|
---|
104 | readonly usePoisonedData: boolean;
|
---|
105 | private livePerfRecorder;
|
---|
106 | /**
|
---|
107 | * Lazily evaluated state of the compilation.
|
---|
108 | *
|
---|
109 | * This is created on demand by calling `ensureAnalyzed`.
|
---|
110 | */
|
---|
111 | private compilation;
|
---|
112 | /**
|
---|
113 | * Any diagnostics related to the construction of the compilation.
|
---|
114 | *
|
---|
115 | * These are diagnostics which arose during setup of the host and/or program.
|
---|
116 | */
|
---|
117 | private constructionDiagnostics;
|
---|
118 | /**
|
---|
119 | * Non-template diagnostics related to the program itself. Does not include template
|
---|
120 | * diagnostics because the template type checker memoizes them itself.
|
---|
121 | *
|
---|
122 | * This is set by (and memoizes) `getNonTemplateDiagnostics`.
|
---|
123 | */
|
---|
124 | private nonTemplateDiagnostics;
|
---|
125 | private closureCompilerEnabled;
|
---|
126 | private currentProgram;
|
---|
127 | private entryPoint;
|
---|
128 | private moduleResolver;
|
---|
129 | private resourceManager;
|
---|
130 | private cycleAnalyzer;
|
---|
131 | readonly ignoreForDiagnostics: Set<ts.SourceFile>;
|
---|
132 | readonly ignoreForEmit: Set<ts.SourceFile>;
|
---|
133 | /**
|
---|
134 | * `NgCompiler` can be reused for multiple compilations (for resource-only changes), and each
|
---|
135 | * new compilation uses a fresh `PerfRecorder`. Thus, classes created with a lifespan of the
|
---|
136 | * `NgCompiler` use a `DelegatingPerfRecorder` so the `PerfRecorder` they write to can be updated
|
---|
137 | * with each fresh compilation.
|
---|
138 | */
|
---|
139 | private delegatingPerfRecorder;
|
---|
140 | /**
|
---|
141 | * Convert a `CompilationTicket` into an `NgCompiler` instance for the requested compilation.
|
---|
142 | *
|
---|
143 | * Depending on the nature of the compilation request, the `NgCompiler` instance may be reused
|
---|
144 | * from a previous compilation and updated with any changes, it may be a new instance which
|
---|
145 | * incrementally reuses state from a previous compilation, or it may represent a fresh
|
---|
146 | * compilation entirely.
|
---|
147 | */
|
---|
148 | static fromTicket(ticket: CompilationTicket, adapter: NgCompilerAdapter): NgCompiler;
|
---|
149 | private constructor();
|
---|
150 | get perfRecorder(): ActivePerfRecorder;
|
---|
151 | /**
|
---|
152 | * Exposes the `IncrementalCompilation` under an old property name that the CLI uses, avoiding a
|
---|
153 | * chicken-and-egg problem with the rename to `incrementalCompilation`.
|
---|
154 | *
|
---|
155 | * TODO(alxhub): remove when the CLI uses the new name.
|
---|
156 | */
|
---|
157 | get incrementalDriver(): IncrementalCompilation;
|
---|
158 | private updateWithChangedResources;
|
---|
159 | /**
|
---|
160 | * Get the resource dependencies of a file.
|
---|
161 | *
|
---|
162 | * If the file is not part of the compilation, an empty array will be returned.
|
---|
163 | */
|
---|
164 | getResourceDependencies(file: ts.SourceFile): string[];
|
---|
165 | /**
|
---|
166 | * Get all Angular-related diagnostics for this compilation.
|
---|
167 | */
|
---|
168 | getDiagnostics(): ts.Diagnostic[];
|
---|
169 | /**
|
---|
170 | * Get all Angular-related diagnostics for this compilation.
|
---|
171 | *
|
---|
172 | * If a `ts.SourceFile` is passed, only diagnostics related to that file are returned.
|
---|
173 | */
|
---|
174 | getDiagnosticsForFile(file: ts.SourceFile, optimizeFor: OptimizeFor): ts.Diagnostic[];
|
---|
175 | /**
|
---|
176 | * Get all `ts.Diagnostic`s currently available that pertain to the given component.
|
---|
177 | */
|
---|
178 | getDiagnosticsForComponent(component: ts.ClassDeclaration): ts.Diagnostic[];
|
---|
179 | /**
|
---|
180 | * Add Angular.io error guide links to diagnostics for this compilation.
|
---|
181 | */
|
---|
182 | private addMessageTextDetails;
|
---|
183 | /**
|
---|
184 | * Get all setup-related diagnostics for this compilation.
|
---|
185 | */
|
---|
186 | getOptionDiagnostics(): ts.Diagnostic[];
|
---|
187 | /**
|
---|
188 | * Get the current `ts.Program` known to this `NgCompiler`.
|
---|
189 | *
|
---|
190 | * Compilation begins with an input `ts.Program`, and during template type-checking operations new
|
---|
191 | * `ts.Program`s may be produced using the `ProgramDriver`. The most recent such `ts.Program` to
|
---|
192 | * be produced is available here.
|
---|
193 | *
|
---|
194 | * This `ts.Program` serves two key purposes:
|
---|
195 | *
|
---|
196 | * * As an incremental starting point for creating the next `ts.Program` based on files that the
|
---|
197 | * user has changed (for clients using the TS compiler program APIs).
|
---|
198 | *
|
---|
199 | * * As the "before" point for an incremental compilation invocation, to determine what's changed
|
---|
200 | * between the old and new programs (for all compilations).
|
---|
201 | */
|
---|
202 | getCurrentProgram(): ts.Program;
|
---|
203 | getTemplateTypeChecker(): TemplateTypeChecker;
|
---|
204 | /**
|
---|
205 | * Retrieves the `ts.Declaration`s for any component(s) which use the given template file.
|
---|
206 | */
|
---|
207 | getComponentsWithTemplateFile(templateFilePath: string): ReadonlySet<DeclarationNode>;
|
---|
208 | /**
|
---|
209 | * Retrieves the `ts.Declaration`s for any component(s) which use the given template file.
|
---|
210 | */
|
---|
211 | getComponentsWithStyleFile(styleFilePath: string): ReadonlySet<DeclarationNode>;
|
---|
212 | /**
|
---|
213 | * Retrieves external resources for the given component.
|
---|
214 | */
|
---|
215 | getComponentResources(classDecl: DeclarationNode): ComponentResources | null;
|
---|
216 | getMeta(classDecl: DeclarationNode): PipeMeta | DirectiveMeta | null;
|
---|
217 | /**
|
---|
218 | * Perform Angular's analysis step (as a precursor to `getDiagnostics` or `prepareEmit`)
|
---|
219 | * asynchronously.
|
---|
220 | *
|
---|
221 | * Normally, this operation happens lazily whenever `getDiagnostics` or `prepareEmit` are called.
|
---|
222 | * However, certain consumers may wish to allow for an asynchronous phase of analysis, where
|
---|
223 | * resources such as `styleUrls` are resolved asynchonously. In these cases `analyzeAsync` must be
|
---|
224 | * called first, and its `Promise` awaited prior to calling any other APIs of `NgCompiler`.
|
---|
225 | */
|
---|
226 | analyzeAsync(): Promise<void>;
|
---|
227 | /**
|
---|
228 | * List lazy routes detected during analysis.
|
---|
229 | *
|
---|
230 | * This can be called for one specific route, or to retrieve all top-level routes.
|
---|
231 | */
|
---|
232 | listLazyRoutes(entryRoute?: string): LazyRoute[];
|
---|
233 | /**
|
---|
234 | * Fetch transformers and other information which is necessary for a consumer to `emit` the
|
---|
235 | * program with Angular-added definitions.
|
---|
236 | */
|
---|
237 | prepareEmit(): {
|
---|
238 | transformers: ts.CustomTransformers;
|
---|
239 | };
|
---|
240 | /**
|
---|
241 | * Run the indexing process and return a `Map` of all indexed components.
|
---|
242 | *
|
---|
243 | * See the `indexing` package for more details.
|
---|
244 | */
|
---|
245 | getIndexedComponents(): Map<DeclarationNode, IndexedComponent>;
|
---|
246 | /**
|
---|
247 | * Collect i18n messages into the `Xi18nContext`.
|
---|
248 | */
|
---|
249 | xi18n(ctx: Xi18nContext): void;
|
---|
250 | private ensureAnalyzed;
|
---|
251 | private analyzeSync;
|
---|
252 | private resolveCompilation;
|
---|
253 | private get fullTemplateTypeCheck();
|
---|
254 | private getTypeCheckingConfig;
|
---|
255 | private getTemplateDiagnostics;
|
---|
256 | private getTemplateDiagnosticsForFile;
|
---|
257 | private getNonTemplateDiagnostics;
|
---|
258 | /**
|
---|
259 | * Calls the `extendedTemplateCheck` phase of the trait compiler
|
---|
260 | * @param sf optional parameter to get diagnostics for a certain file
|
---|
261 | * or all files in the program if `sf` is undefined
|
---|
262 | * @returns generated extended template diagnostics
|
---|
263 | */
|
---|
264 | private getExtendedTemplateDiagnostics;
|
---|
265 | private makeCompilation;
|
---|
266 | }
|
---|
267 | /**
|
---|
268 | * Determine if the given `Program` is @angular/core.
|
---|
269 | */
|
---|
270 | export declare function isAngularCorePackage(program: ts.Program): boolean;
|
---|