UNPKG

7.96 kBTypeScriptView Raw
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 */
8import ts from 'typescript';
9import { ExtendedTsCompilerHost, NgCompilerOptions } from '../ngtsc/core/api';
10export declare const DEFAULT_ERROR_CODE = 100;
11export declare const UNKNOWN_ERROR_CODE = 500;
12export declare const SOURCE: "angular";
13export declare function isTsDiagnostic(diagnostic: any): diagnostic is ts.Diagnostic;
14export interface CompilerOptions extends NgCompilerOptions, ts.CompilerOptions {
15 genDir?: string;
16 basePath?: string;
17 skipMetadataEmit?: boolean;
18 strictMetadataEmit?: boolean;
19 skipTemplateCodegen?: boolean;
20 flatModulePrivateSymbolPrefix?: string;
21 generateCodeForLibraries?: boolean;
22 annotationsAs?: 'decorators' | 'static fields';
23 trace?: boolean;
24 disableExpressionLowering?: boolean;
25 i18nInFormat?: string;
26 i18nInFile?: string;
27 i18nInMissingTranslations?: 'error' | 'warning' | 'ignore';
28 /**
29 * Whether to replace the `templateUrl` and `styleUrls` property in all
30 * @Component decorators with inlined contents in `template` and `styles`
31 * properties.
32 * When enabled, the .js output of ngc will have no lazy-loaded `templateUrl`
33 * or `styleUrl`s. Note that this requires that resources be available to
34 * load statically at compile-time.
35 */
36 enableResourceInlining?: boolean;
37 /**
38 * Whether NGC should generate re-exports for external symbols which are referenced
39 * in Angular metadata (e.g. @Component, @Inject, @ViewChild). This can be enabled in
40 * order to avoid dynamically generated module dependencies which can break strict
41 * dependency enforcements. This is not enabled by default.
42 * Read more about this here: https://github.com/angular/angular/issues/25644.
43 */
44 createExternalSymbolFactoryReexports?: boolean;
45}
46export interface CompilerHost extends ts.CompilerHost, ExtendedTsCompilerHost {
47 /**
48 * Converts a module name that is used in an `import` to a file path.
49 * I.e. `path/to/containingFile.ts` containing `import {...} from 'module-name'`.
50 */
51 moduleNameToFileName?(moduleName: string, containingFile: string): string | null;
52 /**
53 * Converts a file name into a representation that should be stored in a summary file.
54 * This has to include changing the suffix as well.
55 * E.g.
56 * `some_file.ts` -> `some_file.d.ts`
57 *
58 * @param referringSrcFileName the source file that refers to fileName
59 */
60 toSummaryFileName?(fileName: string, referringSrcFileName: string): string;
61 /**
62 * Converts a fileName that was processed by `toSummaryFileName` back into a real fileName
63 * given the fileName of the library that is referring to it.
64 */
65 fromSummaryFileName?(fileName: string, referringLibFileName: string): string;
66 /**
67 * Produce an AMD module name for the source file. Used in Bazel.
68 *
69 * An AMD module can have an arbitrary name, so that it is require'd by name
70 * rather than by path. See https://requirejs.org/docs/whyamd.html#namedmodules
71 */
72 amdModuleName?(sf: ts.SourceFile): string | undefined;
73}
74export declare enum EmitFlags {
75 DTS = 1,
76 JS = 2,
77 Metadata = 4,
78 I18nBundle = 8,
79 Codegen = 16,
80 Default = 19,
81 All = 31
82}
83export interface CustomTransformers {
84 beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
85 afterTs?: ts.TransformerFactory<ts.SourceFile>[];
86}
87export interface TsEmitArguments {
88 program: ts.Program;
89 host: CompilerHost;
90 options: CompilerOptions;
91 targetSourceFile?: ts.SourceFile;
92 writeFile?: ts.WriteFileCallback;
93 cancellationToken?: ts.CancellationToken;
94 emitOnlyDtsFiles?: boolean;
95 customTransformers?: ts.CustomTransformers;
96}
97export interface TsEmitCallback<T extends ts.EmitResult> {
98 (args: TsEmitArguments): T;
99}
100export interface TsMergeEmitResultsCallback<T extends ts.EmitResult> {
101 (results: T[]): T;
102}
103export interface LazyRoute {
104 route: string;
105 module: {
106 name: string;
107 filePath: string;
108 };
109 referencedModule: {
110 name: string;
111 filePath: string;
112 };
113}
114export interface EmitOptions<CbEmitRes extends ts.EmitResult> {
115 emitFlags?: EmitFlags;
116 forceEmit?: boolean;
117 cancellationToken?: ts.CancellationToken;
118 customTransformers?: CustomTransformers;
119 emitCallback?: TsEmitCallback<CbEmitRes>;
120 mergeEmitResultsCallback?: TsMergeEmitResultsCallback<CbEmitRes>;
121}
122export interface Program {
123 /**
124 * Retrieve the TypeScript program used to produce semantic diagnostics and emit the sources.
125 *
126 * Angular structural information is required to produce the program.
127 */
128 getTsProgram(): ts.Program;
129 /**
130 * Retrieve options diagnostics for the TypeScript options used to create the program. This is
131 * faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to
132 * collect Angular structural information to produce the errors.
133 */
134 getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
135 /**
136 * Retrieve options diagnostics for the Angular options used to create the program.
137 */
138 getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
139 /**
140 * Retrieve the syntax diagnostics from TypeScript. This is faster than calling
141 * `getTsProgram().getSyntacticDiagnostics()` since it does not need to collect Angular structural
142 * information to produce the errors.
143 */
144 getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
145 /**
146 * Retrieve the diagnostics for the structure of an Angular application is correctly formed.
147 * This includes validating Angular annotations and the syntax of referenced and imbedded HTML
148 * and CSS.
149 *
150 * Note it is important to displaying TypeScript semantic diagnostics along with Angular
151 * structural diagnostics as an error in the program structure might cause errors detected in
152 * semantic analysis and a semantic error might cause errors in specifying the program structure.
153 *
154 * Angular structural information is required to produce these diagnostics.
155 */
156 getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
157 /**
158 * Retrieve the semantic diagnostics from TypeScript. This is equivalent to calling
159 * `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness.
160 */
161 getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
162 /**
163 * Retrieve the Angular semantic diagnostics.
164 *
165 * Angular structural information is required to produce these diagnostics.
166 */
167 getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
168 /**
169 * Load Angular structural information asynchronously. If this method is not called then the
170 * Angular structural information, including referenced HTML and CSS files, are loaded
171 * synchronously. If the supplied Angular compiler host returns a promise from `loadResource()`
172 * will produce a diagnostic error message or, `getTsProgram()` or `emit` to throw.
173 */
174 loadNgStructureAsync(): Promise<void>;
175 /**
176 * This method is obsolete and always returns an empty array.
177 */
178 listLazyRoutes(entryRoute?: string): LazyRoute[];
179 /**
180 * Emit the files requested by emitFlags implied by the program.
181 *
182 * Angular structural information is required to emit files.
183 */
184 emit<CbEmitRes extends ts.EmitResult>(opts?: EmitOptions<CbEmitRes> | undefined): ts.EmitResult;
185}