diff --git a/tools/@angular/tsc-wrapped/src/compiler_host.ts b/tools/@angular/tsc-wrapped/src/compiler_host.ts index f55c220df2..5759d533ff 100644 --- a/tools/@angular/tsc-wrapped/src/compiler_host.ts +++ b/tools/@angular/tsc-wrapped/src/compiler_host.ts @@ -56,7 +56,10 @@ const DTS = /\.d\.ts$/; export class MetadataWriterHost extends DelegatingHost { private metadataCollector = new MetadataCollector({quotedNames: true}); private metadataCollector1 = new MetadataCollector({version: 1}); - constructor(delegate: ts.CompilerHost, private ngOptions: NgOptions) { super(delegate); } + constructor( + delegate: ts.CompilerHost, private ngOptions: NgOptions, private emitAllFiles: boolean) { + super(delegate); + } private writeMetadata(emitFilePath: string, sourceFile: ts.SourceFile) { // TODO: replace with DTS filePath when https://github.com/Microsoft/TypeScript/pull/8412 is @@ -87,10 +90,12 @@ export class MetadataWriterHost extends DelegatingHost { writeFile: ts.WriteFileCallback = (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => { - if (/\.d\.ts$/.test(fileName)) { + const isDts = /\.d\.ts$/.test(fileName); + if (this.emitAllFiles || isDts) { // Let the original file be written first; this takes care of creating parent directories this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); - + } + if (isDts) { // TODO: remove this early return after https://github.com/Microsoft/TypeScript/pull/8412 // is // released diff --git a/tools/@angular/tsc-wrapped/src/main.ts b/tools/@angular/tsc-wrapped/src/main.ts index 2abdb6e3f7..741aa4cb0e 100644 --- a/tools/@angular/tsc-wrapped/src/main.ts +++ b/tools/@angular/tsc-wrapped/src/main.ts @@ -117,7 +117,11 @@ export function main( if (diagnostics) console.timeEnd('NG codegen'); let definitionsHost: ts.CompilerHost = tsickleCompilerHost; if (!ngOptions.skipMetadataEmit) { - definitionsHost = new MetadataWriterHost(tsickleCompilerHost, ngOptions); + // if tsickle is not not used for emitting, but we do use the MetadataWriterHost, + // it also needs to emit the js files. + const emitJsFiles = + ngOptions.annotationsAs === 'decorators' && !ngOptions.annotateForClosureCompiler; + definitionsHost = new MetadataWriterHost(tsickleCompilerHost, ngOptions, emitJsFiles); } // Create a new program since codegen files were created after making the old program let programWithCodegen = createProgram(definitionsHost, program); diff --git a/tools/@angular/tsc-wrapped/test/main.spec.ts b/tools/@angular/tsc-wrapped/test/main.spec.ts index 4b15d2b6c1..a5419de29f 100644 --- a/tools/@angular/tsc-wrapped/test/main.spec.ts +++ b/tools/@angular/tsc-wrapped/test/main.spec.ts @@ -153,6 +153,40 @@ describe('tsc-wrapped', () => { .catch(e => done.fail(e)); }); + it('should allow all options disabled with metadata emit', (done) => { + write('tsconfig.json', `{ + "compilerOptions": { + "experimentalDecorators": true, + "types": [], + "outDir": "built", + "declaration": false, + "module": "es2015", + "moduleResolution": "node" + }, + "angularCompilerOptions": { + "annotateForClosureCompiler": false, + "annotationsAs": "decorators", + "skipMetadataEmit": false, + "skipTemplateCodegen": true + }, + "files": ["test.ts"] + }`); + + main(basePath, {basePath}) + .then(() => { + const out = readOut('js'); + // TypeScript's decorator emit + expect(out).toContain('__decorate'); + // Not annotated for Closure compiler + expect(out).not.toContain('* @param {?} x'); + expect(() => fs.accessSync(path.join(basePath, 'built', 'test.d.ts'))).toThrow(); + const metadata = readOut('metadata.json'); + expect(metadata).toContain('"Comp":{"__symbolic":"class"'); + done(); + }) + .catch(e => done.fail(e)); + }); + it('should allow JSDoc annotations without decorator downleveling', (done) => { write('tsconfig.json', `{ "compilerOptions": {