From bbed364e7b5325ec15251bb8d035e6941b94f2fa Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Tue, 7 Jun 2016 15:42:27 -0700 Subject: [PATCH] chore(tsc-wrapped): update to newest tsickle --- .gitignore | 5 ----- npm-shrinkwrap.clean.json | 2 +- npm-shrinkwrap.json | 5 ++--- package.json | 2 +- tools/@angular/tsc-wrapped/package.json | 2 +- tools/@angular/tsc-wrapped/src/compiler_host.ts | 16 +++++++++++----- tools/@angular/tsc-wrapped/src/main.ts | 14 ++++++++------ tools/@angular/tsc-wrapped/src/tsc.ts | 5 +---- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index c8cfa0210d..9d84735b80 100644 --- a/.gitignore +++ b/.gitignore @@ -21,11 +21,6 @@ tmp *.js.deps *.js.map -# Files created by the template compiler -**/*.ngfactory.ts -**/*.css.ts -**/*.css.shim.ts - # Include when developing application packages. pubspec.lock .c9 diff --git a/npm-shrinkwrap.clean.json b/npm-shrinkwrap.clean.json index dbe6c30415..3ff6b4f5f9 100644 --- a/npm-shrinkwrap.clean.json +++ b/npm-shrinkwrap.clean.json @@ -5203,7 +5203,7 @@ } }, "tsickle": { - "version": "0.1.2", + "version": "0.1.4", "dependencies": { "source-map": { "version": "0.4.4" diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 3f2e41e501..4be3634f4d 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -8293,9 +8293,8 @@ } }, "tsickle": { - "version": "0.1.2", - "from": "tsickle@0.1.2", - "resolved": "https://registry.npmjs.org/tsickle/-/tsickle-0.1.2.tgz", + "version": "0.1.4", + "from": "tsickle@0.1.4", "dependencies": { "source-map": { "version": "0.4.4", diff --git a/package.json b/package.json index b51e345646..781f3937d6 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,7 @@ "through2": "^0.6.5", "ts-api-guardian": "0.0.3", "ts2dart": "^0.9.10", - "tsickle": "0.1.2", + "tsickle": "^0.1.4", "tslint": "^3.10.0-dev.2", "typescript": "^1.9.0-dev.20160409", "universal-analytics": "^0.3.9", diff --git a/tools/@angular/tsc-wrapped/package.json b/tools/@angular/tsc-wrapped/package.json index af6cc0bbd9..43d4fbdd48 100644 --- a/tools/@angular/tsc-wrapped/package.json +++ b/tools/@angular/tsc-wrapped/package.json @@ -11,7 +11,7 @@ "license": "MIT", "repository": {"type":"git","url":"https://github.com/angular/angular.git"}, "dependencies": { - "tsickle": "0.1.2" + "tsickle": "0.1.4" }, "peerDependencies": { "typescript": "^1.9.0-dev" diff --git a/tools/@angular/tsc-wrapped/src/compiler_host.ts b/tools/@angular/tsc-wrapped/src/compiler_host.ts index 4167b6502d..a2bcaa9a6f 100644 --- a/tools/@angular/tsc-wrapped/src/compiler_host.ts +++ b/tools/@angular/tsc-wrapped/src/compiler_host.ts @@ -39,18 +39,24 @@ interface DecoratorInvocation { args?: any[]; } `; - constructor(delegate: ts.CompilerHost) { super(delegate); } + constructor(delegate: ts.CompilerHost, private program: ts.Program) { super(delegate); } getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void) => { const originalContent = this.delegate.readFile(fileName); let newContent = originalContent; if (!/\.d\.ts$/.test(fileName)) { - const converted = convertDecorators(fileName, originalContent); - if (converted.diagnostics) { - this.diagnostics.push(...converted.diagnostics); + try { + const converted = convertDecorators( + this.program.getTypeChecker(), this.program.getSourceFile(fileName)); + if (converted.diagnostics) { + this.diagnostics.push(...converted.diagnostics); + } + newContent = converted.output + this.TSICKLE_SUPPORT; + } catch (e) { + console.error('Cannot convertDecorators on file', fileName); + throw e; } - newContent = converted.output + this.TSICKLE_SUPPORT; } return ts.createSourceFile(fileName, newContent, languageVersion, true); }; diff --git a/tools/@angular/tsc-wrapped/src/main.ts b/tools/@angular/tsc-wrapped/src/main.ts index 175cea7230..b943be8c34 100644 --- a/tools/@angular/tsc-wrapped/src/main.ts +++ b/tools/@angular/tsc-wrapped/src/main.ts @@ -8,7 +8,7 @@ import NgOptions from './options'; import {MetadataWriterHost, TsickleHost} from './compiler_host'; export type CodegenExtension = (ngOptions: NgOptions, program: ts.Program, host: ts.CompilerHost) => - Promise; + Promise; export function main(project: string, basePath?: string, codegen?: CodegenExtension): Promise { try { @@ -32,11 +32,13 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens codegen = () => Promise.resolve(null); } return codegen(ngOptions, program, host).then(() => { - tsc.typeCheck(host, program); + // Create a new program since codegen files were created after making the old program + const newProgram = ts.createProgram(parsed.fileNames, parsed.options, host, program); + tsc.typeCheck(host, newProgram); // Emit *.js with Decorators lowered to Annotations, and also *.js.map - const tsicklePreProcessor = new TsickleHost(host); - tsc.emit(tsicklePreProcessor, program); + const tsicklePreProcessor = new TsickleHost(host, newProgram); + tsc.emit(tsicklePreProcessor, newProgram); if (!ngOptions.skipMetadataEmit) { // Emit *.metadata.json and *.d.ts @@ -44,8 +46,8 @@ export function main(project: string, basePath?: string, codegen?: CodegenExtens // decorators which we want to read or document. // Do this emit second since TypeScript will create missing directories for us // in the standard emit. - const metadataWriter = new MetadataWriterHost(host, program); - tsc.emit(metadataWriter, program); + const metadataWriter = new MetadataWriterHost(host, newProgram); + tsc.emit(metadataWriter, newProgram); } }); } catch (e) { diff --git a/tools/@angular/tsc-wrapped/src/tsc.ts b/tools/@angular/tsc-wrapped/src/tsc.ts index 1591089aef..f3150e5593 100644 --- a/tools/@angular/tsc-wrapped/src/tsc.ts +++ b/tools/@angular/tsc-wrapped/src/tsc.ts @@ -79,10 +79,7 @@ export class Tsc implements CompilerInterface { return {parsed: this.parsed, ngOptions: this.ngOptions}; } - typeCheck(compilerHost: ts.CompilerHost, oldProgram: ts.Program): void { - // Create a new program since codegen files were created after making the old program - const program = - ts.createProgram(this.parsed.fileNames, this.parsed.options, compilerHost, oldProgram); + typeCheck(compilerHost: ts.CompilerHost, program: ts.Program): void { debug('Checking global diagnostics...'); check(program.getGlobalDiagnostics());