@angular/compiler-cli
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -9,4 +9,5 @@ /** | ||
export { CodeGenerator } from './src/codegen'; | ||
export { Extractor } from './src/extractor'; | ||
export { NodeReflectorHostContext, ReflectorHost, ReflectorHostContext } from './src/reflector_host'; | ||
export { StaticReflector, StaticReflectorHost, StaticSymbol } from './src/static_reflector'; | ||
export * from '@angular/tsc-wrapped'; |
@@ -14,2 +14,4 @@ /** | ||
exports.CodeGenerator = codegen_1.CodeGenerator; | ||
var extractor_1 = require('./src/extractor'); | ||
exports.Extractor = extractor_1.Extractor; | ||
var reflector_host_1 = require('./src/reflector_host'); | ||
@@ -16,0 +18,0 @@ exports.NodeReflectorHostContext = reflector_host_1.NodeReflectorHostContext; |
@@ -1,1 +0,1 @@ | ||
{"__symbolic":"module","version":1,"metadata":{},"exports":[{"from":"./src/codegen","export":["CodeGenerator"]},{"from":"./src/reflector_host","export":["NodeReflectorHostContext","ReflectorHost","ReflectorHostContext"]},{"from":"./src/static_reflector","export":["StaticReflector","StaticReflectorHost","StaticSymbol"]},{"from":"@angular/tsc-wrapped"}]} | ||
{"__symbolic":"module","version":1,"metadata":{},"exports":[{"from":"./src/codegen","export":["CodeGenerator"]},{"from":"./src/extractor","export":["Extractor"]},{"from":"./src/reflector_host","export":["NodeReflectorHostContext","ReflectorHost","ReflectorHostContext"]},{"from":"./src/static_reflector","export":["StaticReflector","StaticReflectorHost","StaticSymbol"]},{"from":"@angular/tsc-wrapped"}]} |
{ | ||
"name": "@angular/compiler-cli", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Angular - the compiler CLI for Node.js", | ||
@@ -18,4 +18,4 @@ "main": "index.js", | ||
"typescript": "^2.0.2", | ||
"@angular/compiler": "2.1.1", | ||
"@angular/core": "2.1.1" | ||
"@angular/compiler": "2.1.2", | ||
"@angular/core": "2.1.2" | ||
}, | ||
@@ -22,0 +22,0 @@ "repository": { |
@@ -17,14 +17,2 @@ /** | ||
import { StaticReflector, StaticReflectorHost, StaticSymbol } from './static_reflector'; | ||
export declare class CodeGeneratorModuleCollector { | ||
private staticReflector; | ||
private reflectorHost; | ||
private program; | ||
private options; | ||
constructor(staticReflector: StaticReflector, reflectorHost: StaticReflectorHost, program: ts.Program, options: AngularCompilerOptions); | ||
getModuleSymbols(program: ts.Program): { | ||
fileMetas: FileMetadata[]; | ||
ngModules: StaticSymbol[]; | ||
}; | ||
private readFileMetadata(absSourcePath); | ||
} | ||
export declare class CodeGenerator { | ||
@@ -37,12 +25,9 @@ private options; | ||
private reflectorHost; | ||
private moduleCollector; | ||
constructor(options: AngularCompilerOptions, program: ts.Program, host: ts.CompilerHost, staticReflector: StaticReflector, compiler: compiler.OfflineCompiler, reflectorHost: StaticReflectorHost); | ||
private calculateEmitPath(filePath); | ||
codegen(): Promise<any>; | ||
codegen(options: { | ||
transitiveModules: boolean; | ||
}): Promise<any>; | ||
static create(options: AngularCompilerOptions, cliOptions: NgcCliOptions, program: ts.Program, compilerHost: ts.CompilerHost, reflectorHostContext?: ReflectorHostContext, resourceLoader?: compiler.ResourceLoader, reflectorHost?: ReflectorHost): CodeGenerator; | ||
} | ||
export interface FileMetadata { | ||
fileUrl: string; | ||
directives: StaticSymbol[]; | ||
ngModules: StaticSymbol[]; | ||
} | ||
export declare function extractProgramSymbols(program: ts.Program, staticReflector: StaticReflector, reflectorHost: StaticReflectorHost, options: AngularCompilerOptions): StaticSymbol[]; |
@@ -25,63 +25,2 @@ /** | ||
var PREAMBLE = "/**\n * This file is generated by the Angular 2 template compiler.\n * Do not edit.\n */\n /* tslint:disable */\n\n"; | ||
var CodeGeneratorModuleCollector = (function () { | ||
function CodeGeneratorModuleCollector(staticReflector, reflectorHost, program, options) { | ||
this.staticReflector = staticReflector; | ||
this.reflectorHost = reflectorHost; | ||
this.program = program; | ||
this.options = options; | ||
} | ||
CodeGeneratorModuleCollector.prototype.getModuleSymbols = function (program) { | ||
var _this = this; | ||
// Compare with false since the default should be true | ||
var skipFileNames = (this.options.generateCodeForLibraries === false) ? | ||
GENERATED_OR_DTS_FILES : | ||
GENERATED_FILES; | ||
var filePaths = this.program.getSourceFiles() | ||
.filter(function (sf) { return !skipFileNames.test(sf.fileName); }) | ||
.map(function (sf) { return _this.reflectorHost.getCanonicalFileName(sf.fileName); }); | ||
var fileMetas = filePaths.map(function (filePath) { return _this.readFileMetadata(filePath); }); | ||
var ngModules = fileMetas.reduce(function (ngModules, fileMeta) { | ||
ngModules.push.apply(ngModules, fileMeta.ngModules); | ||
return ngModules; | ||
}, []); | ||
return { fileMetas: fileMetas, ngModules: ngModules }; | ||
}; | ||
CodeGeneratorModuleCollector.prototype.readFileMetadata = function (absSourcePath) { | ||
var moduleMetadata = this.staticReflector.getModuleMetadata(absSourcePath); | ||
var result = { directives: [], ngModules: [], fileUrl: absSourcePath }; | ||
if (!moduleMetadata) { | ||
console.log("WARNING: no metadata found for " + absSourcePath); | ||
return result; | ||
} | ||
var metadata = moduleMetadata['metadata']; | ||
var symbols = metadata && Object.keys(metadata); | ||
if (!symbols || !symbols.length) { | ||
return result; | ||
} | ||
var _loop_1 = function(symbol) { | ||
if (metadata[symbol] && metadata[symbol].__symbolic == 'error') { | ||
// Ignore symbols that are only included to record error information. | ||
return "continue"; | ||
} | ||
var staticType = this_1.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath); | ||
var annotations = this_1.staticReflector.annotations(staticType); | ||
annotations.forEach(function (annotation) { | ||
if (annotation instanceof core_1.NgModule) { | ||
result.ngModules.push(staticType); | ||
} | ||
else if (annotation instanceof core_1.Directive) { | ||
result.directives.push(staticType); | ||
} | ||
}); | ||
}; | ||
var this_1 = this; | ||
for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) { | ||
var symbol = symbols_1[_i]; | ||
_loop_1(symbol); | ||
} | ||
return result; | ||
}; | ||
return CodeGeneratorModuleCollector; | ||
}()); | ||
exports.CodeGeneratorModuleCollector = CodeGeneratorModuleCollector; | ||
var CodeGenerator = (function () { | ||
@@ -95,4 +34,2 @@ function CodeGenerator(options, program, host, staticReflector, compiler, reflectorHost) { | ||
this.reflectorHost = reflectorHost; | ||
this.moduleCollector = | ||
new CodeGeneratorModuleCollector(staticReflector, reflectorHost, program, options); | ||
} | ||
@@ -120,17 +57,12 @@ // Write codegen in a directory structure matching the sources. | ||
}; | ||
CodeGenerator.prototype.codegen = function () { | ||
CodeGenerator.prototype.codegen = function (options) { | ||
var _this = this; | ||
var _a = this.moduleCollector.getModuleSymbols(this.program), fileMetas = _a.fileMetas, ngModules = _a.ngModules; | ||
var analyzedNgModules = this.compiler.analyzeModules(ngModules); | ||
return Promise.all(fileMetas.map(function (fileMeta) { | ||
return _this.compiler | ||
.compile(fileMeta.fileUrl, analyzedNgModules, fileMeta.directives, fileMeta.ngModules) | ||
.then(function (generatedModules) { | ||
generatedModules.forEach(function (generatedModule) { | ||
var sourceFile = _this.program.getSourceFile(fileMeta.fileUrl); | ||
var emitPath = _this.calculateEmitPath(generatedModule.moduleUrl); | ||
_this.host.writeFile(emitPath, PREAMBLE + generatedModule.source, false, function () { }, [sourceFile]); | ||
}); | ||
var staticSymbols = extractProgramSymbols(this.program, this.staticReflector, this.reflectorHost, this.options); | ||
return this.compiler.compileModules(staticSymbols, options).then(function (generatedModules) { | ||
generatedModules.forEach(function (generatedModule) { | ||
var sourceFile = _this.program.getSourceFile(generatedModule.fileUrl); | ||
var emitPath = _this.calculateEmitPath(generatedModule.moduleUrl); | ||
_this.host.writeFile(emitPath, PREAMBLE + generatedModule.source, false, function () { }, [sourceFile]); | ||
}); | ||
})); | ||
}); | ||
}; | ||
@@ -179,3 +111,3 @@ CodeGenerator.create = function (options, cliOptions, program, compilerHost, reflectorHostContext, resourceLoader, reflectorHost) { | ||
// TODO(vicb): do not pass cliOptions.i18nFormat here | ||
var offlineCompiler = new compiler.OfflineCompiler(resolver, normalizer, tmplParser, new compiler.StyleCompiler(urlResolver), new compiler.ViewCompiler(config), new compiler.DirectiveWrapperCompiler(config), new compiler.NgModuleCompiler(), new compiler.TypeScriptEmitter(reflectorHost), cliOptions.locale, cliOptions.i18nFormat); | ||
var offlineCompiler = new compiler.OfflineCompiler(resolver, normalizer, tmplParser, new compiler.StyleCompiler(urlResolver), new compiler.ViewCompiler(config, elementSchemaRegistry), new compiler.DirectiveWrapperCompiler(config, expressionParser, elementSchemaRegistry, console), new compiler.NgModuleCompiler(), new compiler.TypeScriptEmitter(reflectorHost), cliOptions.locale, cliOptions.i18nFormat); | ||
return new CodeGenerator(options, program, compilerHost, staticReflector, offlineCompiler, reflectorHost); | ||
@@ -186,2 +118,31 @@ }; | ||
exports.CodeGenerator = CodeGenerator; | ||
function extractProgramSymbols(program, staticReflector, reflectorHost, options) { | ||
// Compare with false since the default should be true | ||
var skipFileNames = options.generateCodeForLibraries === false ? GENERATED_OR_DTS_FILES : GENERATED_FILES; | ||
var staticSymbols = []; | ||
program.getSourceFiles() | ||
.filter(function (sourceFile) { return !skipFileNames.test(sourceFile.fileName); }) | ||
.forEach(function (sourceFile) { | ||
var absSrcPath = reflectorHost.getCanonicalFileName(sourceFile.fileName); | ||
var moduleMetadata = staticReflector.getModuleMetadata(absSrcPath); | ||
if (!moduleMetadata) { | ||
console.log("WARNING: no metadata found for " + absSrcPath); | ||
return; | ||
} | ||
var metadata = moduleMetadata['metadata']; | ||
if (!metadata) { | ||
return; | ||
} | ||
for (var _i = 0, _a = Object.keys(metadata); _i < _a.length; _i++) { | ||
var symbol = _a[_i]; | ||
if (metadata[symbol] && metadata[symbol].__symbolic == 'error') { | ||
// Ignore symbols that are only included to record error information. | ||
continue; | ||
} | ||
staticSymbols.push(reflectorHost.findDeclaration(absSrcPath, symbol, absSrcPath)); | ||
} | ||
}); | ||
return staticSymbols; | ||
} | ||
exports.extractProgramSymbols = extractProgramSymbols; | ||
//# sourceMappingURL=codegen.js.map |
import 'reflect-metadata'; | ||
import * as compiler from '@angular/compiler'; | ||
import * as ts from 'typescript'; | ||
import * as tsc from '@angular/tsc-wrapped'; | ||
import { ReflectorHost, ReflectorHostContext } from './reflector_host'; | ||
import { StaticReflector } from './static_reflector'; | ||
export declare class Extractor { | ||
private program; | ||
host: ts.CompilerHost; | ||
private staticReflector; | ||
private messageBundle; | ||
private reflectorHost; | ||
private metadataResolver; | ||
private directiveNormalizer; | ||
constructor(program: ts.Program, host: ts.CompilerHost, staticReflector: StaticReflector, messageBundle: compiler.MessageBundle, reflectorHost: ReflectorHost, metadataResolver: compiler.CompileMetadataResolver, directiveNormalizer: compiler.DirectiveNormalizer); | ||
private readFileMetadata(absSourcePath); | ||
extract(): Promise<compiler.MessageBundle>; | ||
static create(options: tsc.AngularCompilerOptions, translationsFormat: string, program: ts.Program, compilerHost: ts.CompilerHost, htmlParser: compiler.I18NHtmlParser, reflectorHostContext?: ReflectorHostContext): Extractor; | ||
} |
@@ -5,11 +5,16 @@ #!/usr/bin/env node | ||
var compiler = require('@angular/compiler'); | ||
var core_1 = require('@angular/core'); | ||
var tsc = require('@angular/tsc-wrapped'); | ||
var path = require('path'); | ||
var tsc = require('@angular/tsc-wrapped'); | ||
var reflector_host_1 = require('./reflector_host'); | ||
var static_reflection_capabilities_1 = require('./static_reflection_capabilities'); | ||
var static_reflector_1 = require('./static_reflector'); | ||
var extractor_1 = require('./extractor'); | ||
function extract(ngOptions, cliOptions, program, host) { | ||
var htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser()); | ||
var extractor = Extractor.create(ngOptions, cliOptions.i18nFormat, program, host, htmlParser); | ||
var resourceLoader = { | ||
get: function (s) { | ||
if (!host.fileExists(s)) { | ||
// TODO: We should really have a test for error cases like this! | ||
throw new Error("Compilation failed. Resource file not found: " + s); | ||
} | ||
return Promise.resolve(host.readFile(s)); | ||
} | ||
}; | ||
var extractor = extractor_1.Extractor.create(ngOptions, cliOptions.i18nFormat, program, host, resourceLoader); | ||
var bundlePromise = extractor.extract(); | ||
@@ -28,2 +33,3 @@ return (bundlePromise).then(function (messageBundle) { | ||
default: | ||
var htmlParser = new compiler.I18NHtmlParser(new compiler.HtmlParser()); | ||
ext = 'xlf'; | ||
@@ -37,115 +43,2 @@ serializer = new compiler.Xliff(htmlParser, compiler.DEFAULT_INTERPOLATION_CONFIG); | ||
} | ||
var GENERATED_FILES = /\.ngfactory\.ts$|\.css\.ts$|\.css\.shim\.ts$/; | ||
var Extractor = (function () { | ||
function Extractor(program, host, staticReflector, messageBundle, reflectorHost, metadataResolver, directiveNormalizer) { | ||
this.program = program; | ||
this.host = host; | ||
this.staticReflector = staticReflector; | ||
this.messageBundle = messageBundle; | ||
this.reflectorHost = reflectorHost; | ||
this.metadataResolver = metadataResolver; | ||
this.directiveNormalizer = directiveNormalizer; | ||
} | ||
Extractor.prototype.readFileMetadata = function (absSourcePath) { | ||
var moduleMetadata = this.staticReflector.getModuleMetadata(absSourcePath); | ||
var result = { components: [], ngModules: [], fileUrl: absSourcePath }; | ||
if (!moduleMetadata) { | ||
console.log("WARNING: no metadata found for " + absSourcePath); | ||
return result; | ||
} | ||
var metadata = moduleMetadata['metadata']; | ||
var symbols = metadata && Object.keys(metadata); | ||
if (!symbols || !symbols.length) { | ||
return result; | ||
} | ||
var _loop_1 = function(symbol) { | ||
if (metadata[symbol] && metadata[symbol].__symbolic == 'error') { | ||
// Ignore symbols that are only included to record error information. | ||
return "continue"; | ||
} | ||
var staticType = this_1.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath); | ||
var annotations = this_1.staticReflector.annotations(staticType); | ||
annotations.forEach(function (annotation) { | ||
if (annotation instanceof core_1.NgModule) { | ||
result.ngModules.push(staticType); | ||
} | ||
else if (annotation instanceof core_1.Component) { | ||
result.components.push(staticType); | ||
} | ||
}); | ||
}; | ||
var this_1 = this; | ||
for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) { | ||
var symbol = symbols_1[_i]; | ||
_loop_1(symbol); | ||
} | ||
return result; | ||
}; | ||
Extractor.prototype.extract = function () { | ||
var _this = this; | ||
var filePaths = this.program.getSourceFiles().map(function (sf) { return sf.fileName; }).filter(function (f) { return !GENERATED_FILES.test(f); }); | ||
var fileMetas = filePaths.map(function (filePath) { return _this.readFileMetadata(filePath); }); | ||
var ngModules = fileMetas.reduce(function (ngModules, fileMeta) { | ||
ngModules.push.apply(ngModules, fileMeta.ngModules); | ||
return ngModules; | ||
}, []); | ||
var analyzedNgModules = compiler.analyzeModules(ngModules, this.metadataResolver); | ||
var errors = []; | ||
var bundlePromise = Promise | ||
.all(fileMetas.map(function (fileMeta) { | ||
var url = fileMeta.fileUrl; | ||
return Promise.all(fileMeta.components.map(function (compType) { | ||
var compMeta = _this.metadataResolver.getDirectiveMetadata(compType); | ||
var ngModule = analyzedNgModules.ngModuleByDirective.get(compType); | ||
if (!ngModule) { | ||
throw new Error("Cannot determine the module for component " + compMeta.type.name + "!"); | ||
} | ||
return Promise | ||
.all([compMeta].concat(ngModule.transitiveModule.directives).map(function (dirMeta) { | ||
return _this.directiveNormalizer.normalizeDirective(dirMeta).asyncResult; | ||
})) | ||
.then(function (normalizedCompWithDirectives) { | ||
var compMeta = normalizedCompWithDirectives[0]; | ||
var html = compMeta.template.template; | ||
var interpolationConfig = compiler.InterpolationConfig.fromArray(compMeta.template.interpolation); | ||
errors.push.apply(errors, _this.messageBundle.updateFromTemplate(html, url, interpolationConfig)); | ||
}); | ||
})); | ||
})) | ||
.then(function (_) { return _this.messageBundle; }); | ||
if (errors.length) { | ||
throw new Error(errors.map(function (e) { return e.toString(); }).join('\n')); | ||
} | ||
return bundlePromise; | ||
}; | ||
Extractor.create = function (options, translationsFormat, program, compilerHost, htmlParser, reflectorHostContext) { | ||
var resourceLoader = { | ||
get: function (s) { | ||
if (!compilerHost.fileExists(s)) { | ||
// TODO: We should really have a test for error cases like this! | ||
throw new Error("Compilation failed. Resource file not found: " + s); | ||
} | ||
return Promise.resolve(compilerHost.readFile(s)); | ||
} | ||
}; | ||
var urlResolver = compiler.createOfflineCompileUrlResolver(); | ||
var reflectorHost = new reflector_host_1.ReflectorHost(program, compilerHost, options, reflectorHostContext); | ||
var staticReflector = new static_reflector_1.StaticReflector(reflectorHost); | ||
static_reflection_capabilities_1.StaticAndDynamicReflectionCapabilities.install(staticReflector); | ||
var config = new compiler.CompilerConfig({ | ||
genDebugInfo: options.debug === true, | ||
defaultEncapsulation: core_1.ViewEncapsulation.Emulated, | ||
logBindingUpdate: false, | ||
useJit: false | ||
}); | ||
var normalizer = new compiler.DirectiveNormalizer(resourceLoader, urlResolver, htmlParser, config); | ||
var elementSchemaRegistry = new compiler.DomElementSchemaRegistry(); | ||
var resolver = new compiler.CompileMetadataResolver(new compiler.NgModuleResolver(staticReflector), new compiler.DirectiveResolver(staticReflector), new compiler.PipeResolver(staticReflector), elementSchemaRegistry, staticReflector); | ||
// TODO(vicb): implicit tags & attributes | ||
var messageBundle = new compiler.MessageBundle(htmlParser, [], {}); | ||
return new Extractor(program, compilerHost, staticReflector, messageBundle, reflectorHost, resolver, normalizer); | ||
}; | ||
return Extractor; | ||
}()); | ||
exports.Extractor = Extractor; | ||
// Entry point | ||
@@ -152,0 +45,0 @@ if (require.main === module) { |
@@ -7,3 +7,5 @@ #!/usr/bin/env node | ||
function codegen(ngOptions, cliOptions, program, host) { | ||
return codegen_1.CodeGenerator.create(ngOptions, cliOptions, program, host).codegen(); | ||
return codegen_1.CodeGenerator.create(ngOptions, cliOptions, program, host).codegen({ | ||
transitiveModules: true | ||
}); | ||
} | ||
@@ -10,0 +12,0 @@ // CLI entry point |
@@ -222,2 +222,6 @@ /** | ||
if (!sf) { | ||
if (this.context.fileExists(filePath)) { | ||
var sourceText = this.context.readFile(filePath); | ||
return this.metadataCollector.getMetadata(ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true)); | ||
} | ||
throw new Error("Source file " + filePath + " not present in program."); | ||
@@ -224,0 +228,0 @@ } |
@@ -17,3 +17,5 @@ import { ReflectorReader } from './private_import_core'; | ||
[key: string]: any; | ||
}; | ||
} | { | ||
[key: string]: any; | ||
}[]; | ||
/** | ||
@@ -20,0 +22,0 @@ * Resolve a symbol from an import statement form, to the file where it is declared. |
@@ -49,4 +49,3 @@ /** | ||
StaticReflector.prototype.resolveIdentifier = function (name, moduleUrl, runtime) { | ||
var result = this.host.findDeclaration(moduleUrl, name, ''); | ||
return result; | ||
return this.host.findDeclaration(moduleUrl, name, ''); | ||
}; | ||
@@ -198,3 +197,2 @@ StaticReflector.prototype.resolveEnum = function (enumIdentifier, name) { | ||
function resolveReferenceValue(staticSymbol) { | ||
var result = staticSymbol; | ||
var moduleMetadata = _this.getModuleMetadata(staticSymbol.filePath); | ||
@@ -491,4 +489,3 @@ var declarationValue = moduleMetadata ? moduleMetadata['metadata'][staticSymbol.name] : null; | ||
if (Array.isArray(moduleMetadata)) { | ||
moduleMetadata = moduleMetadata | ||
.find(function (element) { return element.version === SUPPORTED_SCHEMA_VERSION; }) || | ||
moduleMetadata = moduleMetadata.find(function (md) { return md['version'] === SUPPORTED_SCHEMA_VERSION; }) || | ||
moduleMetadata[0]; | ||
@@ -509,7 +506,3 @@ } | ||
var moduleMetadata = this.getModuleMetadata(type.filePath); | ||
var result = moduleMetadata['metadata'][type.name]; | ||
if (!result) { | ||
result = { __symbolic: 'class' }; | ||
} | ||
return result; | ||
return moduleMetadata['metadata'][type.name] || { __symbolic: 'class' }; | ||
}; | ||
@@ -569,3 +562,2 @@ return StaticReflector; | ||
var current = new Map(); | ||
var parent = undefined; | ||
return { | ||
@@ -572,0 +564,0 @@ define: function (name, value) { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34
144683
1756