2017-06-09 14:50:57 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2017-11-14 17:49:47 -08:00
|
|
|
import {GeneratedFile, ParseSourceSpan, Position} from '@angular/compiler';
|
2017-06-09 14:50:57 -07:00
|
|
|
import * as ts from 'typescript';
|
|
|
|
|
2017-08-18 14:03:59 -07:00
|
|
|
export const DEFAULT_ERROR_CODE = 100;
|
|
|
|
export const UNKNOWN_ERROR_CODE = 500;
|
|
|
|
export const SOURCE = 'angular' as 'angular';
|
|
|
|
|
2017-11-14 17:49:47 -08:00
|
|
|
export interface DiagnosticMessageChain {
|
|
|
|
messageText: string;
|
|
|
|
position?: Position;
|
|
|
|
next?: DiagnosticMessageChain;
|
|
|
|
}
|
|
|
|
|
2017-06-09 14:50:57 -07:00
|
|
|
export interface Diagnostic {
|
2017-08-18 14:03:59 -07:00
|
|
|
messageText: string;
|
2017-06-09 14:50:57 -07:00
|
|
|
span?: ParseSourceSpan;
|
2017-11-14 17:49:47 -08:00
|
|
|
position?: Position;
|
|
|
|
chain?: DiagnosticMessageChain;
|
2017-08-09 13:45:45 -07:00
|
|
|
category: ts.DiagnosticCategory;
|
2017-08-18 14:03:59 -07:00
|
|
|
code: number;
|
|
|
|
source: 'angular';
|
2017-06-09 14:50:57 -07:00
|
|
|
}
|
|
|
|
|
2017-09-11 15:18:19 -07:00
|
|
|
export function isTsDiagnostic(diagnostic: any): diagnostic is ts.Diagnostic {
|
|
|
|
return diagnostic != null && diagnostic.source !== 'angular';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isNgDiagnostic(diagnostic: any): diagnostic is Diagnostic {
|
|
|
|
return diagnostic != null && diagnostic.source === 'angular';
|
|
|
|
}
|
|
|
|
|
2017-06-09 14:50:57 -07:00
|
|
|
export interface CompilerOptions extends ts.CompilerOptions {
|
2017-11-20 10:21:17 -08:00
|
|
|
// NOTE: These comments and aio/content/guides/aot-compiler.md should be kept in sync.
|
|
|
|
|
2017-09-19 11:43:34 -07: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 14:50:57 -07:00
|
|
|
// Absolute path to a directory where generated file structure is written.
|
|
|
|
// If unspecified, generated files will be written alongside sources.
|
2017-08-02 11:20:07 -07:00
|
|
|
// @deprecated - no effect
|
2017-06-09 14:50:57 -07: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 08:10:35 -08:00
|
|
|
// Don't produce .ngfactory.js or .ngstyle.js files
|
2017-06-09 14:50:57 -07:00
|
|
|
skipTemplateCodegen?: boolean;
|
|
|
|
|
2017-09-26 13:40:47 -07:00
|
|
|
// Always report errors when the type of a parameter supplied whose injection type cannot
|
|
|
|
// be determined. When this value option is not provided or is `false`, constructor
|
|
|
|
// parameters of classes marked with `@Injectable` whose type cannot be resolved will
|
|
|
|
// produce a warning. With this option `true`, they produce an error. When this option is
|
|
|
|
// not provided is treated as if it were `false`. In Angular 6.0, if this option is not
|
|
|
|
// provided, it will be treated as `true`.
|
|
|
|
strictInjectionParameters?: boolean;
|
|
|
|
|
2017-06-09 14:50:57 -07:00
|
|
|
// Whether to generate a flat module index of the given name and the corresponding
|
|
|
|
// flat module metadata. This option is intended to be used when creating flat
|
|
|
|
// modules similar to how `@angular/core` and `@angular/common` are packaged.
|
2018-03-10 17:14:58 +00:00
|
|
|
// When this option is used the `package.json` for the library should referred to the
|
2017-06-09 14:50:57 -07:00
|
|
|
// generated flat module index instead of the library index file. When using this
|
|
|
|
// option only one .metadata.json file is produced that contains all the metadata
|
|
|
|
// necessary for symbols exported from the library index.
|
|
|
|
// In the generated .ngfactory.ts files flat module index is used to import symbols
|
|
|
|
// includes both the public API from the library index as well as shrowded internal
|
|
|
|
// symbols.
|
|
|
|
// By default the .ts file supplied in the `files` files field is assumed to be
|
|
|
|
// library index. If more than one is specified, uses `libraryIndex` to select the
|
|
|
|
// file to use. If more than on .ts file is supplied and no `libraryIndex` is supplied
|
|
|
|
// an error is produced.
|
|
|
|
// A flat module index .d.ts and .js will be created with the given `flatModuleOutFile`
|
|
|
|
// name in the same location as the library index .d.ts file is emitted.
|
|
|
|
// For example, if a library uses `public_api.ts` file as the library index of the
|
|
|
|
// module the `tsconfig.json` `files` field would be `["public_api.ts"]`. The
|
|
|
|
// `flatModuleOutFile` options could then be set to, for example `"index.js"`, which
|
|
|
|
// produces `index.d.ts` and `index.metadata.json` files. The library's
|
|
|
|
// `package.json`'s `module` field would be `"index.js"` and the `typings` field would
|
|
|
|
// be `"index.d.ts"`.
|
|
|
|
flatModuleOutFile?: string;
|
|
|
|
|
|
|
|
// Preferred module id to use for importing flat module. References generated by `ngc`
|
|
|
|
// will use this module name when importing symbols from the flat module. This is only
|
|
|
|
// meaningful when `flatModuleOutFile` is also supplied. It is otherwise ignored.
|
|
|
|
flatModuleId?: string;
|
|
|
|
|
2018-03-26 14:34:44 -07: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 14:50:57 -07:00
|
|
|
// Whether to generate code for library code.
|
|
|
|
// If true, produce .ngfactory.ts and .ngstyle.ts files for .d.ts inputs.
|
|
|
|
// Default is true.
|
|
|
|
generateCodeForLibraries?: boolean;
|
|
|
|
|
2017-09-11 15:18:19 -07:00
|
|
|
// Whether to enable all type checks for templates.
|
|
|
|
// This will be true be default in Angular 6.
|
|
|
|
fullTemplateTypeCheck?: boolean;
|
|
|
|
|
feat(ivy): use fileNameToModuleName to emit imports when it's available (#28523)
The ultimate goal of this commit is to make use of fileNameToModuleName to
get the module specifier to use when generating an import, when that API is
available in the CompilerHost that ngtsc is created with.
As part of getting there, the way in which ngtsc tracks references and
generates import module specifiers is refactored considerably. References
are tracked with the Reference class, and previously ngtsc had several
different kinds of Reference. An AbsoluteReference represented a declaration
which needed to be imported via an absolute module specifier tracked in the
AbsoluteReference, and a RelativeReference represented a declaration from
the local program, imported via relative path or referred to directly by
identifier if possible. Thus, how to refer to a particular declaration was
encoded into the Reference type _at the time of creation of the Reference_.
This commit refactors that logic and reduces Reference to a single class
with no subclasses. A Reference represents a node being referenced, plus
context about how the node was located. This context includes a
"bestGuessOwningModule", the compiler's best guess at which absolute
module specifier has defined this reference. For example, if the compiler
arrives at the declaration of CommonModule via an import to @angular/common,
then any references obtained from CommonModule (e.g. NgIf) will also be
considered to be owned by @angular/common.
A ReferenceEmitter class and accompanying ReferenceEmitStrategy interface
are introduced. To produce an Expression referring to a given Reference'd
node, the ReferenceEmitter consults a sequence of ReferenceEmitStrategy
implementations.
Several different strategies are defined:
- LocalIdentifierStrategy: use local ts.Identifiers if available.
- AbsoluteModuleStrategy: if the Reference has a bestGuessOwningModule,
import the node via an absolute import from that module specifier.
- LogicalProjectStrategy: if the Reference is in the logical project
(is under the project rootDirs), import the node via a relative import.
- FileToModuleStrategy: use a FileToModuleHost to generate the module
specifier by which to import the node.
Depending on the availability of fileNameToModuleName in the CompilerHost,
then, a different collection of these strategies is used for compilation.
PR Close #28523
2019-02-01 17:24:21 -08:00
|
|
|
// Whether to use the CompilerHost's fileNameToModuleName utility (if available) to generate
|
|
|
|
// import module specifiers. This is false by default, and exists to support running ngtsc
|
|
|
|
// within Google. This option is internal and is used by the ng_module.bzl rule to switch
|
|
|
|
// behavior between Bazel and Blaze.
|
|
|
|
_useHostForImportGeneration?: boolean;
|
|
|
|
|
2017-06-09 14:50:57 -07:00
|
|
|
// Insert JSDoc type annotations needed by Closure Compiler
|
|
|
|
annotateForClosureCompiler?: 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 14:25:17 -07:00
|
|
|
// Whether to enable lowering expressions lambdas and expressions in a reference value
|
|
|
|
// position.
|
|
|
|
disableExpressionLowering?: boolean;
|
2017-08-02 11:20:07 -07:00
|
|
|
|
2017-12-02 12:52:11 +01:00
|
|
|
// Disable TypeScript Version Check.
|
|
|
|
disableTypeScriptVersionCheck?: boolean;
|
|
|
|
|
2017-08-02 11:20:07 -07:00
|
|
|
// Locale of the application
|
|
|
|
i18nOutLocale?: string;
|
|
|
|
// Export format (xlf, xlf2 or xmb)
|
|
|
|
i18nOutFormat?: string;
|
|
|
|
// Path to the extracted message file
|
|
|
|
i18nOutFile?: string;
|
|
|
|
|
|
|
|
// Import format if different from `i18nFormat`
|
|
|
|
i18nInFormat?: string;
|
|
|
|
// Locale of the imported translations
|
|
|
|
i18nInLocale?: string;
|
|
|
|
// Path to the translation file
|
|
|
|
i18nInFile?: string;
|
|
|
|
// How to handle missing messages
|
|
|
|
i18nInMissingTranslations?: 'error'|'warning'|'ignore';
|
2018-11-16 09:57:23 -08:00
|
|
|
// Whether translation variable name should contain external message id
|
|
|
|
// (used by Closure Compiler's output of `goog.getMsg` for transition period)
|
|
|
|
i18nUseExternalIds?: boolean;
|
2017-07-28 15:58:28 +02:00
|
|
|
|
2019-10-01 14:58:49 +01:00
|
|
|
/**
|
|
|
|
* Render `$localize` message ids with the specified legacy format (xlf, xlf2 or xmb).
|
|
|
|
*
|
|
|
|
* Use this option when use are using the `$localize` based localization messages but
|
|
|
|
* have not migrated the translation files to use the new `$localize` message id format.
|
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
* `i18nLegacyMessageIdFormat` should only be used while migrating from legacy message id
|
|
|
|
* formatted translation files and will be removed at the same time as ViewEngine support is
|
|
|
|
* removed.
|
|
|
|
*/
|
|
|
|
i18nLegacyMessageIdFormat?: string;
|
|
|
|
|
2018-02-06 00:37:05 +01:00
|
|
|
// Whether to remove blank text nodes from compiled templates. It is `false` by default starting
|
|
|
|
// from Angular 6.
|
2017-07-28 15:58:28 +02:00
|
|
|
preserveWhitespaces?: boolean;
|
2017-09-21 18:05:07 -07:00
|
|
|
|
|
|
|
/** generate all possible generated files */
|
|
|
|
allowEmptyCodegenFiles?: boolean;
|
2017-09-29 14:55:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether to generate .ngsummary.ts files that allow to use AOTed artifacts
|
|
|
|
* in JIT mode. This is off by default.
|
|
|
|
*/
|
|
|
|
enableSummariesForJit?: boolean;
|
2017-10-24 12:52:14 -07:00
|
|
|
|
2018-03-06 14:53:01 -08: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-11-20 10:21:17 -08:00
|
|
|
/**
|
|
|
|
* Tells the compiler to generate definitions using the Render3 style code generation.
|
2019-08-20 10:52:31 -07:00
|
|
|
* This option defaults to `true`.
|
2017-11-20 10:21:17 -08:00
|
|
|
*
|
build(ivy): support alternate compilation modes to enable Ivy testing (#24056)
Bazel has a restriction that a single output (eg. a compiled version of
//packages/common) can only be produced by a single rule. This precludes
the Angular repo from having multiple rules that build the same code. And
the complexity of having a single rule produce multiple outputs (eg. an
ngc-compiled version of //packages/common and an Ivy-enabled version) is
too high.
Additionally, the Angular repo has lots of existing tests which could be
executed as-is under Ivy. Such testing is very valuable, and it would be
nice to share not only the code, but the dependency graph / build config
as well.
Thus, this change introduces a --define flag 'compile' with three potential
values. When --define=compile=X is set, the entire build system runs in a
particular mode - the behavior of all existing targets is controlled by
the flag. This allows us to reuse our entire build structure for testing
in a variety of different manners. The flag has three possible settings:
* legacy (the default): the traditional View Engine (ngc) build
* local: runs the prototype ngtsc compiler, which does not rely on global
analysis
* jit: runs ngtsc in a mode which executes tsickle, but excludes the
Angular related transforms, which approximates the behavior of plain
tsc. This allows the main packages such as common to be tested with
the JIT compiler.
Additionally, the ivy_ng_module() rule still exists and runs ngc in a mode
where Ivy-compiled output is produced from global analysis information, as
a stopgap while ngtsc is being developed.
PR Close #24056
2018-05-21 15:48:00 -07:00
|
|
|
* Acceptable values are as follows:
|
|
|
|
*
|
|
|
|
* `false` - run ngc normally
|
2019-02-08 11:37:21 +00:00
|
|
|
* `true` - run the ngtsc compiler instead of the normal ngc compiler
|
|
|
|
* `ngtsc` - alias for `true`
|
build(ivy): support alternate compilation modes to enable Ivy testing (#24056)
Bazel has a restriction that a single output (eg. a compiled version of
//packages/common) can only be produced by a single rule. This precludes
the Angular repo from having multiple rules that build the same code. And
the complexity of having a single rule produce multiple outputs (eg. an
ngc-compiled version of //packages/common and an Ivy-enabled version) is
too high.
Additionally, the Angular repo has lots of existing tests which could be
executed as-is under Ivy. Such testing is very valuable, and it would be
nice to share not only the code, but the dependency graph / build config
as well.
Thus, this change introduces a --define flag 'compile' with three potential
values. When --define=compile=X is set, the entire build system runs in a
particular mode - the behavior of all existing targets is controlled by
the flag. This allows us to reuse our entire build structure for testing
in a variety of different manners. The flag has three possible settings:
* legacy (the default): the traditional View Engine (ngc) build
* local: runs the prototype ngtsc compiler, which does not rely on global
analysis
* jit: runs ngtsc in a mode which executes tsickle, but excludes the
Angular related transforms, which approximates the behavior of plain
tsc. This allows the main packages such as common to be tested with
the JIT compiler.
Additionally, the ivy_ng_module() rule still exists and runs ngc in a mode
where Ivy-compiled output is produced from global analysis information, as
a stopgap while ngtsc is being developed.
PR Close #24056
2018-05-21 15:48:00 -07:00
|
|
|
*
|
2018-10-19 12:12:20 +01:00
|
|
|
* @publicApi
|
2017-11-20 10:21:17 -08:00
|
|
|
*/
|
2019-08-20 10:54:02 -07:00
|
|
|
enableIvy?: boolean|'ngtsc';
|
2017-11-20 10:21:17 -08:00
|
|
|
|
2017-10-24 12:52:14 -07:00
|
|
|
/** @internal */
|
|
|
|
collectAllErrors?: boolean;
|
2019-02-12 23:29:28 +01:00
|
|
|
|
2019-03-18 11:16:38 -07:00
|
|
|
/** An option to enable ngtsc's internal performance tracing.
|
|
|
|
*
|
|
|
|
* This should be a path to a JSON file where trace information will be written. An optional 'ts:'
|
|
|
|
* prefix will cause the trace to be written via the TS host instead of directly to the filesystem
|
|
|
|
* (not all hosts support this mode of operation).
|
|
|
|
*
|
|
|
|
* This is currently not exposed to users as the trace format is still unstable.
|
|
|
|
*
|
|
|
|
* @internal */
|
|
|
|
tracePerformance?: string;
|
|
|
|
|
2019-02-12 23:29:28 +01: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;
|
2019-04-02 11:52:19 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn on template type-checking in the Ivy compiler.
|
|
|
|
*
|
|
|
|
* This is an internal flag being used to roll out template type-checking in ngtsc. Turning it on
|
|
|
|
* by default before it's ready might break other users attempting to test the new compiler's
|
|
|
|
* behavior.
|
|
|
|
*
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
ivyTemplateTypeCheck?: boolean;
|
2017-06-09 14:50:57 -07:00
|
|
|
}
|
|
|
|
|
2017-08-14 11:04:55 -07:00
|
|
|
export interface CompilerHost extends ts.CompilerHost {
|
2017-06-09 14:50:57 -07: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 09:40:28 -07:00
|
|
|
moduleNameToFileName?(moduleName: string, containingFile: string): string|null;
|
2017-06-09 14:50:57 -07:00
|
|
|
/**
|
2017-08-14 11:04:55 -07:00
|
|
|
* Converts a file path to a module name that can be used as an `import ...`
|
2017-06-09 14:50:57 -07:00
|
|
|
* I.e. `path/to/importedFile.ts` should be imported by `path/to/containingFile.ts`.
|
|
|
|
*/
|
2017-09-12 09:40:28 -07:00
|
|
|
fileNameToModuleName?(importedFilePath: string, containingFilePath: string): string;
|
2017-08-15 17:06:09 -07:00
|
|
|
/**
|
|
|
|
* Converts a file path for a resource that is used in a source file or another resource
|
|
|
|
* into a filepath.
|
|
|
|
*/
|
2017-09-12 09:40:28 -07:00
|
|
|
resourceNameToFileName?(resourceName: string, containingFilePath: string): string|null;
|
2017-08-15 14:41:48 -07: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`
|
|
|
|
*
|
|
|
|
* @param referringSrcFileName the soure file that refers to fileName
|
|
|
|
*/
|
2017-09-12 09:40:28 -07:00
|
|
|
toSummaryFileName?(fileName: string, referringSrcFileName: string): string;
|
2017-08-15 14:41:48 -07:00
|
|
|
/**
|
|
|
|
* Converts a fileName that was processed by `toSummaryFileName` back into a real fileName
|
|
|
|
* given the fileName of the library that is referrig to it.
|
|
|
|
*/
|
2017-09-12 09:40:28 -07:00
|
|
|
fromSummaryFileName?(fileName: string, referringLibFileName: string): string;
|
2017-06-09 14:50:57 -07:00
|
|
|
/**
|
|
|
|
* Load a referenced resource either statically or asynchronously. If the host returns a
|
|
|
|
* `Promise<string>` it is assumed the user of the corresponding `Program` will call
|
2018-03-10 17:14:58 +00:00
|
|
|
* `loadNgStructureAsync()`. Returning `Promise<string>` outside `loadNgStructureAsync()` will
|
2017-06-09 14:50:57 -07:00
|
|
|
* cause a diagnostics diagnostic error or an exception to be thrown.
|
|
|
|
*/
|
|
|
|
readResource?(fileName: string): Promise<string>|string;
|
2017-11-14 11:29:16 -08: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
|
|
|
|
* rather than by path. See http://requirejs.org/docs/whyamd.html#namedmodules
|
|
|
|
*/
|
|
|
|
amdModuleName?(sf: ts.SourceFile): string|undefined;
|
2019-06-10 16:22:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the absolute paths to the changed files that triggered the current compilation
|
|
|
|
* or `undefined` if this is not an incremental build.
|
|
|
|
*/
|
|
|
|
getModifiedResourceFiles?(): Set<string>|undefined;
|
2017-06-09 14:50:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum EmitFlags {
|
|
|
|
DTS = 1 << 0,
|
|
|
|
JS = 1 << 1,
|
|
|
|
Metadata = 1 << 2,
|
|
|
|
I18nBundle = 1 << 3,
|
2017-09-19 11:41:47 -07:00
|
|
|
Codegen = 1 << 4,
|
2017-06-09 14:50:57 -07:00
|
|
|
|
2017-09-19 11:41:47 -07:00
|
|
|
Default = DTS | JS | Codegen,
|
|
|
|
All = DTS | JS | Metadata | I18nBundle | Codegen,
|
2017-06-09 14:50:57 -07:00
|
|
|
}
|
|
|
|
|
2017-08-16 15:35:19 -07:00
|
|
|
export interface CustomTransformers {
|
|
|
|
beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
|
|
|
|
afterTs?: ts.TransformerFactory<ts.SourceFile>[];
|
2017-08-02 11:20:07 -07:00
|
|
|
}
|
|
|
|
|
2017-10-12 16:09:49 -07:00
|
|
|
export interface TsEmitArguments {
|
2017-08-16 15:35:19 -07:00
|
|
|
program: ts.Program;
|
|
|
|
host: CompilerHost;
|
|
|
|
options: CompilerOptions;
|
2017-10-12 16:09:49 -07:00
|
|
|
targetSourceFile?: ts.SourceFile;
|
2017-08-16 15:35:19 -07:00
|
|
|
writeFile?: ts.WriteFileCallback;
|
|
|
|
cancellationToken?: ts.CancellationToken;
|
|
|
|
emitOnlyDtsFiles?: boolean;
|
|
|
|
customTransformers?: ts.CustomTransformers;
|
|
|
|
}
|
|
|
|
|
2017-10-12 16:09:49 -07:00
|
|
|
export interface TsEmitCallback { (args: TsEmitArguments): ts.EmitResult; }
|
2018-03-20 16:11:20 -07:00
|
|
|
export interface TsMergeEmitResultsCallback { (results: ts.EmitResult[]): ts.EmitResult; }
|
2017-08-16 15:35:19 -07:00
|
|
|
|
2017-09-21 18:05:07 -07:00
|
|
|
export interface LibrarySummary {
|
|
|
|
fileName: string;
|
|
|
|
text: string;
|
|
|
|
sourceFile?: ts.SourceFile;
|
|
|
|
}
|
|
|
|
|
2017-10-20 09:46:41 -07:00
|
|
|
export interface LazyRoute {
|
|
|
|
route: string;
|
|
|
|
module: {name: string, filePath: string};
|
|
|
|
referencedModule: {name: string, filePath: string};
|
|
|
|
}
|
|
|
|
|
2017-06-09 14:50:57 -07: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 11:20:07 -07:00
|
|
|
* Retrieve options diagnostics for the TypeScript options used to create the program. This is
|
2017-06-09 14:50:57 -07:00
|
|
|
* faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to
|
|
|
|
* collect Angular structural information to produce the errors.
|
|
|
|
*/
|
2017-12-22 09:36:47 -08:00
|
|
|
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 14:50:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve options diagnostics for the Angular options used to create the program.
|
|
|
|
*/
|
2018-12-13 11:52:20 -08:00
|
|
|
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken):
|
|
|
|
ReadonlyArray<ts.Diagnostic|Diagnostic>;
|
2017-06-09 14:50:57 -07:00
|
|
|
|
|
|
|
/**
|
2017-08-02 11:20:07 -07:00
|
|
|
* Retrieve the syntax diagnostics from TypeScript. This is faster than calling
|
2017-06-09 14:50:57 -07: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 09:36:47 -08:00
|
|
|
ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 14:50:57 -07: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 16:16:42 +02:00
|
|
|
* structural diagnostics as an error in the program structure might cause errors detected in
|
2017-06-09 14:50:57 -07:00
|
|
|
* semantic analysis and a semantic error might cause errors in specifying the program structure.
|
|
|
|
*
|
|
|
|
* Angular structural information is required to produce these diagnostics.
|
|
|
|
*/
|
2017-12-22 09:36:47 -08:00
|
|
|
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): ReadonlyArray<Diagnostic>;
|
2017-06-09 14:50:57 -07:00
|
|
|
|
|
|
|
/**
|
2018-03-10 17:14:58 +00:00
|
|
|
* Retrieve the semantic diagnostics from TypeScript. This is equivalent to calling
|
2017-06-09 14:50:57 -07:00
|
|
|
* `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness.
|
|
|
|
*/
|
|
|
|
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
2017-12-22 09:36:47 -08:00
|
|
|
ReadonlyArray<ts.Diagnostic>;
|
2017-06-09 14:50:57 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the Angular semantic diagnostics.
|
|
|
|
*
|
|
|
|
* Angular structural information is required to produce these diagnostics.
|
|
|
|
*/
|
2017-10-12 16:09:49 -07:00
|
|
|
getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken):
|
2018-08-23 14:34:55 -07:00
|
|
|
ReadonlyArray<ts.Diagnostic|Diagnostic>;
|
2017-06-09 14:50:57 -07: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 09:46:41 -07:00
|
|
|
/**
|
|
|
|
* Returns the lazy routes in the program.
|
|
|
|
* @param entryRoute A reference to an NgModule like `someModule#name`. If given,
|
|
|
|
* will recursively analyze routes starting from this symbol only.
|
|
|
|
* Otherwise will list all routes for all NgModules in the program/
|
|
|
|
*/
|
|
|
|
listLazyRoutes(entryRoute?: string): LazyRoute[];
|
|
|
|
|
2017-06-09 14:50:57 -07:00
|
|
|
/**
|
|
|
|
* Emit the files requested by emitFlags implied by the program.
|
|
|
|
*
|
|
|
|
* Angular structural information is required to emit files.
|
|
|
|
*/
|
2018-03-20 16:11:20 -07:00
|
|
|
emit({emitFlags, cancellationToken, customTransformers, emitCallback,
|
|
|
|
mergeEmitResultsCallback}?: {
|
2017-08-16 15:35:19 -07:00
|
|
|
emitFlags?: EmitFlags,
|
2017-06-09 14:50:57 -07:00
|
|
|
cancellationToken?: ts.CancellationToken,
|
2017-08-16 15:35:19 -07:00
|
|
|
customTransformers?: CustomTransformers,
|
2018-03-20 16:11:20 -07:00
|
|
|
emitCallback?: TsEmitCallback,
|
|
|
|
mergeEmitResultsCallback?: TsMergeEmitResultsCallback
|
2017-08-16 15:35:19 -07:00
|
|
|
}): ts.EmitResult;
|
2017-09-19 11:43:34 -07:00
|
|
|
|
|
|
|
/**
|
2017-09-21 18:05:07 -07:00
|
|
|
* Returns the .d.ts / .ngsummary.json / .ngfactory.d.ts files of libraries that have been emitted
|
|
|
|
* in this program or previous programs with paths that emulate the fact that these libraries
|
|
|
|
* have been compiled before with no outDir.
|
2017-09-29 15:02:11 -07:00
|
|
|
*/
|
|
|
|
getLibrarySummaries(): Map<string, LibrarySummary>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2017-09-19 11:43:34 -07:00
|
|
|
*/
|
2017-10-12 16:09:49 -07:00
|
|
|
getEmittedGeneratedFiles(): Map<string, GeneratedFile>;
|
2017-10-03 09:53:58 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
getEmittedSourceFiles(): Map<string, ts.SourceFile>;
|
2017-06-09 14:50:57 -07:00
|
|
|
}
|