@angular/compiler-cli
Advanced tools
Comparing version 5.0.0-beta.3 to 5.0.0-beta.4
@@ -20,3 +20,3 @@ /** | ||
export * from './src/transformers/entry_points'; | ||
export { performCompilation } from './src/perform-compile'; | ||
export { performCompilation, readConfiguration, formatDiagnostics, calcProjectFileAndBasePath, createNgCompilerOptions } from './src/perform-compile'; | ||
export { NgTools_InternalApi_NG_2 as __NGTOOLS_PRIVATE_API_2 } from './src/ngtools_api'; |
@@ -42,2 +42,6 @@ "use strict"; | ||
exports.performCompilation = perform_compile_1.performCompilation; | ||
exports.readConfiguration = perform_compile_1.readConfiguration; | ||
exports.formatDiagnostics = perform_compile_1.formatDiagnostics; | ||
exports.calcProjectFileAndBasePath = perform_compile_1.calcProjectFileAndBasePath; | ||
exports.createNgCompilerOptions = perform_compile_1.createNgCompilerOptions; | ||
// TODO(hansl): moving to Angular 4 need to update this API. | ||
@@ -44,0 +48,0 @@ var ngtools_api_1 = require("./src/ngtools_api"); |
{ | ||
"name": "@angular/compiler-cli", | ||
"version": "5.0.0-beta.3", | ||
"version": "5.0.0-beta.4", | ||
"description": "Angular - the compiler CLI for Node.js", | ||
@@ -12,10 +12,11 @@ "main": "index.js", | ||
"dependencies": { | ||
"@angular/tsc-wrapped": "5.0.0-beta.3", | ||
"@angular/tsc-wrapped": "5.0.0-beta.4", | ||
"reflect-metadata": "^0.1.2", | ||
"minimist": "^1.2.0" | ||
"minimist": "^1.2.0", | ||
"tsickle": "^0.23.4" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^2.0.2", | ||
"@angular/compiler": "5.0.0-beta.3", | ||
"@angular/core": "5.0.0-beta.3" | ||
"@angular/compiler": "5.0.0-beta.4", | ||
"@angular/core": "5.0.0-beta.4" | ||
}, | ||
@@ -22,0 +23,0 @@ "repository": { |
@@ -156,3 +156,3 @@ "use strict"; | ||
message: diagnosticMessageToString(diagnostic.messageText), | ||
category: diagnosticCategoryConverter(diagnostic.category), span: span | ||
category: diagnostic.category, span: span | ||
}); | ||
@@ -179,6 +179,2 @@ } | ||
} | ||
function diagnosticCategoryConverter(kind) { | ||
// The diagnostics kind matches ts.DiagnosticCategory. Review this code if this changes. | ||
return kind; | ||
} | ||
function createFactoryInfo(emitter, file) { | ||
@@ -185,0 +181,0 @@ var _a = emitter.emitStatementsAndContext(file.srcFileUrl, file.genFileUrl, file.stmts), sourceText = _a.sourceText, context = _a.context; |
@@ -50,3 +50,3 @@ "use strict"; | ||
type: type || info.query.getBuiltinType(symbols_1.BuiltinType.Any), | ||
get definition() { return getDefintionOf(info, reference); } | ||
get definition() { return getDefinitionOf(info, reference); } | ||
}); | ||
@@ -77,3 +77,3 @@ }; | ||
} | ||
function getDefintionOf(info, ast) { | ||
function getDefinitionOf(info, ast) { | ||
if (info.fileName) { | ||
@@ -119,3 +119,3 @@ var templateOffset = info.offset; | ||
name: name_1, | ||
kind: 'variable', type: type, get definition() { return getDefintionOf(info, variable); } | ||
kind: 'variable', type: type, get definition() { return getDefinitionOf(info, variable); } | ||
}); | ||
@@ -122,0 +122,0 @@ }; |
import 'reflect-metadata'; | ||
export declare function main(args: any, consoleError?: (s: string) => void): Promise<number>; | ||
export declare function main(args: string[], consoleError?: (s: string) => void): Promise<number>; | ||
export declare function mainSync(args: string[], consoleError?: (s: string) => void): number; |
@@ -5,34 +5,90 @@ #!/usr/bin/env node | ||
require("reflect-metadata"); | ||
var ts = require("typescript"); | ||
var tsc = require("@angular/tsc-wrapped"); | ||
var perform_compile_1 = require("./perform-compile"); | ||
var compiler_1 = require("@angular/compiler"); | ||
var codegen_1 = require("./codegen"); | ||
function codegen(ngOptions, cliOptions, program, host) { | ||
if (ngOptions.enableSummariesForJit === undefined) { | ||
// default to false | ||
ngOptions.enableSummariesForJit = false; | ||
function main(args, consoleError) { | ||
if (consoleError === void 0) { consoleError = console.error; } | ||
var parsedArgs = require('minimist')(args); | ||
var _a = readCommandLineAndConfiguration(parsedArgs), rootNames = _a.rootNames, options = _a.options, configErrors = _a.errors; | ||
if (configErrors.length) { | ||
return Promise.resolve(reportErrorsAndExit(options, configErrors, consoleError)); | ||
} | ||
return codegen_1.CodeGenerator.create(ngOptions, cliOptions, program, host).codegen(); | ||
if (options.disableTransformerPipeline) { | ||
return disabledTransformerPipelineNgcMain(parsedArgs, consoleError); | ||
} | ||
var compileDiags = perform_compile_1.performCompilation(rootNames, options).diagnostics; | ||
return Promise.resolve(reportErrorsAndExit(options, compileDiags, consoleError)); | ||
} | ||
function main(args, consoleError) { | ||
exports.main = main; | ||
function mainSync(args, consoleError) { | ||
if (consoleError === void 0) { consoleError = console.error; } | ||
var parsedArgs = require('minimist')(args); | ||
var _a = readCommandLineAndConfiguration(parsedArgs), rootNames = _a.rootNames, options = _a.options, configErrors = _a.errors; | ||
if (configErrors.length) { | ||
return reportErrorsAndExit(options, configErrors, consoleError); | ||
} | ||
var compileDiags = perform_compile_1.performCompilation(rootNames, options).diagnostics; | ||
return reportErrorsAndExit(options, compileDiags, consoleError); | ||
} | ||
exports.mainSync = mainSync; | ||
function readCommandLineAndConfiguration(args) { | ||
var project = args.p || args.project || '.'; | ||
var allDiagnostics = []; | ||
var config = perform_compile_1.readConfiguration(project); | ||
var options = mergeCommandLineParams(args, config.options); | ||
return { rootNames: config.rootNames, options: options, errors: config.errors }; | ||
} | ||
function reportErrorsAndExit(options, allDiagnostics, consoleError) { | ||
if (consoleError === void 0) { consoleError = console.error; } | ||
var exitCode = allDiagnostics.some(function (d) { return d.category === ts.DiagnosticCategory.Error; }) ? 1 : 0; | ||
if (allDiagnostics.length) { | ||
consoleError(perform_compile_1.formatDiagnostics(options, allDiagnostics)); | ||
} | ||
return exitCode; | ||
} | ||
function mergeCommandLineParams(cliArgs, options) { | ||
// TODO: also merge in tsc command line parameters by calling | ||
// ts.readCommandLine. | ||
if (cliArgs.i18nFile) | ||
options.i18nInFile = cliArgs.i18nFile; | ||
if (cliArgs.i18nFormat) | ||
options.i18nInFormat = cliArgs.i18nFormat; | ||
if (cliArgs.locale) | ||
options.i18nInLocale = cliArgs.locale; | ||
var mt = cliArgs.missingTranslation; | ||
if (mt === 'error' || mt === 'warning' || mt === 'ignore') { | ||
options.i18nInMissingTranslations = mt; | ||
} | ||
return options; | ||
} | ||
function disabledTransformerPipelineNgcMain(args, consoleError) { | ||
if (consoleError === void 0) { consoleError = console.error; } | ||
var cliOptions = new tsc.NgcCliOptions(args); | ||
return tsc.main(project, cliOptions, codegen).then(function () { return 0; }).catch(function (e) { | ||
var project = args.p || args.project || '.'; | ||
return tsc.main(project, cliOptions, disabledTransformerPipelineCodegen) | ||
.then(function () { return 0; }) | ||
.catch(function (e) { | ||
if (e instanceof tsc.UserError || compiler_1.isSyntaxError(e)) { | ||
consoleError(e.message); | ||
return Promise.resolve(1); | ||
} | ||
else { | ||
consoleError(e.stack); | ||
consoleError('Compilation failed'); | ||
return Promise.resolve(1); | ||
} | ||
return Promise.resolve(1); | ||
}); | ||
} | ||
exports.main = main; | ||
function disabledTransformerPipelineCodegen(ngOptions, cliOptions, program, host) { | ||
if (ngOptions.enableSummariesForJit === undefined) { | ||
// default to false | ||
ngOptions.enableSummariesForJit = false; | ||
} | ||
return codegen_1.CodeGenerator.create(ngOptions, cliOptions, program, host).codegen(); | ||
} | ||
// CLI entry point | ||
if (require.main === module) { | ||
var args = require('minimist')(process.argv.slice(2)); | ||
main(args).then(function (exitCode) { return process.exit(exitCode); }); | ||
var args = process.argv.slice(2); | ||
main(args).then(function (exitCode) { return process.exitCode = exitCode; }); | ||
} | ||
//# sourceMappingURL=main.js.map |
import * as ts from 'typescript'; | ||
import * as api from './transformers/api'; | ||
export declare type Diagnostics = ts.Diagnostic[] | api.Diagnostic[]; | ||
/** | ||
* Throw a syntax error exception with a message formatted for output | ||
* if the args parameter contains diagnostics errors. | ||
* | ||
* @param cwd The directory to report error as relative to. | ||
* @param args A list of potentially empty diagnostic errors. | ||
*/ | ||
export declare function throwOnDiagnostics(cwd: string, ...args: Diagnostics[]): void; | ||
export declare function readConfiguration(project: string, basePath: string, checkFunc?: (cwd: string, ...args: any[]) => void, existingOptions?: ts.CompilerOptions): { | ||
parsed: ts.ParsedCommandLine; | ||
ngOptions: any; | ||
export declare type Diagnostics = Array<ts.Diagnostic | api.Diagnostic>; | ||
export declare function formatDiagnostics(options: api.CompilerOptions, diags: Diagnostics): string; | ||
export interface ParsedConfiguration { | ||
options: api.CompilerOptions; | ||
rootNames: string[]; | ||
errors: Diagnostics; | ||
} | ||
export declare function calcProjectFileAndBasePath(project: string): { | ||
projectFile: string; | ||
basePath: string; | ||
}; | ||
export declare function performCompilation(basePath: string, files: string[], options: ts.CompilerOptions, ngOptions: any, consoleError?: (s: string) => void, checkFunc?: (cwd: string, ...args: any[]) => void, tsCompilerHost?: ts.CompilerHost): 0 | 1; | ||
export declare function createNgCompilerOptions(basePath: string, config: any, tsOptions: ts.CompilerOptions): api.CompilerOptions; | ||
export declare function readConfiguration(project: string, existingOptions?: ts.CompilerOptions): ParsedConfiguration; | ||
export declare function performCompilation(rootNames: string[], options: api.CompilerOptions, host?: api.CompilerHost, oldProgram?: api.Program): { | ||
program?: api.Program; | ||
emitResult?: api.EmitResult; | ||
diagnostics: Diagnostics; | ||
}; |
@@ -19,3 +19,2 @@ "use strict"; | ||
var compiler_1 = require("@angular/compiler"); | ||
var tsc_wrapped_1 = require("@angular/tsc-wrapped"); | ||
var fs = require("fs"); | ||
@@ -27,18 +26,19 @@ var path = require("path"); | ||
var TS_EXT = /\.ts$/; | ||
function isTsDiagnostics(diagnostics) { | ||
return diagnostics && diagnostics[0] && (diagnostics[0].file || diagnostics[0].messageText); | ||
function isTsDiagnostic(diagnostic) { | ||
return diagnostic && (diagnostic.file || diagnostic.messageText); | ||
} | ||
function formatDiagnostics(cwd, diags) { | ||
function formatDiagnostics(options, diags) { | ||
if (diags && diags.length) { | ||
if (isTsDiagnostics(diags)) { | ||
return ts.formatDiagnostics(diags, { | ||
getCurrentDirectory: function () { return cwd; }, | ||
getCanonicalFileName: function (fileName) { return fileName; }, | ||
getNewLine: function () { return ts.sys.newLine; } | ||
}); | ||
} | ||
else { | ||
return diags | ||
.map(function (d) { | ||
var res = api.DiagnosticCategory[d.category]; | ||
var tsFormatHost_1 = { | ||
getCurrentDirectory: function () { return options.basePath || process.cwd(); }, | ||
getCanonicalFileName: function (fileName) { return fileName; }, | ||
getNewLine: function () { return ts.sys.newLine; } | ||
}; | ||
return diags | ||
.map(function (d) { | ||
if (isTsDiagnostic(d)) { | ||
return ts.formatDiagnostics([d], tsFormatHost_1); | ||
} | ||
else { | ||
var res = ts.DiagnosticCategory[d.category]; | ||
if (d.span) { | ||
@@ -55,5 +55,5 @@ res += | ||
return res; | ||
}) | ||
.join(); | ||
} | ||
} | ||
}) | ||
.join(); | ||
} | ||
@@ -63,124 +63,98 @@ else | ||
} | ||
/** | ||
* Throw a syntax error exception with a message formatted for output | ||
* if the args parameter contains diagnostics errors. | ||
* | ||
* @param cwd The directory to report error as relative to. | ||
* @param args A list of potentially empty diagnostic errors. | ||
*/ | ||
function throwOnDiagnostics(cwd) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
if (args.some(function (diags) { return !!(diags && diags[0]); })) { | ||
throw compiler_1.syntaxError(args.map(function (diags) { | ||
if (diags && diags[0]) { | ||
return formatDiagnostics(cwd, diags); | ||
} | ||
}) | ||
.filter(function (message) { return !!message; }) | ||
.join('')); | ||
} | ||
exports.formatDiagnostics = formatDiagnostics; | ||
function calcProjectFileAndBasePath(project) { | ||
var projectIsDir = fs.lstatSync(project).isDirectory(); | ||
var projectFile = projectIsDir ? path.join(project, 'tsconfig.json') : project; | ||
var projectDir = projectIsDir ? project : path.dirname(project); | ||
var basePath = path.resolve(process.cwd(), projectDir); | ||
return { projectFile: projectFile, basePath: basePath }; | ||
} | ||
exports.throwOnDiagnostics = throwOnDiagnostics; | ||
function syntheticError(message) { | ||
return { | ||
file: null, | ||
start: 0, | ||
length: 0, | ||
messageText: message, | ||
category: ts.DiagnosticCategory.Error, | ||
code: 0 | ||
}; | ||
exports.calcProjectFileAndBasePath = calcProjectFileAndBasePath; | ||
function createNgCompilerOptions(basePath, config, tsOptions) { | ||
return __assign({}, tsOptions, config.angularCompilerOptions, { genDir: basePath, basePath: basePath }); | ||
} | ||
function readConfiguration(project, basePath, checkFunc, existingOptions) { | ||
if (checkFunc === void 0) { checkFunc = throwOnDiagnostics; } | ||
// Allow a directory containing tsconfig.json as the project value | ||
// Note, TS@next returns an empty array, while earlier versions throw | ||
var projectFile = fs.lstatSync(project).isDirectory() ? path.join(project, 'tsconfig.json') : project; | ||
var _a = ts.readConfigFile(projectFile, ts.sys.readFile), config = _a.config, error = _a.error; | ||
if (error) | ||
checkFunc(basePath, [error]); | ||
var parseConfigHost = { | ||
useCaseSensitiveFileNames: true, | ||
fileExists: fs.existsSync, | ||
readDirectory: ts.sys.readDirectory, | ||
readFile: ts.sys.readFile | ||
}; | ||
var parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, basePath, existingOptions); | ||
checkFunc(basePath, parsed.errors); | ||
// Default codegen goes to the current directory | ||
// Parsed options are already converted to absolute paths | ||
var ngOptions = config.angularCompilerOptions || {}; | ||
// Ignore the genDir option | ||
ngOptions.genDir = basePath; | ||
return { parsed: parsed, ngOptions: ngOptions }; | ||
} | ||
exports.readConfiguration = readConfiguration; | ||
function getProjectDirectory(project) { | ||
var isFile; | ||
exports.createNgCompilerOptions = createNgCompilerOptions; | ||
function readConfiguration(project, existingOptions) { | ||
try { | ||
isFile = fs.lstatSync(project).isFile(); | ||
var _a = calcProjectFileAndBasePath(project), projectFile = _a.projectFile, basePath = _a.basePath; | ||
var _b = ts.readConfigFile(projectFile, ts.sys.readFile), config = _b.config, error = _b.error; | ||
if (error) { | ||
return { errors: [error], rootNames: [], options: {} }; | ||
} | ||
var parseConfigHost = { | ||
useCaseSensitiveFileNames: true, | ||
fileExists: fs.existsSync, | ||
readDirectory: ts.sys.readDirectory, | ||
readFile: ts.sys.readFile | ||
}; | ||
var parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, basePath, existingOptions); | ||
var rootNames = parsed.fileNames.map(function (f) { return path.normalize(f); }); | ||
var options = createNgCompilerOptions(basePath, config, parsed.options); | ||
return { rootNames: rootNames, options: options, errors: parsed.errors }; | ||
} | ||
catch (e) { | ||
// Project doesn't exist. Assume it is a file has an extension. This case happens | ||
// when the project file is passed to set basePath but no tsconfig.json file exists. | ||
// It is used in tests to ensure that the options can be passed in without there being | ||
// an actual config file. | ||
isFile = path.extname(project) !== ''; | ||
var errors = [{ | ||
category: ts.DiagnosticCategory.Error, | ||
message: e.stack, | ||
}]; | ||
return { errors: errors, rootNames: [], options: {} }; | ||
} | ||
// If project refers to a file, the project directory is the file's parent directory | ||
// otherwise project is the project directory. | ||
return isFile ? path.dirname(project) : project; | ||
} | ||
function performCompilation(basePath, files, options, ngOptions, consoleError, checkFunc, tsCompilerHost) { | ||
if (consoleError === void 0) { consoleError = console.error; } | ||
if (checkFunc === void 0) { checkFunc = throwOnDiagnostics; } | ||
exports.readConfiguration = readConfiguration; | ||
function performCompilation(rootNames, options, host, oldProgram) { | ||
var _a = ts.version.split('.'), major = _a[0], minor = _a[1]; | ||
if (Number(major) < 2 || (Number(major) === 2 && Number(minor) < 3)) { | ||
throw new Error('Must use TypeScript > 2.3 to have transformer support'); | ||
} | ||
var allDiagnostics = []; | ||
function checkDiagnostics(diags) { | ||
if (diags) { | ||
allDiagnostics.push.apply(allDiagnostics, diags); | ||
return diags.every(function (d) { return d.category !== ts.DiagnosticCategory.Error; }); | ||
} | ||
return true; | ||
} | ||
var program; | ||
var emitResult; | ||
try { | ||
ngOptions.basePath = basePath; | ||
ngOptions.genDir = basePath; | ||
var host = tsCompilerHost || ts.createCompilerHost(options, true); | ||
host.realpath = function (p) { return p; }; | ||
var rootFileNames_1 = files.map(function (f) { return path.normalize(f); }); | ||
var addGeneratedFileName = function (fileName) { | ||
if (fileName.startsWith(basePath) && TS_EXT.exec(fileName)) { | ||
rootFileNames_1.push(fileName); | ||
} | ||
}; | ||
if (ngOptions.flatModuleOutFile && !ngOptions.skipMetadataEmit) { | ||
var _a = tsc_wrapped_1.createBundleIndexHost(ngOptions, rootFileNames_1, host), bundleHost = _a.host, indexName = _a.indexName, errors = _a.errors; | ||
if (errors) | ||
checkFunc(basePath, errors); | ||
if (indexName) | ||
addGeneratedFileName(indexName); | ||
host = bundleHost; | ||
if (!host) { | ||
host = ng.createNgCompilerHost({ options: options }); | ||
} | ||
var ngHostOptions = __assign({}, options, ngOptions); | ||
var ngHost = ng.createHost({ tsHost: host, options: ngHostOptions }); | ||
var ngProgram = ng.createProgram({ rootNames: rootFileNames_1, host: ngHost, options: ngHostOptions }); | ||
program = ng.createProgram({ rootNames: rootNames, host: host, options: options, oldProgram: oldProgram }); | ||
var shouldEmit = true; | ||
// Check parameter diagnostics | ||
checkFunc(basePath, ngProgram.getTsOptionDiagnostics(), ngProgram.getNgOptionDiagnostics()); | ||
shouldEmit = shouldEmit && checkDiagnostics(program.getTsOptionDiagnostics().concat(program.getNgOptionDiagnostics())); | ||
// Check syntactic diagnostics | ||
checkFunc(basePath, ngProgram.getTsSyntacticDiagnostics()); | ||
shouldEmit = shouldEmit && checkDiagnostics(program.getTsSyntacticDiagnostics()); | ||
// Check TypeScript semantic and Angular structure diagnostics | ||
checkFunc(basePath, ngProgram.getTsSemanticDiagnostics(), ngProgram.getNgStructuralDiagnostics()); | ||
shouldEmit = | ||
shouldEmit && | ||
checkDiagnostics(program.getTsSemanticDiagnostics().concat(program.getNgStructuralDiagnostics())); | ||
// Check Angular semantic diagnostics | ||
checkFunc(basePath, ngProgram.getNgSemanticDiagnostics()); | ||
ngProgram.emit({ | ||
emitFlags: api.EmitFlags.Default | | ||
((ngOptions.skipMetadataEmit || ngOptions.flatModuleOutFile) ? 0 : api.EmitFlags.Metadata) | ||
}); | ||
shouldEmit = shouldEmit && checkDiagnostics(program.getNgSemanticDiagnostics()); | ||
if (shouldEmit) { | ||
var emitResult_1 = program.emit({ | ||
emitFlags: api.EmitFlags.Default | | ||
((options.skipMetadataEmit || options.flatModuleOutFile) ? 0 : api.EmitFlags.Metadata) | ||
}); | ||
allDiagnostics.push.apply(allDiagnostics, emitResult_1.diagnostics); | ||
} | ||
} | ||
catch (e) { | ||
var errMsg = void 0; | ||
if (compiler_1.isSyntaxError(e)) { | ||
console.error(e.message); | ||
consoleError(e.message); | ||
return 1; | ||
// don't report the stack for syntax errors as they are well known errors. | ||
errMsg = e.message; | ||
} | ||
throw e; | ||
else { | ||
errMsg = e.stack; | ||
} | ||
allDiagnostics.push({ | ||
category: ts.DiagnosticCategory.Error, | ||
message: errMsg, | ||
}); | ||
} | ||
return 0; | ||
return { program: program, emitResult: emitResult, diagnostics: allDiagnostics }; | ||
} | ||
exports.performCompilation = performCompilation; | ||
//# sourceMappingURL=perform-compile.js.map |
@@ -10,11 +10,6 @@ /** | ||
import * as ts from 'typescript'; | ||
export declare enum DiagnosticCategory { | ||
Warning = 0, | ||
Error = 1, | ||
Message = 2, | ||
} | ||
export interface Diagnostic { | ||
message: string; | ||
span?: ParseSourceSpan; | ||
category: DiagnosticCategory; | ||
category: ts.DiagnosticCategory; | ||
} | ||
@@ -35,2 +30,11 @@ export interface CompilerOptions extends ts.CompilerOptions { | ||
disableExpressionLowering?: boolean; | ||
expectedOut?: string[]; | ||
i18nOutLocale?: string; | ||
i18nOutFormat?: string; | ||
i18nOutFile?: string; | ||
i18nInFormat?: string; | ||
i18nInLocale?: string; | ||
i18nInFile?: string; | ||
i18nInMissingTranslations?: 'error' | 'warning' | 'ignore'; | ||
preserveWhitespaces?: boolean; | ||
} | ||
@@ -73,2 +77,11 @@ export interface ModuleFilenameResolver { | ||
} | ||
export interface EmitResult extends ts.EmitResult { | ||
modulesManifest: { | ||
modules: string[]; | ||
fileNames: string[]; | ||
}; | ||
externs: { | ||
[fileName: string]: string; | ||
}; | ||
} | ||
export interface Program { | ||
@@ -82,3 +95,3 @@ /** | ||
/** | ||
* Retreive options diagnostics for the TypeScript options used to create the program. This is | ||
* Retrieve options diagnostics for the TypeScript options used to create the program. This is | ||
* faster than calling `getTsProgram().getOptionsDiagnostics()` since it does not need to | ||
@@ -93,3 +106,3 @@ * collect Angular structural information to produce the errors. | ||
/** | ||
* Retrive the syntax diagnostics from TypeScript. This is faster than calling | ||
* Retrieve the syntax diagnostics from TypeScript. This is faster than calling | ||
* `getTsProgram().getSyntacticDiagnostics()` since it does not need to collect Angular structural | ||
@@ -112,3 +125,3 @@ * information to produce the errors. | ||
/** | ||
* Retreive the semantic diagnostics from TypeScript. This is equivilent to calling | ||
* Retrieve the semantic diagnostics from TypeScript. This is equivilent to calling | ||
* `getTsProgram().getSemanticDiagnostics()` directly and is included for completeness. | ||
@@ -146,3 +159,3 @@ */ | ||
cancellationToken?: ts.CancellationToken; | ||
}): void; | ||
}): EmitResult; | ||
} |
@@ -10,8 +10,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var DiagnosticCategory; | ||
(function (DiagnosticCategory) { | ||
DiagnosticCategory[DiagnosticCategory["Warning"] = 0] = "Warning"; | ||
DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error"; | ||
DiagnosticCategory[DiagnosticCategory["Message"] = 2] = "Message"; | ||
})(DiagnosticCategory = exports.DiagnosticCategory || (exports.DiagnosticCategory = {})); | ||
var EmitFlags; | ||
@@ -18,0 +12,0 @@ (function (EmitFlags) { |
@@ -13,5 +13,5 @@ /** | ||
export { createModuleFilenameResolver }; | ||
export declare function createHost({tsHost, options}: { | ||
tsHost: ts.CompilerHost; | ||
export declare function createNgCompilerHost({options, tsHost}: { | ||
options: CompilerOptions; | ||
tsHost?: ts.CompilerHost; | ||
}): CompilerHost; |
@@ -10,2 +10,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var module_filename_resolver_1 = require("./module_filename_resolver"); | ||
@@ -15,4 +16,4 @@ exports.createModuleFilenameResolver = module_filename_resolver_1.createModuleFilenameResolver; | ||
exports.createProgram = program_1.createProgram; | ||
function createHost(_a) { | ||
var tsHost = _a.tsHost, options = _a.options; | ||
function createNgCompilerHost(_a) { | ||
var options = _a.options, _b = _a.tsHost, tsHost = _b === void 0 ? ts.createCompilerHost(options, true) : _b; | ||
var resolver = module_filename_resolver_1.createModuleFilenameResolver(tsHost, options); | ||
@@ -29,3 +30,3 @@ var host = Object.create(tsHost); | ||
} | ||
exports.createHost = createHost; | ||
exports.createNgCompilerHost = createNgCompilerHost; | ||
//# sourceMappingURL=entry_points.js.map |
@@ -34,3 +34,3 @@ "use strict"; | ||
var inserts = []; | ||
// Calculate the range of intersting locations. The transform will only visit nodes in this | ||
// Calculate the range of interesting locations. The transform will only visit nodes in this | ||
// range to improve the performance on large files. | ||
@@ -40,2 +40,6 @@ var locations = Array.from(requests.keys()); | ||
var max = Math.max.apply(Math, locations); | ||
// Visit nodes matching the request and synthetic nodes added by tsickle | ||
function shouldVisit(pos, end) { | ||
return (pos <= max && end >= min) || pos == -1; | ||
} | ||
function visitSourceFile(sourceFile) { | ||
@@ -45,4 +49,6 @@ function topLevelStatement(node) { | ||
function visitNode(node) { | ||
var nodeRequest = requests.get(node.pos); | ||
if (nodeRequest && nodeRequest.kind == node.kind && nodeRequest.end == node.end) { | ||
// Get the original node before tsickle | ||
var _a = ts.getOriginalNode(node), pos = _a.pos, end = _a.end, kind = _a.kind; | ||
var nodeRequest = requests.get(pos); | ||
if (nodeRequest && nodeRequest.kind == kind && nodeRequest.end == end) { | ||
// This node is requested to be rewritten as a reference to the exported name. | ||
@@ -55,3 +61,3 @@ // Record that the node needs to be moved to an exported variable with the given name | ||
var result = node; | ||
if (node.pos <= max && node.end >= min && !isLexicalScope(node)) { | ||
if (shouldVisit(pos, end) && !isLexicalScope(node)) { | ||
result = ts.visitEachChild(node, visitNode, context); | ||
@@ -61,3 +67,5 @@ } | ||
} | ||
var result = (node.pos <= max && node.end >= min) ? ts.visitEachChild(node, visitNode, context) : node; | ||
// Get the original node before tsickle | ||
var _a = ts.getOriginalNode(node), pos = _a.pos, end = _a.end; | ||
var result = shouldVisit(pos, end) ? ts.visitEachChild(node, visitNode, context) : node; | ||
if (declarations.length) { | ||
@@ -64,0 +72,0 @@ inserts.push({ priorTo: result, declarations: declarations }); |
@@ -20,3 +20,5 @@ "use strict"; | ||
var converter = new _NodeEmitterVisitor(); | ||
var statements = stmts.map(function (stmt) { return stmt.visitStatement(converter, null); }).filter(function (stmt) { return stmt != null; }); | ||
// [].concat flattens the result so that each `visit...` method can also return an array of | ||
// stmts. | ||
var statements = [].concat.apply([], stmts.map(function (stmt) { return stmt.visitStatement(converter, null); }).filter(function (stmt) { return stmt != null; })); | ||
var newSourceFile = ts.updateSourceFileNode(sourceFile, converter.getReexports().concat(converter.getImports(), statements)); | ||
@@ -114,4 +116,13 @@ if (preamble) { | ||
} | ||
return this.record(stmt, ts.createVariableStatement(this.getModifiers(stmt), ts.createVariableDeclarationList([ts.createVariableDeclaration(ts.createIdentifier(stmt.name), | ||
/* type */ undefined, (stmt.value && stmt.value.visitExpression(this, null)) || undefined)]))); | ||
var varDeclList = ts.createVariableDeclarationList([ts.createVariableDeclaration(ts.createIdentifier(stmt.name), | ||
/* type */ undefined, (stmt.value && stmt.value.visitExpression(this, null)) || undefined)]); | ||
if (stmt.hasModifier(compiler_1.StmtModifier.Exported)) { | ||
// Note: We need to add an explicit variable and export declaration so that | ||
// the variable can be referred in the same file as well. | ||
var tsVarStmt = this.record(stmt, ts.createVariableStatement(/* modifiers */ [], varDeclList)); | ||
var exportStmt = this.record(stmt, ts.createExportDeclaration( | ||
/*decorators*/ undefined, /*modifiers*/ undefined, ts.createNamedExports([ts.createExportSpecifier(stmt.name, stmt.name)]))); | ||
return [tsVarStmt, exportStmt]; | ||
} | ||
return this.record(stmt, ts.createVariableStatement(this.getModifiers(stmt), varDeclList)); | ||
}; | ||
@@ -121,3 +132,3 @@ _NodeEmitterVisitor.prototype.visitDeclareFunctionStmt = function (stmt, context) { | ||
/* decorators */ undefined, this.getModifiers(stmt), | ||
/* astrictToken */ undefined, stmt.name, /* typeParameters */ undefined, stmt.params.map(function (p) { return ts.createParameter( | ||
/* asteriskToken */ undefined, stmt.name, /* typeParameters */ undefined, stmt.params.map(function (p) { return ts.createParameter( | ||
/* decorators */ undefined, /* modifiers */ undefined, | ||
@@ -124,0 +135,0 @@ /* dotDotDotToken */ undefined, p.name); }), |
@@ -11,4 +11,7 @@ "use strict"; | ||
var compiler_1 = require("@angular/compiler"); | ||
var fs_1 = require("fs"); | ||
var core_1 = require("@angular/core"); | ||
var tsc_wrapped_1 = require("@angular/tsc-wrapped"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var tsickle = require("tsickle"); | ||
var ts = require("typescript"); | ||
@@ -34,5 +37,21 @@ var compiler_host_1 = require("../compiler_host"); | ||
this._structuralDiagnostics = []; | ||
this.oldTsProgram = oldProgram ? oldProgram.getTsProgram() : undefined; | ||
this.tsProgram = ts.createProgram(rootNames, options, host, this.oldTsProgram); | ||
this.srcNames = this.tsProgram.getSourceFiles().map(function (sf) { return sf.fileName; }); | ||
this._optionsDiagnostics = []; | ||
if (options.flatModuleOutFile && !options.skipMetadataEmit) { | ||
var _a = tsc_wrapped_1.createBundleIndexHost(options, rootNames, host), bundleHost = _a.host, indexName = _a.indexName, errors = _a.errors; | ||
if (errors) { | ||
// TODO(tbosch): once we move MetadataBundler from tsc_wrapped into compiler_cli, | ||
// directly create ng.Diagnostic instead of using ts.Diagnostic here. | ||
(_b = this._optionsDiagnostics).push.apply(_b, errors.map(function (e) { return ({ category: e.category, message: e.messageText }); })); | ||
} | ||
else { | ||
rootNames.push(indexName); | ||
this.host = host = bundleHost; | ||
} | ||
} | ||
var oldTsProgram = oldProgram ? oldProgram.getTsProgram() : undefined; | ||
this.tsProgram = ts.createProgram(rootNames, options, host, oldTsProgram); | ||
this.srcNames = | ||
this.tsProgram.getSourceFiles() | ||
.map(function (sf) { return sf.fileName; }) | ||
.filter(function (f) { return !f.match(/\.ngfactory\.[\w.]+$|\.ngstyle\.[\w.]+$|\.ngsummary\.[\w.]+$/); }); | ||
this.metadataCache = new lower_expressions_1.LowerMetadataCache({ quotedNames: true }, !!options.strictMetadataEmit); | ||
@@ -43,4 +62,5 @@ this.aotCompilerHost = new compiler_host_1.CompilerHost(this.tsProgram, options, host, /* collectorOptions */ undefined, this.metadataCache); | ||
} | ||
var compiler = compiler_1.createAotCompiler(this.aotCompilerHost, options).compiler; | ||
this.compiler = compiler; | ||
var aotOptions = getAotCompilerOptions(options); | ||
this.compiler = compiler_1.createAotCompiler(this.aotCompilerHost, aotOptions).compiler; | ||
var _b; | ||
} | ||
@@ -53,3 +73,3 @@ // Program implementation | ||
AngularCompilerProgram.prototype.getNgOptionDiagnostics = function (cancellationToken) { | ||
return getNgOptionDiagnostics(this.options); | ||
return this._optionsDiagnostics.concat(getNgOptionDiagnostics(this.options)); | ||
}; | ||
@@ -89,5 +109,23 @@ AngularCompilerProgram.prototype.getTsSyntacticDiagnostics = function (sourceFile, cancellationToken) { | ||
var emitMap = new Map(); | ||
var result = this.programWithStubs.emit( | ||
/* targetSourceFile */ undefined, createWriteFileCallback(emitFlags, this.host, this.metadataCache, emitMap), cancellationToken, (emitFlags & (api_1.EmitFlags.DTS | api_1.EmitFlags.JS)) == api_1.EmitFlags.DTS, this.calculateTransforms()); | ||
var tsickleCompilerHostOptions = { | ||
googmodule: false, | ||
untyped: true, | ||
convertIndexImportShorthand: true, | ||
transformDecorators: this.options.annotationsAs !== 'decorators', | ||
transformTypesToClosure: this.options.annotateForClosureCompiler, | ||
}; | ||
var tsickleHost = { | ||
shouldSkipTsickleProcessing: function (fileName) { return /\.d\.ts$/.test(fileName); }, | ||
pathToModuleName: function (context, importPath) { return ''; }, | ||
shouldIgnoreWarningsForPath: function (filePath) { return false; }, | ||
fileNameToModuleId: function (fileName) { return fileName; }, | ||
}; | ||
var expectedOut = this.options.expectedOut ? | ||
this.options.expectedOut.map(function (f) { return path.resolve(process.cwd(), f); }) : | ||
undefined; | ||
var result = tsickle.emitWithTsickle(this.programWithStubs, tsickleHost, tsickleCompilerHostOptions, this.host, this.options, | ||
/* targetSourceFile */ undefined, createWriteFileCallback(emitFlags, this.host, this.metadataCache, emitMap, expectedOut), cancellationToken, (emitFlags & (api_1.EmitFlags.DTS | api_1.EmitFlags.JS)) == api_1.EmitFlags.DTS, this.calculateTransforms()); | ||
this.generatedFiles.forEach(function (file) { | ||
// In order not to replicate the TS calculation of the out folder for files | ||
// derive the out location for .json files from the out location of the .ts files | ||
if (file.source && file.source.length && SUMMARY_JSON_FILES.test(file.genFileUrl)) { | ||
@@ -97,8 +135,13 @@ // If we have emitted the ngsummary.ts file, ensure the ngsummary.json file is emitted to | ||
var emittedFile = emitMap.get(file.srcFileUrl); | ||
var fileName = emittedFile ? | ||
path.join(path.dirname(emittedFile), path.basename(file.genFileUrl)) : | ||
file.genFileUrl; | ||
_this.host.writeFile(fileName, file.source, false, function (error) { }); | ||
if (emittedFile) { | ||
var fileName = path.join(path.dirname(emittedFile), path.basename(file.genFileUrl)); | ||
_this.host.writeFile(fileName, file.source, false, function (error) { }); | ||
} | ||
} | ||
}); | ||
// Ensure that expected output files exist. | ||
for (var _i = 0, _c = expectedOut || []; _i < _c.length; _i++) { | ||
var out = _c[_i]; | ||
fs.appendFileSync(out, '', 'utf8'); | ||
} | ||
return result; | ||
@@ -179,16 +222,10 @@ }; | ||
AngularCompilerProgram.prototype.calculateTransforms = function () { | ||
var before = []; | ||
var after = []; | ||
var beforeTs = []; | ||
if (!this.options.disableExpressionLowering) { | ||
before.push(lower_expressions_1.getExpressionLoweringTransformFactory(this.metadataCache)); | ||
beforeTs.push(lower_expressions_1.getExpressionLoweringTransformFactory(this.metadataCache)); | ||
} | ||
if (!this.options.skipTemplateCodegen) { | ||
after.push(node_emitter_transform_1.getAngularEmitterTransformFactory(this.generatedFiles)); | ||
beforeTs.push(node_emitter_transform_1.getAngularEmitterTransformFactory(this.generatedFiles)); | ||
} | ||
var result = {}; | ||
if (before.length) | ||
result.before = before; | ||
if (after.length) | ||
result.after = after; | ||
return result; | ||
return { beforeTs: beforeTs }; | ||
}; | ||
@@ -202,3 +239,3 @@ AngularCompilerProgram.prototype.catchAnalysisError = function (e) { | ||
message: e.contextualMessage(), | ||
category: api_1.DiagnosticCategory.Error, | ||
category: ts.DiagnosticCategory.Error, | ||
span: e.span | ||
@@ -208,3 +245,3 @@ }); }); | ||
else { | ||
this._structuralDiagnostics = [{ message: e.message, category: api_1.DiagnosticCategory.Error }]; | ||
this._structuralDiagnostics = [{ message: e.message, category: ts.DiagnosticCategory.Error }]; | ||
} | ||
@@ -227,4 +264,4 @@ this._analyzedModules = emptyModules; | ||
this.options.generateCodeForLibraries === false ? | ||
this.compiler.emitAllStubs(this.analyzedModules) : | ||
this.compiler.emitPartialStubs(this.analyzedModules); | ||
this.compiler.emitPartialStubs(this.analyzedModules) : | ||
this.compiler.emitAllStubs(this.analyzedModules); | ||
}; | ||
@@ -240,3 +277,4 @@ AngularCompilerProgram.prototype.generateFiles = function () { | ||
if (compiler_1.isSyntaxError(e)) { | ||
this._generatedFileDiagnostics = [{ message: e.message, category: api_1.DiagnosticCategory.Error }]; | ||
this._generatedFileDiagnostics = | ||
[{ message: e.message, category: ts.DiagnosticCategory.Error }]; | ||
return []; | ||
@@ -264,2 +302,33 @@ } | ||
exports.createProgram = createProgram; | ||
// Compute the AotCompiler options | ||
function getAotCompilerOptions(options) { | ||
var missingTranslation = core_1.MissingTranslationStrategy.Warning; | ||
switch (options.i18nInMissingTranslations) { | ||
case 'ignore': | ||
missingTranslation = core_1.MissingTranslationStrategy.Ignore; | ||
break; | ||
case 'error': | ||
missingTranslation = core_1.MissingTranslationStrategy.Error; | ||
break; | ||
} | ||
var translations = ''; | ||
if (options.i18nInFile) { | ||
if (!options.locale) { | ||
throw new Error("The translation file (" + options.i18nInFile + ") locale must be provided."); | ||
} | ||
translations = fs.readFileSync(options.i18nInFile, 'utf8'); | ||
} | ||
else { | ||
// No translations are provided, ignore any errors | ||
// We still go through i18n to remove i18n attributes | ||
missingTranslation = core_1.MissingTranslationStrategy.Ignore; | ||
} | ||
return { | ||
locale: options.i18nInLocale, | ||
i18nFormat: options.i18nInFormat || options.i18nOutFormat, translations: translations, missingTranslation: missingTranslation, | ||
enableLegacyTemplate: options.enableLegacyTemplate, | ||
enableSummariesForJit: true, | ||
preserveWhitespaces: options.preserveWhitespaces, | ||
}; | ||
} | ||
function writeMetadata(emitFilePath, sourceFile, metadataCache) { | ||
@@ -279,27 +348,23 @@ if (/\.js$/.test(emitFilePath)) { | ||
var metadataText = JSON.stringify([metadata]); | ||
fs_1.writeFileSync(path_1, metadataText, { encoding: 'utf-8' }); | ||
fs.writeFileSync(path_1, metadataText, { encoding: 'utf-8' }); | ||
} | ||
} | ||
} | ||
function createWriteFileCallback(emitFlags, host, metadataCache, emitMap) { | ||
var withMetadata = function (fileName, data, writeByteOrderMark, onError, sourceFiles) { | ||
var generatedFile = GENERATED_FILES.test(fileName); | ||
if (!generatedFile || data != '') { | ||
host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); | ||
function createWriteFileCallback(emitFlags, host, metadataCache, emitMap, expectedOut) { | ||
return function (fileName, data, writeByteOrderMark, onError, sourceFiles) { | ||
var srcFile; | ||
if (sourceFiles && sourceFiles.length == 1) { | ||
srcFile = sourceFiles[0]; | ||
emitMap.set(srcFile.fileName, fileName); | ||
} | ||
if (!generatedFile && sourceFiles && sourceFiles.length == 1) { | ||
emitMap.set(sourceFiles[0].fileName, fileName); | ||
writeMetadata(fileName, sourceFiles[0], metadataCache); | ||
} | ||
}; | ||
var withoutMetadata = function (fileName, data, writeByteOrderMark, onError, sourceFiles) { | ||
var absFile = path.resolve(process.cwd(), fileName); | ||
var generatedFile = GENERATED_FILES.test(fileName); | ||
if (!generatedFile || data != '') { | ||
// Don't emit unexpected files nor empty generated files | ||
if ((!expectedOut || expectedOut.indexOf(absFile) > -1) && (!generatedFile || data)) { | ||
host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); | ||
if (srcFile && !generatedFile && (emitFlags & api_1.EmitFlags.Metadata) != 0) { | ||
writeMetadata(fileName, srcFile, metadataCache); | ||
} | ||
} | ||
if (!generatedFile && sourceFiles && sourceFiles.length == 1) { | ||
emitMap.set(sourceFiles[0].fileName, fileName); | ||
} | ||
}; | ||
return (emitFlags & api_1.EmitFlags.Metadata) != 0 ? withMetadata : withoutMetadata; | ||
} | ||
@@ -315,3 +380,3 @@ function getNgOptionDiagnostics(options) { | ||
message: 'Angular compiler options "annotationsAs" only supports "static fields" and "decorators"', | ||
category: api_1.DiagnosticCategory.Error | ||
category: ts.DiagnosticCategory.Error | ||
}]; | ||
@@ -318,0 +383,0 @@ } |
@@ -19,3 +19,3 @@ "use strict"; | ||
*/ | ||
exports.VERSION = new core_1.Version('5.0.0-beta.3'); | ||
exports.VERSION = new core_1.Version('5.0.0-beta.4'); | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
614875
5593
5
7
+ Addedtsickle@^0.23.4
+ Added@angular/compiler@5.0.0-beta.4(transitive)
+ Added@angular/core@5.0.0-beta.4(transitive)
+ Added@angular/tsc-wrapped@5.0.0-beta.4(transitive)
+ Addedtsickle@0.23.6(transitive)
+ Addedtypescript@2.3.4(transitive)
- Removed@angular/compiler@5.0.0-beta.3(transitive)
- Removed@angular/core@5.0.0-beta.3(transitive)
- Removed@angular/tsc-wrapped@5.0.0-beta.3(transitive)