feat(compiler-cli): new compiler api and command-line using TypeScript transformers
This commit is contained in:

committed by
Matias Niemelä

parent
43c187b624
commit
3097083277
227
packages/compiler-cli/src/transformers/api.ts
Normal file
227
packages/compiler-cli/src/transformers/api.ts
Normal file
@ -0,0 +1,227 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {ParseSourceSpan} from '@angular/compiler';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
export enum DiagnosticCategory {
|
||||
Warning = 0,
|
||||
Error = 1,
|
||||
Message = 2,
|
||||
}
|
||||
|
||||
export interface Diagnostic {
|
||||
message: string;
|
||||
span?: ParseSourceSpan;
|
||||
category: DiagnosticCategory;
|
||||
}
|
||||
|
||||
export interface CompilerOptions extends ts.CompilerOptions {
|
||||
// Absolute path to a directory where generated file structure is written.
|
||||
// If unspecified, generated files will be written alongside sources.
|
||||
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;
|
||||
|
||||
// Don't produce .ngfactory.ts or .ngstyle.ts files
|
||||
skipTemplateCodegen?: boolean;
|
||||
|
||||
// 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.
|
||||
// When this option is used the `package.json` for the library should refered to the
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
|
||||
// Whether to enable support for <template> and the template attribute (true by default)
|
||||
enableLegacyTemplate?: boolean;
|
||||
}
|
||||
|
||||
export interface ModuleFilenameResolver {
|
||||
/**
|
||||
* 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'`.
|
||||
*/
|
||||
moduleNameToFileName(moduleName: string, containingFile?: string): string|null;
|
||||
|
||||
/**
|
||||
* Converts a file path to a module name that can be used as an `import.
|
||||
* I.e. `path/to/importedFile.ts` should be imported by `path/to/containingFile.ts`.
|
||||
*
|
||||
* See ImportResolver.
|
||||
*/
|
||||
fileNameToModuleName(importedFilePath: string, containingFilePath: string): string|null;
|
||||
|
||||
getNgCanonicalFileName(fileName: string): string;
|
||||
|
||||
assumeFileExists(fileName: string): void;
|
||||
}
|
||||
|
||||
export interface CompilerHost extends ts.CompilerHost, ModuleFilenameResolver {
|
||||
/**
|
||||
* 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
|
||||
* `loadNgStructureAsync()`. Returing `Promise<string>` outside `loadNgStructureAsync()` will
|
||||
* cause a diagnostics diagnostic error or an exception to be thrown.
|
||||
*
|
||||
* If `loadResource()` is not provided, `readFile()` will be called to load the resource.
|
||||
*/
|
||||
readResource?(fileName: string): Promise<string>|string;
|
||||
}
|
||||
|
||||
export enum EmitFlags {
|
||||
DTS = 1 << 0,
|
||||
JS = 1 << 1,
|
||||
Metadata = 1 << 2,
|
||||
I18nBundle = 1 << 3,
|
||||
Summary = 1 << 4,
|
||||
|
||||
Default = DTS | JS,
|
||||
All = DTS | JS | Metadata | I18nBundle | Summary
|
||||
}
|
||||
|
||||
// TODO(chuckj): Support CustomTransformers once we require TypeScript 2.3+
|
||||
// export interface CustomTransformers {
|
||||
// beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
|
||||
// afterTs?: ts.TransformerFactory<ts.SourceFile>[];
|
||||
// }
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Retreive options diagnostics for the TypeScript options used to create the program. This is
|
||||
* faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to
|
||||
* collect Angular structural information to produce the errors.
|
||||
*/
|
||||
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ts.Diagnostic[];
|
||||
|
||||
/**
|
||||
* Retrieve options diagnostics for the Angular options used to create the program.
|
||||
*/
|
||||
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
|
||||
|
||||
/**
|
||||
* Retrive the syntax diagnostics from TypeScript. This is faster than calling
|
||||
* `getTsProgram().getSyntacticDiagnostics()` since it does not need to collect Angular structural
|
||||
* information to produce the errors.
|
||||
*/
|
||||
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
||||
ts.Diagnostic[];
|
||||
|
||||
/**
|
||||
* 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
|
||||
* structural diagnostics as an error in the program strucutre might cause errors detected in
|
||||
* semantic analysis and a semantic error might cause errors in specifying the program structure.
|
||||
*
|
||||
* Angular structural information is required to produce these diagnostics.
|
||||
*/
|
||||
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
|
||||
|
||||
/**
|
||||
* Retreive the semantic diagnostics from TypeScript. This is equivilent to calling
|
||||
* `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness.
|
||||
*/
|
||||
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
||||
ts.Diagnostic[];
|
||||
|
||||
/**
|
||||
* Retrieve the Angular semantic diagnostics.
|
||||
*
|
||||
* Angular structural information is required to produce these diagnostics.
|
||||
*/
|
||||
getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken):
|
||||
Diagnostic[];
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
|
||||
/**
|
||||
* Retrieve the lazy route references in the program.
|
||||
*
|
||||
* Angular structural information is required to produce these routes.
|
||||
*/
|
||||
getLazyRoutes(cancellationToken?: ts.CancellationToken): {[route: string]: string};
|
||||
|
||||
/**
|
||||
* Emit the files requested by emitFlags implied by the program.
|
||||
*
|
||||
* Angular structural information is required to emit files.
|
||||
*/
|
||||
emit({// transformers,
|
||||
emitFlags, cancellationToken}: {
|
||||
emitFlags: EmitFlags,
|
||||
// transformers?: CustomTransformers, // See TODO above
|
||||
cancellationToken?: ts.CancellationToken,
|
||||
}): void;
|
||||
}
|
24
packages/compiler-cli/src/transformers/entry_points.ts
Normal file
24
packages/compiler-cli/src/transformers/entry_points.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {CompilerHost, CompilerOptions, Program} from './api';
|
||||
import {createModuleFilenameResolver} from './module_filename_resolver';
|
||||
export {createProgram} from './program';
|
||||
export {createModuleFilenameResolver};
|
||||
|
||||
export function createHost({tsHost, options}: {tsHost: ts.CompilerHost, options: CompilerOptions}):
|
||||
CompilerHost {
|
||||
const resolver = createModuleFilenameResolver(tsHost, options);
|
||||
|
||||
const host = Object.create(tsHost);
|
||||
|
||||
host.moduleNameToFileName = resolver.moduleNameToFileName.bind(resolver);
|
||||
host.fileNameToModuleName = resolver.fileNameToModuleName.bind(resolver);
|
||||
host.getNgCanonicalFileName = resolver.getNgCanonicalFileName.bind(resolver);
|
||||
host.assumeFileExists = resolver.assumeFileExists.bind(resolver);
|
||||
|
||||
// Make sure we do not `host.realpath()` from TS as we do not want to resolve symlinks.
|
||||
// https://github.com/Microsoft/TypeScript/issues/9552
|
||||
host.realpath = (fileName: string) => fileName;
|
||||
|
||||
return host;
|
||||
}
|
@ -0,0 +1,285 @@
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {ModuleFilenameResolver} from './api';
|
||||
import {CompilerOptions} from './api';
|
||||
|
||||
const EXT = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||
const DTS = /\.d\.ts$/;
|
||||
const NODE_MODULES = '/node_modules/';
|
||||
const IS_GENERATED = /\.(ngfactory|ngstyle|ngsummary)$/;
|
||||
const SHALLOW_IMPORT = /^((\w|-)+|(@(\w|-)+(\/(\w|-)+)+))$/;
|
||||
|
||||
export function createModuleFilenameResolver(
|
||||
tsHost: ts.ModuleResolutionHost, options: CompilerOptions): ModuleFilenameResolver {
|
||||
const host = createModuleFilenameResolverHost(tsHost);
|
||||
|
||||
return options.rootDirs && options.rootDirs.length > 0 ?
|
||||
new MultipleRootDirModuleFilenameResolver(host, options) :
|
||||
new SingleRootDirModuleFilenameResolver(host, options);
|
||||
}
|
||||
|
||||
class SingleRootDirModuleFilenameResolver implements ModuleFilenameResolver {
|
||||
private isGenDirChildOfRootDir: boolean;
|
||||
private basePath: string;
|
||||
private genDir: string;
|
||||
private moduleFileNames = new Map<string, string|null>();
|
||||
|
||||
constructor(private host: ModuleFilenameResolutionHost, private options: CompilerOptions) {
|
||||
// normalize the path so that it never ends with '/'.
|
||||
this.basePath = path.normalize(path.join(options.basePath, '.')).replace(/\\/g, '/');
|
||||
this.genDir = path.normalize(path.join(options.genDir, '.')).replace(/\\/g, '/');
|
||||
|
||||
const genPath: string = path.relative(this.basePath, this.genDir);
|
||||
this.isGenDirChildOfRootDir = genPath === '' || !genPath.startsWith('..');
|
||||
}
|
||||
|
||||
moduleNameToFileName(m: string, containingFile: string): string|null {
|
||||
const key = m + ':' + (containingFile || '');
|
||||
let result: string|null = this.moduleFileNames.get(key) || null;
|
||||
if (!result) {
|
||||
if (!containingFile) {
|
||||
if (m.indexOf('.') === 0) {
|
||||
throw new Error('Resolution of relative paths requires a containing file.');
|
||||
}
|
||||
// Any containing file gives the same result for absolute imports
|
||||
containingFile = this.getNgCanonicalFileName(path.join(this.basePath, 'index.ts'));
|
||||
}
|
||||
m = m.replace(EXT, '');
|
||||
const resolved =
|
||||
ts.resolveModuleName(m, containingFile.replace(/\\/g, '/'), this.options, this.host)
|
||||
.resolvedModule;
|
||||
result = resolved ? this.getNgCanonicalFileName(resolved.resolvedFileName) : null;
|
||||
this.moduleFileNames.set(key, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* We want a moduleId that will appear in import statements in the generated code.
|
||||
* These need to be in a form that system.js can load, so absolute file paths don't work.
|
||||
*
|
||||
* The `containingFile` is always in the `genDir`, where as the `importedFile` can be in
|
||||
* `genDir`, `node_module` or `basePath`. The `importedFile` is either a generated file or
|
||||
* existing file.
|
||||
*
|
||||
* | genDir | node_module | rootDir
|
||||
* --------------+----------+-------------+----------
|
||||
* generated | relative | relative | n/a
|
||||
* existing file | n/a | absolute | relative(*)
|
||||
*
|
||||
* NOTE: (*) the relative path is computed depending on `isGenDirChildOfRootDir`.
|
||||
*/
|
||||
fileNameToModuleName(importedFile: string, containingFile: string): string {
|
||||
// If a file does not yet exist (because we compile it later), we still need to
|
||||
// assume it exists it so that the `resolve` method works!
|
||||
if (!this.host.fileExists(importedFile)) {
|
||||
this.host.assumeFileExists(importedFile);
|
||||
}
|
||||
|
||||
containingFile = this.rewriteGenDirPath(containingFile);
|
||||
const containingDir = path.dirname(containingFile);
|
||||
// drop extension
|
||||
importedFile = importedFile.replace(EXT, '');
|
||||
|
||||
const nodeModulesIndex = importedFile.indexOf(NODE_MODULES);
|
||||
const importModule = nodeModulesIndex === -1 ?
|
||||
null :
|
||||
importedFile.substring(nodeModulesIndex + NODE_MODULES.length);
|
||||
const isGeneratedFile = IS_GENERATED.test(importedFile);
|
||||
|
||||
if (isGeneratedFile) {
|
||||
// rewrite to genDir path
|
||||
if (importModule) {
|
||||
// it is generated, therefore we do a relative path to the factory
|
||||
return this.dotRelative(containingDir, this.genDir + NODE_MODULES + importModule);
|
||||
} else {
|
||||
// assume that import is also in `genDir`
|
||||
importedFile = this.rewriteGenDirPath(importedFile);
|
||||
return this.dotRelative(containingDir, importedFile);
|
||||
}
|
||||
} else {
|
||||
// user code import
|
||||
if (importModule) {
|
||||
return importModule;
|
||||
} else {
|
||||
if (!this.isGenDirChildOfRootDir) {
|
||||
// assume that they are on top of each other.
|
||||
importedFile = importedFile.replace(this.basePath, this.genDir);
|
||||
}
|
||||
if (SHALLOW_IMPORT.test(importedFile)) {
|
||||
return importedFile;
|
||||
}
|
||||
return this.dotRelative(containingDir, importedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We use absolute paths on disk as canonical.
|
||||
getNgCanonicalFileName(fileName: string): string { return fileName; }
|
||||
|
||||
assumeFileExists(fileName: string) { this.host.assumeFileExists(fileName); }
|
||||
|
||||
private dotRelative(from: string, to: string): string {
|
||||
const rPath: string = path.relative(from, to).replace(/\\/g, '/');
|
||||
return rPath.startsWith('.') ? rPath : './' + rPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the path into `genDir` folder while preserving the `node_modules` directory.
|
||||
*/
|
||||
private rewriteGenDirPath(filepath: string) {
|
||||
const nodeModulesIndex = filepath.indexOf(NODE_MODULES);
|
||||
if (nodeModulesIndex !== -1) {
|
||||
// If we are in node_module, transplant them into `genDir`.
|
||||
return path.join(this.genDir, filepath.substring(nodeModulesIndex));
|
||||
} else {
|
||||
// pretend that containing file is on top of the `genDir` to normalize the paths.
|
||||
// we apply the `genDir` => `rootDir` delta through `rootDirPrefix` later.
|
||||
return filepath.replace(this.basePath, this.genDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This version of the AotCompilerHost expects that the program will be compiled
|
||||
* and executed with a "path mapped" directory structure, where generated files
|
||||
* are in a parallel tree with the sources, and imported using a `./` relative
|
||||
* import. This requires using TS `rootDirs` option and also teaching the module
|
||||
* loader what to do.
|
||||
*/
|
||||
class MultipleRootDirModuleFilenameResolver implements ModuleFilenameResolver {
|
||||
private basePath: string;
|
||||
|
||||
constructor(private host: ModuleFilenameResolutionHost, private options: CompilerOptions) {
|
||||
// normalize the path so that it never ends with '/'.
|
||||
this.basePath = path.normalize(path.join(options.basePath, '.')).replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
getNgCanonicalFileName(fileName: string): string {
|
||||
if (!fileName) return fileName;
|
||||
// NB: the rootDirs should have been sorted longest-first
|
||||
for (const dir of this.options.rootDirs || []) {
|
||||
if (fileName.indexOf(dir) === 0) {
|
||||
fileName = fileName.substring(dir.length);
|
||||
}
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
assumeFileExists(fileName: string) { this.host.assumeFileExists(fileName); }
|
||||
|
||||
moduleNameToFileName(m: string, containingFile: string): string|null {
|
||||
if (!containingFile) {
|
||||
if (m.indexOf('.') === 0) {
|
||||
throw new Error('Resolution of relative paths requires a containing file.');
|
||||
}
|
||||
// Any containing file gives the same result for absolute imports
|
||||
containingFile = this.getNgCanonicalFileName(path.join(this.basePath, 'index.ts'));
|
||||
}
|
||||
for (const root of this.options.rootDirs || ['']) {
|
||||
const rootedContainingFile = path.join(root, containingFile);
|
||||
const resolved =
|
||||
ts.resolveModuleName(m, rootedContainingFile, this.options, this.host).resolvedModule;
|
||||
if (resolved) {
|
||||
if (this.options.traceResolution) {
|
||||
console.error('resolve', m, containingFile, '=>', resolved.resolvedFileName);
|
||||
}
|
||||
return this.getNgCanonicalFileName(resolved.resolvedFileName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* We want a moduleId that will appear in import statements in the generated code.
|
||||
* These need to be in a form that system.js can load, so absolute file paths don't work.
|
||||
* Relativize the paths by checking candidate prefixes of the absolute path, to see if
|
||||
* they are resolvable by the moduleResolution strategy from the CompilerHost.
|
||||
*/
|
||||
fileNameToModuleName(importedFile: string, containingFile: string): string {
|
||||
if (this.options.traceResolution) {
|
||||
console.error(
|
||||
'getImportPath from containingFile', containingFile, 'to importedFile', importedFile);
|
||||
}
|
||||
|
||||
// If a file does not yet exist (because we compile it later), we still need to
|
||||
// assume it exists so that the `resolve` method works!
|
||||
if (!this.host.fileExists(importedFile)) {
|
||||
if (this.options.rootDirs && this.options.rootDirs.length > 0) {
|
||||
this.host.assumeFileExists(path.join(this.options.rootDirs[0], importedFile));
|
||||
} else {
|
||||
this.host.assumeFileExists(importedFile);
|
||||
}
|
||||
}
|
||||
|
||||
const resolvable = (candidate: string) => {
|
||||
const resolved = this.moduleNameToFileName(candidate, importedFile);
|
||||
return resolved && resolved.replace(EXT, '') === importedFile.replace(EXT, '');
|
||||
};
|
||||
|
||||
const importModuleName = importedFile.replace(EXT, '');
|
||||
const parts = importModuleName.split(path.sep).filter(p => !!p);
|
||||
let foundRelativeImport: string|undefined;
|
||||
|
||||
for (let index = parts.length - 1; index >= 0; index--) {
|
||||
let candidate = parts.slice(index, parts.length).join(path.sep);
|
||||
if (resolvable(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
candidate = '.' + path.sep + candidate;
|
||||
if (resolvable(candidate)) {
|
||||
foundRelativeImport = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundRelativeImport) return foundRelativeImport;
|
||||
|
||||
// Try a relative import
|
||||
const candidate = path.relative(path.dirname(containingFile), importModuleName);
|
||||
if (resolvable(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Unable to find any resolvable import for ${importedFile} relative to ${containingFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
interface ModuleFilenameResolutionHost extends ts.ModuleResolutionHost {
|
||||
assumeFileExists(fileName: string): void;
|
||||
}
|
||||
|
||||
function createModuleFilenameResolverHost(host: ts.ModuleResolutionHost):
|
||||
ModuleFilenameResolutionHost {
|
||||
const assumedExists = new Set<string>();
|
||||
const resolveModuleNameHost = Object.create(host);
|
||||
// When calling ts.resolveModuleName, additional allow checks for .d.ts files to be done based on
|
||||
// checks for .ngsummary.json files, so that our codegen depends on fewer inputs and requires
|
||||
// to be called less often.
|
||||
// This is needed as we use ts.resolveModuleName in reflector_host and it should be able to
|
||||
// resolve summary file names.
|
||||
resolveModuleNameHost.fileExists = (fileName: string): boolean => {
|
||||
if (assumedExists.has(fileName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (host.fileExists(fileName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (DTS.test(fileName)) {
|
||||
const base = fileName.substring(0, fileName.length - 5);
|
||||
return host.fileExists(base + '.ngsummary.json');
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
resolveModuleNameHost.assumeFileExists = (fileName: string) => assumedExists.add(fileName);
|
||||
// Make sure we do not `host.realpath()` from TS as we do not want to resolve symlinks.
|
||||
// https://github.com/Microsoft/TypeScript/issues/9552
|
||||
resolveModuleNameHost.realpath = (fileName: string) => fileName;
|
||||
|
||||
return resolveModuleNameHost;
|
||||
}
|
@ -16,9 +16,8 @@ const CATCH_ERROR_NAME = 'error';
|
||||
const CATCH_STACK_NAME = 'stack';
|
||||
|
||||
export class TypeScriptNodeEmitter {
|
||||
updateSourceFile(
|
||||
sourceFile: ts.SourceFile, srcFilePath: string, genFilePath: string, stmts: Statement[],
|
||||
exportedVars: string[], preamble?: string): [ts.SourceFile, Map<ts.Node, Node>] {
|
||||
updateSourceFile(sourceFile: ts.SourceFile, stmts: Statement[], preamble?: string):
|
||||
[ts.SourceFile, Map<ts.Node, Node>] {
|
||||
const converter = new _NodeEmitterVisitor();
|
||||
const statements =
|
||||
stmts.map(stmt => stmt.visitStatement(converter, null)).filter(stmt => stmt != null);
|
||||
@ -99,9 +98,6 @@ class _NodeEmitterVisitor implements StatementVisitor, ExpressionVisitor {
|
||||
if (stmt.hasModifier(StmtModifier.Exported)) {
|
||||
modifiers.push(ts.createToken(ts.SyntaxKind.ExportKeyword));
|
||||
}
|
||||
if (stmt.hasModifier(StmtModifier.Final)) {
|
||||
modifiers.push(ts.createToken(ts.SyntaxKind.ConstKeyword));
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
@ -140,7 +136,7 @@ class _NodeEmitterVisitor implements StatementVisitor, ExpressionVisitor {
|
||||
p => ts.createParameter(
|
||||
/* decorators */ undefined, /* modifiers */ undefined,
|
||||
/* dotDotDotToken */ undefined, p.name)),
|
||||
undefined, this._visitStatements(stmt.statements)));
|
||||
/* type */ undefined, this._visitStatements(stmt.statements)));
|
||||
}
|
||||
|
||||
visitExpressionStmt(stmt: ExpressionStatement) {
|
||||
@ -187,7 +183,7 @@ class _NodeEmitterVisitor implements StatementVisitor, ExpressionVisitor {
|
||||
p => ts.createParameter(
|
||||
/* decorators */ undefined, /* modifiers */ undefined,
|
||||
/* dotDotDotToken */ undefined, p.name)),
|
||||
undefined, this._visitStatements(method.body)));
|
||||
/* type */ undefined, this._visitStatements(method.body)));
|
||||
return this.record(
|
||||
stmt, ts.createClassDeclaration(
|
||||
/* decorators */ undefined, modifiers, stmt.name, /* typeParameters*/ undefined,
|
||||
@ -221,7 +217,7 @@ class _NodeEmitterVisitor implements StatementVisitor, ExpressionVisitor {
|
||||
ts.createIdentifier(CATCH_ERROR_NAME),
|
||||
ts.createIdentifier(CATCH_STACK_NAME)))])],
|
||||
stmt.catchStmts)),
|
||||
undefined));
|
||||
/* finallyBlock */ undefined));
|
||||
}
|
||||
|
||||
visitThrowStmt(stmt: ThrowStmt) {
|
||||
|
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {GeneratedFile} from '@angular/compiler';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {TypeScriptNodeEmitter} from './node_emitter';
|
||||
|
||||
export function getAngularEmitterTransformFactory(generatedFiles: GeneratedFile[]): () =>
|
||||
(sourceFile: ts.SourceFile) => ts.SourceFile {
|
||||
return function() {
|
||||
const map = new Map(generatedFiles.filter(g => g.stmts && g.stmts.length)
|
||||
.map<[string, GeneratedFile]>(g => [g.genFileUrl, g]));
|
||||
const emitter = new TypeScriptNodeEmitter();
|
||||
return function(sourceFile: ts.SourceFile): ts.SourceFile {
|
||||
const g = map.get(sourceFile.fileName);
|
||||
if (g && g.stmts) {
|
||||
const [newSourceFile] = emitter.updateSourceFile(sourceFile, g.stmts);
|
||||
return newSourceFile;
|
||||
}
|
||||
return sourceFile;
|
||||
};
|
||||
};
|
||||
}
|
391
packages/compiler-cli/src/transformers/program.ts
Normal file
391
packages/compiler-cli/src/transformers/program.ts
Normal file
@ -0,0 +1,391 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {AotCompiler, GeneratedFile, NgAnalyzedModules, createAotCompiler, getParseErrors, isSyntaxError, toTypeScript} from '@angular/compiler';
|
||||
import {MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped';
|
||||
import {writeFileSync} from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {CompilerHost as AotCompilerHost, CompilerHostContext} from '../compiler_host';
|
||||
import {TypeChecker} from '../diagnostics/check_types';
|
||||
|
||||
import {CompilerHost, CompilerOptions, DiagnosticCategory} from './api';
|
||||
import {Diagnostic, EmitFlags, Program} from './api';
|
||||
import {getAngularEmitterTransformFactory} from './node_emitter_transform';
|
||||
|
||||
const GENERATED_FILES = /\.ngfactory\.js$|\.ngstyle\.js$|\.ngsummary\.js$/;
|
||||
const SUMMARY_JSON_FILES = /\.ngsummary.json$/;
|
||||
|
||||
const emptyModules: NgAnalyzedModules = {
|
||||
ngModules: [],
|
||||
ngModuleByPipeOrDirective: new Map(),
|
||||
files: []
|
||||
};
|
||||
|
||||
class AngularCompilerProgram implements Program {
|
||||
// Initialized in the constructor
|
||||
private oldTsProgram: ts.Program|undefined;
|
||||
private tsProgram: ts.Program;
|
||||
private aotCompilerHost: AotCompilerHost;
|
||||
private compiler: AotCompiler;
|
||||
private srcNames: string[];
|
||||
private collector: MetadataCollector;
|
||||
// Lazily initialized fields
|
||||
private _analyzedModules: NgAnalyzedModules|undefined;
|
||||
private _structuralDiagnostics: Diagnostic[] = [];
|
||||
private _stubs: GeneratedFile[]|undefined;
|
||||
private _stubFiles: string[]|undefined;
|
||||
private _programWithStubsHost: ts.CompilerHost|undefined;
|
||||
private _programWithStubs: ts.Program|undefined;
|
||||
private _generatedFiles: GeneratedFile[]|undefined;
|
||||
private _generatedFileDiagnostics: Diagnostic[]|undefined;
|
||||
private _typeChecker: TypeChecker|undefined;
|
||||
private _semanticDiagnostics: Diagnostic[]|undefined;
|
||||
|
||||
constructor(
|
||||
private rootNames: string[], private options: CompilerOptions, private host: CompilerHost,
|
||||
private oldProgram?: Program) {
|
||||
this.oldTsProgram = oldProgram ? oldProgram.getTsProgram() : undefined;
|
||||
|
||||
this.tsProgram = ts.createProgram(rootNames, options, host, this.oldTsProgram);
|
||||
this.srcNames = this.tsProgram.getSourceFiles().map(sf => sf.fileName);
|
||||
this.aotCompilerHost = new AotCompilerHost(this.tsProgram, options, host);
|
||||
if (host.readResource) {
|
||||
this.aotCompilerHost.loadResource = host.readResource.bind(host);
|
||||
}
|
||||
const {compiler} = createAotCompiler(this.aotCompilerHost, options);
|
||||
this.compiler = compiler;
|
||||
this.collector = new MetadataCollector({quotedNames: true});
|
||||
}
|
||||
|
||||
// Program implementation
|
||||
getTsProgram(): ts.Program { return this.programWithStubs; }
|
||||
|
||||
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken) {
|
||||
return this.tsProgram.getOptionsDiagnostics(cancellationToken);
|
||||
}
|
||||
|
||||
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[] {
|
||||
return getNgOptionDiagnostics(this.options);
|
||||
}
|
||||
|
||||
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
||||
ts.Diagnostic[] {
|
||||
return this.tsProgram.getSyntacticDiagnostics(sourceFile, cancellationToken);
|
||||
}
|
||||
|
||||
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[] {
|
||||
return this.structuralDiagnostics;
|
||||
}
|
||||
|
||||
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
||||
ts.Diagnostic[] {
|
||||
return this.programWithStubs.getSemanticDiagnostics(sourceFile, cancellationToken);
|
||||
}
|
||||
|
||||
getNgSemanticDiagnostics(fileName?: string, cancellationToken?: ts.CancellationToken):
|
||||
Diagnostic[] {
|
||||
const compilerDiagnostics = this.generatedFileDiagnostics;
|
||||
|
||||
// If we have diagnostics during the parser phase the type check phase is not meaningful so skip
|
||||
// it.
|
||||
if (compilerDiagnostics && compilerDiagnostics.length) return compilerDiagnostics;
|
||||
|
||||
return this.typeChecker.getDiagnostics(fileName, cancellationToken);
|
||||
}
|
||||
|
||||
loadNgStructureAsync(): Promise<void> {
|
||||
return this.compiler.analyzeModulesAsync(this.rootNames)
|
||||
.catch(this.catchAnalysisError.bind(this))
|
||||
.then(analyzedModules => {
|
||||
if (this._analyzedModules) {
|
||||
throw new Error('Angular structure loaded both synchronously and asynchronsly');
|
||||
}
|
||||
this._analyzedModules = analyzedModules;
|
||||
});
|
||||
}
|
||||
|
||||
getLazyRoutes(cancellationToken?: ts.CancellationToken): {[route: string]: string} { return {}; }
|
||||
|
||||
emit({emitFlags = EmitFlags.Default, cancellationToken}:
|
||||
{emitFlags?: EmitFlags, cancellationToken?: ts.CancellationToken}): ts.EmitResult {
|
||||
const emitMap = new Map<string, string>();
|
||||
const result = this.programWithStubs.emit(
|
||||
/* targetSourceFile */ undefined,
|
||||
createWriteFileCallback(emitFlags, this.host, this.collector, this.options, emitMap),
|
||||
cancellationToken, (emitFlags & (EmitFlags.DTS | EmitFlags.JS)) == EmitFlags.DTS, {
|
||||
after: this.options.skipTemplateCodegen ? [] : [getAngularEmitterTransformFactory(
|
||||
this.generatedFiles)]
|
||||
});
|
||||
|
||||
this.generatedFiles.forEach(file => {
|
||||
if (file.source && file.source.length && SUMMARY_JSON_FILES.test(file.genFileUrl)) {
|
||||
// If we have emitted the ngsummary.ts file, ensure the ngsummary.json file is emitted to
|
||||
// the same location.
|
||||
const emittedFile = emitMap.get(file.srcFileUrl);
|
||||
const fileName = emittedFile ?
|
||||
path.join(path.dirname(emittedFile), path.basename(file.genFileUrl)) :
|
||||
file.genFileUrl;
|
||||
this.host.writeFile(fileName, file.source, false, error => {});
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Private members
|
||||
private get analyzedModules(): NgAnalyzedModules {
|
||||
return this._analyzedModules || (this._analyzedModules = this.analyzeModules());
|
||||
}
|
||||
|
||||
private get structuralDiagnostics(): Diagnostic[] {
|
||||
return this.analyzedModules && this._structuralDiagnostics
|
||||
}
|
||||
|
||||
private get stubs(): GeneratedFile[] {
|
||||
return this._stubs || (this._stubs = this.generateStubs());
|
||||
}
|
||||
|
||||
private get stubFiles(): string[] {
|
||||
return this._stubFiles ||
|
||||
(this._stubFiles = this.stubs.reduce((files: string[], generatedFile) => {
|
||||
if (generatedFile.source || (generatedFile.stmts && generatedFile.stmts.length)) {
|
||||
return [...files, generatedFile.genFileUrl];
|
||||
}
|
||||
return files;
|
||||
}, []));
|
||||
}
|
||||
|
||||
private get programWithStubsHost(): ts.CompilerHost {
|
||||
return this._programWithStubsHost || (this._programWithStubsHost = createProgramWithStubsHost(
|
||||
this.stubs, this.tsProgram, this.host));
|
||||
}
|
||||
|
||||
private get programWithStubs(): ts.Program {
|
||||
return this._programWithStubs || (this._programWithStubs = this.createProgramWithStubs());
|
||||
}
|
||||
|
||||
private get generatedFiles(): GeneratedFile[] {
|
||||
return this._generatedFiles || (this._generatedFiles = this.generateFiles())
|
||||
}
|
||||
|
||||
private get typeChecker(): TypeChecker {
|
||||
return (this._typeChecker && !this._typeChecker.partialResults) ?
|
||||
this._typeChecker :
|
||||
(this._typeChecker = this.createTypeChecker());
|
||||
}
|
||||
|
||||
private get generatedFileDiagnostics(): Diagnostic[]|undefined {
|
||||
return this.generatedFiles && this._generatedFileDiagnostics !;
|
||||
}
|
||||
|
||||
private catchAnalysisError(e: any): NgAnalyzedModules {
|
||||
if (isSyntaxError(e)) {
|
||||
const parserErrors = getParseErrors(e);
|
||||
if (parserErrors && parserErrors.length) {
|
||||
this._structuralDiagnostics =
|
||||
parserErrors.map<Diagnostic>(e => ({
|
||||
message: e.contextualMessage(),
|
||||
category: DiagnosticCategory.Error,
|
||||
span: e.span
|
||||
}));
|
||||
} else {
|
||||
this._structuralDiagnostics = [{message: e.message, category: DiagnosticCategory.Error}];
|
||||
}
|
||||
this._analyzedModules = emptyModules;
|
||||
return emptyModules;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
private analyzeModules() {
|
||||
try {
|
||||
return this.compiler.analyzeModulesSync(this.srcNames);
|
||||
} catch (e) {
|
||||
return this.catchAnalysisError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private generateStubs() {
|
||||
return this.options.skipTemplateCodegen ? [] :
|
||||
this.options.generateCodeForLibraries === false ?
|
||||
this.compiler.emitAllStubs(this.analyzedModules) :
|
||||
this.compiler.emitPartialStubs(this.analyzedModules);
|
||||
}
|
||||
|
||||
private generateFiles() {
|
||||
try {
|
||||
// Always generate the files if requested to ensure we capture any diagnostic errors but only
|
||||
// keep the results if we are not skipping template code generation.
|
||||
const result = this.compiler.emitAllImpls(this.analyzedModules);
|
||||
return this.options.skipTemplateCodegen ? [] : result;
|
||||
} catch (e) {
|
||||
if (isSyntaxError(e)) {
|
||||
this._generatedFileDiagnostics = [{message: e.message, category: DiagnosticCategory.Error}];
|
||||
return [];
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private createTypeChecker(): TypeChecker {
|
||||
return new TypeChecker(
|
||||
this.tsProgram, this.options, this.host, this.aotCompilerHost, this.options,
|
||||
this.analyzedModules, this.generatedFiles);
|
||||
}
|
||||
|
||||
private createProgramWithStubs(): ts.Program {
|
||||
// If we are skipping code generation just use the original program.
|
||||
// Otherwise, create a new program that includes the stub files.
|
||||
return this.options.skipTemplateCodegen ?
|
||||
this.tsProgram :
|
||||
ts.createProgram(
|
||||
[...this.rootNames, ...this.stubFiles], this.options, this.programWithStubsHost);
|
||||
}
|
||||
}
|
||||
|
||||
export function createProgram(
|
||||
{rootNames, options, host, oldProgram}:
|
||||
{rootNames: string[], options: CompilerOptions, host: CompilerHost, oldProgram?: Program}):
|
||||
Program {
|
||||
return new AngularCompilerProgram(rootNames, options, host, oldProgram);
|
||||
}
|
||||
|
||||
function writeMetadata(
|
||||
emitFilePath: string, sourceFile: ts.SourceFile, collector: MetadataCollector,
|
||||
ngOptions: CompilerOptions) {
|
||||
if (/\.js$/.test(emitFilePath)) {
|
||||
const path = emitFilePath.replace(/\.js$/, '.metadata.json');
|
||||
|
||||
// Beginning with 2.1, TypeScript transforms the source tree before emitting it.
|
||||
// We need the original, unmodified, tree which might be several levels back
|
||||
// depending on the number of transforms performed. All SourceFile's prior to 2.1
|
||||
// will appear to be the original source since they didn't include an original field.
|
||||
let collectableFile = sourceFile;
|
||||
while ((collectableFile as any).original) {
|
||||
collectableFile = (collectableFile as any).original;
|
||||
}
|
||||
|
||||
const metadata = collector.getMetadata(collectableFile, !!ngOptions.strictMetadataEmit);
|
||||
if (metadata) {
|
||||
const metadataText = JSON.stringify([metadata]);
|
||||
writeFileSync(path, metadataText, {encoding: 'utf-8'});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createWriteFileCallback(
|
||||
emitFlags: EmitFlags, host: ts.CompilerHost, collector: MetadataCollector,
|
||||
ngOptions: CompilerOptions, emitMap: Map<string, string>) {
|
||||
const withMetadata =
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean,
|
||||
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
|
||||
const generatedFile = GENERATED_FILES.test(fileName);
|
||||
if (!generatedFile || data != '') {
|
||||
host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
||||
}
|
||||
if (!generatedFile && sourceFiles && sourceFiles.length == 1) {
|
||||
emitMap.set(sourceFiles[0].fileName, fileName);
|
||||
writeMetadata(fileName, sourceFiles[0], collector, ngOptions);
|
||||
}
|
||||
};
|
||||
const withoutMetadata =
|
||||
(fileName: string, data: string, writeByteOrderMark: boolean,
|
||||
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
|
||||
const generatedFile = GENERATED_FILES.test(fileName);
|
||||
if (!generatedFile || data != '') {
|
||||
host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
||||
}
|
||||
if (!generatedFile && sourceFiles && sourceFiles.length == 1) {
|
||||
emitMap.set(sourceFiles[0].fileName, fileName);
|
||||
}
|
||||
};
|
||||
return (emitFlags & EmitFlags.Metadata) != 0 ? withMetadata : withoutMetadata;
|
||||
}
|
||||
|
||||
function getNgOptionDiagnostics(options: CompilerOptions): Diagnostic[] {
|
||||
if (options.annotationsAs) {
|
||||
switch (options.annotationsAs) {
|
||||
case 'decorators':
|
||||
case 'static fields':
|
||||
break;
|
||||
default:
|
||||
return [{
|
||||
message:
|
||||
'Angular compiler options "annotationsAs" only supports "static fields" and "decorators"',
|
||||
category: DiagnosticCategory.Error
|
||||
}];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function createProgramWithStubsHost(
|
||||
generatedFiles: GeneratedFile[], originalProgram: ts.Program,
|
||||
originalHost: ts.CompilerHost): ts.CompilerHost {
|
||||
interface FileData {
|
||||
g: GeneratedFile
|
||||
s?: ts.SourceFile;
|
||||
}
|
||||
return new class implements ts.CompilerHost {
|
||||
private generatedFiles: Map<string, FileData>;
|
||||
writeFile: ts.WriteFileCallback;
|
||||
getCancellationToken: () => ts.CancellationToken;
|
||||
getDefaultLibLocation: () => string;
|
||||
trace: (s: string) => void;
|
||||
getDirectories: (path: string) => string[];
|
||||
directoryExists: (directoryName: string) => boolean;
|
||||
constructor() {
|
||||
this.generatedFiles =
|
||||
new Map(generatedFiles.filter(g => g.source || (g.stmts && g.stmts.length))
|
||||
.map<[string, FileData]>(g => [g.genFileUrl, {g}]));
|
||||
this.writeFile = originalHost.writeFile;
|
||||
if (originalHost.getDirectories) {
|
||||
this.getDirectories = path => originalHost.getDirectories !(path);
|
||||
}
|
||||
if (originalHost.directoryExists) {
|
||||
this.directoryExists = directoryName => originalHost.directoryExists !(directoryName);
|
||||
}
|
||||
if (originalHost.getCancellationToken) {
|
||||
this.getCancellationToken = () => originalHost.getCancellationToken !();
|
||||
}
|
||||
if (originalHost.getDefaultLibLocation) {
|
||||
this.getDefaultLibLocation = () => originalHost.getDefaultLibLocation !();
|
||||
}
|
||||
if (originalHost.trace) {
|
||||
this.trace = s => originalHost.trace !(s);
|
||||
}
|
||||
}
|
||||
getSourceFile(
|
||||
fileName: string, languageVersion: ts.ScriptTarget,
|
||||
onError?: ((message: string) => void)|undefined): ts.SourceFile {
|
||||
const data = this.generatedFiles.get(fileName);
|
||||
if (data) {
|
||||
return data.s || (data.s = ts.createSourceFile(
|
||||
fileName, data.g.source || toTypeScript(data.g), languageVersion));
|
||||
}
|
||||
return originalProgram.getSourceFile(fileName) ||
|
||||
originalHost.getSourceFile(fileName, languageVersion, onError);
|
||||
}
|
||||
readFile(fileName: string): string {
|
||||
const data = this.generatedFiles.get(fileName);
|
||||
if (data) {
|
||||
return data.g.source || toTypeScript(data.g);
|
||||
}
|
||||
return originalHost.readFile(fileName);
|
||||
}
|
||||
getDefaultLibFileName = (options: ts.CompilerOptions) =>
|
||||
originalHost.getDefaultLibFileName(options);
|
||||
getCurrentDirectory = () => originalHost.getCurrentDirectory();
|
||||
getCanonicalFileName = (fileName: string) => originalHost.getCanonicalFileName(fileName);
|
||||
useCaseSensitiveFileNames = () => originalHost.useCaseSensitiveFileNames();
|
||||
getNewLine = () => originalHost.getNewLine();
|
||||
fileExists = (fileName: string) =>
|
||||
this.generatedFiles.has(fileName) || originalHost.fileExists(fileName);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user