Skip to content

Commit

Permalink
chore(tsc-wrapped): update to newest tsickle
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Jun 9, 2016
1 parent 3aca5ff commit bbed364
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.clean.json
Original file line number Diff line number Diff line change
Expand Up @@ -5203,7 +5203,7 @@
}
},
"tsickle": {
"version": "0.1.2",
"version": "0.1.4",
"dependencies": {
"source-map": {
"version": "0.4.4"
Expand Down
5 changes: 2 additions & 3 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tools/@angular/tsc-wrapped/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 11 additions & 5 deletions tools/@angular/tsc-wrapped/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
14 changes: 8 additions & 6 deletions tools/@angular/tsc-wrapped/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
Promise<void>;

export function main(project: string, basePath?: string, codegen?: CodegenExtension): Promise<any> {
try {
Expand All @@ -32,20 +32,22 @@ 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
// Not in the same emit pass with above, because tsickle erases
// 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) {
Expand Down
5 changes: 1 addition & 4 deletions tools/@angular/tsc-wrapped/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit bbed364

Please sign in to comment.