2017-08-30 09:37:21 -04: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a private API for @ngtools/webpack. This API should be stable for NG 5.
|
|
|
|
*
|
|
|
|
* It contains copies of the interfaces needed and wrapper functions to ensure that
|
|
|
|
* they are not broken accidentally.
|
|
|
|
*
|
|
|
|
* Once the ngc api is public and stable, this can be removed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {ParseSourceSpan} from '@angular/compiler';
|
|
|
|
import * as ts from 'typescript';
|
|
|
|
|
|
|
|
import {formatDiagnostics as formatDiagnosticsOrig} from './perform_compile';
|
2017-09-29 18:02:11 -04:00
|
|
|
import {Program as ProgramOrig} from './transformers/api';
|
2017-08-30 09:37:21 -04:00
|
|
|
import {createCompilerHost as createCompilerOrig} from './transformers/compiler_host';
|
|
|
|
import {createProgram as createProgramOrig} from './transformers/program';
|
|
|
|
|
2017-09-29 18:02:11 -04:00
|
|
|
|
2017-08-30 09:37:21 -04:00
|
|
|
// Interfaces from ./transformers/api;
|
|
|
|
export interface Diagnostic {
|
|
|
|
messageText: string;
|
|
|
|
span?: ParseSourceSpan;
|
|
|
|
category: ts.DiagnosticCategory;
|
|
|
|
code: number;
|
|
|
|
source: 'angular';
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CompilerOptions extends ts.CompilerOptions {
|
|
|
|
basePath?: string;
|
|
|
|
skipMetadataEmit?: boolean;
|
|
|
|
strictMetadataEmit?: boolean;
|
|
|
|
skipTemplateCodegen?: boolean;
|
|
|
|
flatModuleOutFile?: string;
|
|
|
|
flatModuleId?: string;
|
|
|
|
generateCodeForLibraries?: boolean;
|
|
|
|
annotateForClosureCompiler?: boolean;
|
|
|
|
annotationsAs?: 'decorators'|'static fields';
|
|
|
|
trace?: boolean;
|
|
|
|
enableLegacyTemplate?: boolean;
|
|
|
|
disableExpressionLowering?: boolean;
|
|
|
|
i18nOutLocale?: string;
|
|
|
|
i18nOutFormat?: string;
|
|
|
|
i18nOutFile?: string;
|
|
|
|
i18nInFormat?: string;
|
|
|
|
i18nInLocale?: string;
|
|
|
|
i18nInFile?: string;
|
|
|
|
i18nInMissingTranslations?: 'error'|'warning'|'ignore';
|
|
|
|
preserveWhitespaces?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CompilerHost extends ts.CompilerHost {
|
2017-09-12 12:40:28 -04:00
|
|
|
moduleNameToFileName?(moduleName: string, containingFile?: string): string|null;
|
|
|
|
fileNameToModuleName?(importedFilePath: string, containingFilePath: string): string;
|
|
|
|
resourceNameToFileName?(resourceName: string, containingFilePath: string): string|null;
|
|
|
|
toSummaryFileName?(fileName: string, referringSrcFileName: string): string;
|
|
|
|
fromSummaryFileName?(fileName: string, referringLibFileName: string): string;
|
2017-08-30 09:37:21 -04:00
|
|
|
readResource?(fileName: string): Promise<string>|string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum EmitFlags {
|
|
|
|
DTS = 1 << 0,
|
|
|
|
JS = 1 << 1,
|
2017-09-25 15:37:00 -04:00
|
|
|
Metadata = 1 << 2,
|
|
|
|
I18nBundle = 1 << 3,
|
2017-09-19 14:43:34 -04:00
|
|
|
Codegen = 1 << 4,
|
2017-08-30 09:37:21 -04:00
|
|
|
|
2017-09-25 15:37:00 -04:00
|
|
|
Default = DTS | JS | Codegen,
|
|
|
|
All = DTS | JS | Metadata | I18nBundle | Codegen,
|
2017-08-30 09:37:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CustomTransformers {
|
|
|
|
beforeTs?: ts.TransformerFactory<ts.SourceFile>[];
|
|
|
|
afterTs?: ts.TransformerFactory<ts.SourceFile>[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TsEmitArguments {
|
|
|
|
program: ts.Program;
|
|
|
|
host: CompilerHost;
|
|
|
|
options: CompilerOptions;
|
|
|
|
targetSourceFile?: ts.SourceFile;
|
|
|
|
writeFile?: ts.WriteFileCallback;
|
|
|
|
cancellationToken?: ts.CancellationToken;
|
|
|
|
emitOnlyDtsFiles?: boolean;
|
|
|
|
customTransformers?: ts.CustomTransformers;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TsEmitCallback { (args: TsEmitArguments): ts.EmitResult; }
|
|
|
|
|
|
|
|
export interface Program {
|
|
|
|
getTsProgram(): ts.Program;
|
|
|
|
getTsOptionDiagnostics(cancellationToken?: ts.CancellationToken): ts.Diagnostic[];
|
|
|
|
getNgOptionDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
|
|
|
|
getTsSyntacticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
|
|
|
ts.Diagnostic[];
|
|
|
|
getNgStructuralDiagnostics(cancellationToken?: ts.CancellationToken): Diagnostic[];
|
|
|
|
getTsSemanticDiagnostics(sourceFile?: ts.SourceFile, cancellationToken?: ts.CancellationToken):
|
|
|
|
ts.Diagnostic[];
|
2017-10-12 13:32:21 -04:00
|
|
|
getNgSemanticDiagnostics(genFile?: any, cancellationToken?: ts.CancellationToken): Diagnostic[];
|
2017-08-30 09:37:21 -04:00
|
|
|
loadNgStructureAsync(): Promise<void>;
|
|
|
|
emit({emitFlags, cancellationToken, customTransformers, emitCallback}: {
|
|
|
|
emitFlags?: EmitFlags,
|
|
|
|
cancellationToken?: ts.CancellationToken,
|
|
|
|
customTransformers?: CustomTransformers,
|
|
|
|
emitCallback?: TsEmitCallback
|
|
|
|
}): ts.EmitResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapper for createProgram.
|
|
|
|
export function createProgram(
|
|
|
|
{rootNames, options, host, oldProgram}:
|
|
|
|
{rootNames: string[], options: CompilerOptions, host: CompilerHost, oldProgram?: Program}):
|
|
|
|
Program {
|
2017-09-29 18:02:11 -04:00
|
|
|
return createProgramOrig({rootNames, options, host, oldProgram: oldProgram as ProgramOrig});
|
2017-08-30 09:37:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapper for createCompilerHost.
|
|
|
|
export function createCompilerHost(
|
|
|
|
{options, tsHost = ts.createCompilerHost(options, true)}:
|
|
|
|
{options: CompilerOptions, tsHost?: ts.CompilerHost}): CompilerHost {
|
|
|
|
return createCompilerOrig({options, tsHost});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapper for formatDiagnostics.
|
|
|
|
export type Diagnostics = Array<ts.Diagnostic|Diagnostic>;
|
|
|
|
export function formatDiagnostics(options: CompilerOptions, diags: Diagnostics): string {
|
|
|
|
return formatDiagnosticsOrig(options, diags);
|
|
|
|
}
|