2017-06-09 21:50:57 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2017-06-09 21:50:57 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2021-09-25 13:10:26 +00:00
|
|
|
import ts from 'typescript';
|
2017-06-09 21:50:57 +00:00
|
|
|
|
2020-01-18 00:00:07 +00:00
|
|
|
import {ExtendedTsCompilerHost, NgCompilerOptions} from '../ngtsc/core/api';
|
|
|
|
|
|
2017-08-18 21:03:59 +00:00
|
|
|
export const DEFAULT_ERROR_CODE = 100;
|
|
|
|
|
export const UNKNOWN_ERROR_CODE = 500;
|
|
|
|
|
export const SOURCE = 'angular' as 'angular';
|
|
|
|
|
|
2017-09-11 22:18:19 +00:00
|
|
|
export function isTsDiagnostic(diagnostic: any): diagnostic is ts.Diagnostic {
|
|
|
|
|
return diagnostic != null && diagnostic.source !== 'angular';
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 00:00:07 +00:00
|
|
|
export interface CompilerOptions extends NgCompilerOptions, ts.CompilerOptions {
|
2017-11-20 18:21:17 +00:00
|
|
|
// NOTE: These comments and aio/content/guides/aot-compiler.md should be kept in sync.
|
|
|
|
|
|
2017-09-19 18:43:34 +00:00
|
|
|
// Write statistics about compilation (e.g. total time, ...)
|
|
|
|
|
// Note: this is the --diagnostics command line option from TS (which is @internal
|
|
|
|
|
// on ts.CompilerOptions interface).
|
|
|
|
|
diagnostics?: boolean;
|
|
|
|
|
|
2017-06-09 21:50:57 +00:00
|
|
|
// Absolute path to a directory where generated file structure is written.
|
|
|
|
|
// If unspecified, generated files will be written alongside sources.
|
2017-08-02 18:20:07 +00:00
|
|
|
// @deprecated - no effect
|
2017-06-09 21:50:57 +00:00
|
|
|
genDir?: string;
|
|
|
|
|
|
|
|
|
|
// Path to the directory containing the tsconfig.json file.
|
|
|
|
|
basePath?: string;
|
|
|
|
|
|
|
|
|
|
// Don't produce .metadata.json files (they don't work for bundled emit with --out)
|
|
|
|
|
skipMetadataEmit?: boolean;
|
|
|
|
|
|
|
|
|
|
// Produce an error if the metadata written for a class would produce an error if used.
|
|
|
|
|
strictMetadataEmit?: boolean;
|
|
|
|
|
|
2018-01-05 16:10:35 +00:00
|
|
|
// Don't produce .ngfactory.js or .ngstyle.js files
|
2017-06-09 21:50:57 +00:00
|
|
|
skipTemplateCodegen?: boolean;
|
|
|
|
|
|
2018-03-26 21:34:44 +00:00
|
|
|
// A prefix to insert in generated private symbols, e.g. for "my_prefix_" we
|
|
|
|
|
// would generate private symbols named like `ɵmy_prefix_a`.
|
|
|
|
|
flatModulePrivateSymbolPrefix?: string;
|
|
|
|
|
|
2017-06-09 21:50:57 +00:00
|
|
|
// Whether to generate code for library code.
|
|
|
|
|
// Default is true.
|
|
|
|
|
generateCodeForLibraries?: boolean;
|
|
|
|
|
|
|
|
|
|
// Modify how angular annotations are emitted to improve tree-shaking.
|
|
|
|
|
// Default is static fields.
|
|
|
|
|
// decorators: Leave the Decorators in-place. This makes compilation faster.
|
|
|
|
|
// TypeScript will emit calls to the __decorate helper.
|
|
|
|
|
// `--emitDecoratorMetadata` can be used for runtime reflection.
|
|
|
|
|
// However, the resulting code will not properly tree-shake.
|
|
|
|
|
// static fields: Replace decorators with a static field in the class.
|
|
|
|
|
// Allows advanced tree-shakers like Closure Compiler to remove
|
|
|
|
|
// unused classes.
|
|
|
|
|
annotationsAs?: 'decorators'|'static fields';
|
|
|
|
|
|
|
|
|
|
// Print extra information while running the compiler
|
|
|
|
|
trace?: boolean;
|
|
|
|
|
|
2017-07-13 21:25:17 +00:00
|
|
|
// Whether to enable lowering expressions lambdas and expressions in a reference value
|
|
|
|
|
// position.
|
|
|
|
|
disableExpressionLowering?: boolean;
|
2017-08-02 18:20:07 +00:00
|
|
|
|
|
|
|
|
// Import format if different from `i18nFormat`
|
|
|
|
|
i18nInFormat?: string;
|
|
|
|
|
// Path to the translation file
|
|
|
|
|
i18nInFile?: string;
|
|
|
|
|
// How to handle missing messages
|
|
|
|
|
i18nInMissingTranslations?: 'error'|'warning'|'ignore';
|
2017-09-29 21:55:44 +00:00
|
|
|
|
2018-03-06 22:53:01 +00:00
|
|
|
/**
|
|
|
|
|
* Whether to replace the `templateUrl` and `styleUrls` property in all
|
|
|
|
|
* @Component decorators with inlined contents in `template` and `styles`
|
|
|
|
|
* properties.
|
|
|
|
|
* When enabled, the .js output of ngc will have no lazy-loaded `templateUrl`
|
|
|
|
|
* or `styleUrl`s. Note that this requires that resources be available to
|
|
|
|
|
* load statically at compile-time.
|
|
|
|
|
*/
|
|
|
|
|
enableResourceInlining?: boolean;
|
|
|
|
|
|
2017-10-24 19:52:14 +00:00
|
|
|
/** @internal */
|
|
|
|
|
collectAllErrors?: boolean;
|
2019-02-12 22:29:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether NGC should generate re-exports for external symbols which are referenced
|
|
|
|
|
* in Angular metadata (e.g. @Component, @Inject, @ViewChild). This can be enabled in
|
|
|
|
|
* order to avoid dynamically generated module dependencies which can break strict
|
|
|
|
|
* dependency enforcements. This is not enabled by default.
|
|
|
|
|
* Read more about this here: https://github.com/angular/angular/issues/25644.
|
|
|
|
|
*/
|
|
|
|
|
createExternalSymbolFactoryReexports?: boolean;
|
2017-06-09 21:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-18 00:00:07 +00:00
|
|
|
export interface CompilerHost extends ts.CompilerHost, ExtendedTsCompilerHost {
|
2017-06-09 21:50:57 +00:00
|
|
|
/**
|
|
|
|
|
* Converts a module name that is used in an `import` to a file path.
|
|
|
|
|
* I.e. `path/to/containingFile.ts` containing `import {...} from 'module-name'`.
|
|
|
|
|
*/
|
2017-09-12 16:40:28 +00:00
|
|
|
moduleNameToFileName?(moduleName: string, containingFile: string): string|null;
|
2017-08-15 21:41:48 +00:00
|
|
|
/**
|
|
|
|
|
* Converts a file name into a representation that should be stored in a summary file.
|
|
|
|
|
* This has to include changing the suffix as well.
|
|
|
|
|
* E.g.
|
|
|
|
|
* `some_file.ts` -> `some_file.d.ts`
|
|
|
|
|
*
|
2022-07-05 09:18:49 +00:00
|
|
|
* @param referringSrcFileName the source file that refers to fileName
|
2017-08-15 21:41:48 +00:00
|
|
|
*/
|
2017-09-12 16:40:28 +00:00
|
|
|
toSummaryFileName?(fileName: string, referringSrcFileName: string): string;
|
2017-08-15 21:41:48 +00:00
|
|
|
/**
|
|
|
|
|
* Converts a fileName that was processed by `toSummaryFileName` back into a real fileName
|
2022-07-05 09:18:49 +00:00
|
|
|
* given the fileName of the library that is referring to it.
|
2017-08-15 21:41:48 +00:00
|
|
|
*/
|
2017-09-12 16:40:28 +00:00
|
|
|
fromSummaryFileName?(fileName: string, referringLibFileName: string): string;
|
2017-11-14 19:29:16 +00:00
|
|
|
/**
|
|
|
|
|
* Produce an AMD module name for the source file. Used in Bazel.
|
|
|
|
|
*
|
|
|
|
|
* An AMD module can have an arbitrary name, so that it is require'd by name
|
2020-11-16 21:37:09 +00:00
|
|
|
* rather than by path. See https://requirejs.org/docs/whyamd.html#namedmodules
|
2017-11-14 19:29:16 +00:00
|
|
|
*/
|
|
|
|
|
amdModuleName?(sf: ts.SourceFile): string|undefined;
|
2017-06-09 21:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum EmitFlags {
|
|
|
|
|
DTS = 1 << 0,
|
|
|
|
|
JS = 1 << 1,
|
|
|
|
|
Metadata = 1 << 2,
|
|
|
|
|
I18nBundle = 1 << 3,
|
2017-09-19 18:41:47 +00:00
|
|
|
Codegen = 1 << 4,
|
2017-06-09 21:50:57 +00:00
|
|
|
|
2017-09-19 18:41:47 +00:00
|
|
|
Default = DTS | JS | Codegen,
|
|
|
|
|
All = DTS | JS | Metadata | I18nBundle | Codegen,
|
2017-06-09 21:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-16 22:35:19 +00:00
|
|
|
export interface CustomTransformers {
|
|
|
|
|
beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
|
|
|
|
|
afterTs?: ts.TransformerFactory<ts.SourceFile>[];
|
2017-08-02 18:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-12 23:09:49 +00:00
|
|
|
export interface TsEmitArguments {
|
2017-08-16 22:35:19 +00:00
|
|
|
program: ts.Program;
|
|
|
|
|
host: CompilerHost;
|
|
|
|
|
options: CompilerOptions;
|
2017-10-12 23:09:49 +00:00
|
|
|
targetSourceFile?: ts.SourceFile;
|
2017-08-16 22:35:19 +00:00
|
|
|
writeFile?: ts.WriteFileCallback;
|
|
|
|
|
cancellationToken?: ts.CancellationToken;
|
|
|
|
|
emitOnlyDtsFiles?: boolean;
|
|
|
|
|
customTransformers?: ts.CustomTransformers;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 13:03:00 +00:00
|
|
|
export interface TsEmitCallback<T extends ts.EmitResult> {
|
|
|
|
|
(args: TsEmitArguments): T;
|
2020-04-07 19:43:43 +00:00
|
|
|
}
|
2022-10-27 13:03:00 +00:00
|
|
|
export interface TsMergeEmitResultsCallback<T extends ts.EmitResult> {
|
|
|
|
|
(results: T[]): T;
|
2020-04-07 19:43:43 +00:00
|
|
|
}
|
2017-08-16 22:35:19 +00:00
|
|
|
|
2017-10-20 16:46:41 +00:00
|
|
|
export interface LazyRoute {
|
|
|
|
|
route: string;
|
|
|
|
|
module: {name: string, filePath: string};
|
|
|
|
|
referencedModule: {name: string, filePath: string};
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-27 13:03:00 +00:00
|
|
|
export interface EmitOptions<CbEmitRes extends ts.EmitResult> {
|
|
|
|
|
emitFlags?: EmitFlags;
|
|
|
|
|
forceEmit?: boolean;
|
|
|
|
|
cancellationToken?: ts.CancellationToken;
|
|
|
|
|
customTransformers?: CustomTransformers;
|
|
|
|
|
emitCallback?: TsEmitCallback<CbEmitRes>;
|
|
|
|
|
mergeEmitResultsCallback?: TsMergeEmitResultsCallback<CbEmitRes>;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 21:50:57 +00:00
|
|
|
export interface Program {
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the TypeScript program used to produce semantic diagnostics and emit the sources.
|
|
|
|
|
*
|
|
|
|
|
* Angular structural information is required to produce the program.
|
|
|
|
|
*/
|
|
|
|
|
getTsProgram(): ts.Program;
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-02 18:20:07 +00:00
|
|
|
* Retrieve options diagnostics for the TypeScript options used to create the program. This is
|
2017-06-09 21:50:57 +00:00
|
|
|
* faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to
|
|
|
|
|
* collect Angular structural information to produce the errors.
|
|
|
|
|
*/
|
2017-12-22 17:36:47 +00:00
|
|
|
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 21:50:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve options diagnostics for the Angular options used to create the program.
|
|
|
|
|
*/
|
2021-11-22 22:35:55 +00:00
|
|
|
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 21:50:57 +00:00
|
|
|
|
|
|
|
|
/**
|
2017-08-02 18:20:07 +00:00
|
|
|
* Retrieve the syntax diagnostics from TypeScript. This is faster than calling
|
2017-06-09 21:50:57 +00:00
|
|
|
* `getTsProgram().getSyntacticDiagnostics()` since it does not need to collect Angular structural
|
|
|
|
|
* information to produce the errors.
|
|
|
|
|
*/
|
|
|
|
|
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
2017-12-22 17:36:47 +00:00
|
|
|
ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 21:50:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the diagnostics for the structure of an Angular application is correctly formed.
|
|
|
|
|
* This includes validating Angular annotations and the syntax of referenced and imbedded HTML
|
|
|
|
|
* and CSS.
|
|
|
|
|
*
|
|
|
|
|
* Note it is important to displaying TypeScript semantic diagnostics along with Angular
|
2018-05-14 14:16:42 +00:00
|
|
|
* structural diagnostics as an error in the program structure might cause errors detected in
|
2017-06-09 21:50:57 +00:00
|
|
|
* semantic analysis and a semantic error might cause errors in specifying the program structure.
|
|
|
|
|
*
|
|
|
|
|
* Angular structural information is required to produce these diagnostics.
|
|
|
|
|
*/
|
2021-11-22 22:35:55 +00:00
|
|
|
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken):
|
|
|
|
|
ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 21:50:57 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-03-10 17:14:58 +00:00
|
|
|
* Retrieve the semantic diagnostics from TypeScript. This is equivalent to calling
|
2017-06-09 21:50:57 +00:00
|
|
|
* `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness.
|
|
|
|
|
*/
|
|
|
|
|
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
2017-12-22 17:36:47 +00:00
|
|
|
ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 21:50:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the Angular semantic diagnostics.
|
|
|
|
|
*
|
|
|
|
|
* Angular structural information is required to produce these diagnostics.
|
|
|
|
|
*/
|
2017-10-12 23:09:49 +00:00
|
|
|
getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken):
|
2021-11-22 22:35:55 +00:00
|
|
|
ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 21:50:57 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load Angular structural information asynchronously. If this method is not called then the
|
|
|
|
|
* Angular structural information, including referenced HTML and CSS files, are loaded
|
|
|
|
|
* synchronously. If the supplied Angular compiler host returns a promise from `loadResource()`
|
|
|
|
|
* will produce a diagnostic error message or, `getTsProgram()` or `emit` to throw.
|
|
|
|
|
*/
|
|
|
|
|
loadNgStructureAsync(): Promise<void>;
|
|
|
|
|
|
2017-10-20 16:46:41 +00:00
|
|
|
/**
|
2021-09-25 20:59:24 +00:00
|
|
|
* This method is obsolete and always returns an empty array.
|
2017-10-20 16:46:41 +00:00
|
|
|
*/
|
|
|
|
|
listLazyRoutes(entryRoute?: string): LazyRoute[];
|
|
|
|
|
|
2017-06-09 21:50:57 +00:00
|
|
|
/**
|
|
|
|
|
* Emit the files requested by emitFlags implied by the program.
|
|
|
|
|
*
|
|
|
|
|
* Angular structural information is required to emit files.
|
|
|
|
|
*/
|
2022-10-27 13:03:00 +00:00
|
|
|
emit<CbEmitRes extends ts.EmitResult>(opts?: EmitOptions<CbEmitRes>|undefined): ts.EmitResult;
|
2017-09-19 18:43:34 +00:00
|
|
|
|
2017-10-03 16:53:58 +00:00
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
getEmittedSourceFiles(): Map<string, ts.SourceFile>;
|
2017-06-09 21:50:57 +00:00
|
|
|
}
|