From 5c0ea20bd0dd4acc7936aafc56f7e680aeae4503 Mon Sep 17 00:00:00 2001 From: Lucas Sloan Date: Wed, 22 Feb 2017 13:11:15 -0800 Subject: [PATCH] build(tsc-wrapped): use tsickleCompilerHost for initial file load In order for tsickle's new support for input source maps to work, the tsickleCompilerHost must be used for the initial load of source files, since that's when the inline source maps are read and stripped. --- tools/@angular/tsc-wrapped/src/main.ts | 44 ++++++++++---------- tools/@angular/tsc-wrapped/test/main.spec.ts | 31 ++++++++++++++ 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/tools/@angular/tsc-wrapped/src/main.ts b/tools/@angular/tsc-wrapped/src/main.ts index 024a2f26b4..2abdb6e3f7 100644 --- a/tools/@angular/tsc-wrapped/src/main.ts +++ b/tools/@angular/tsc-wrapped/src/main.ts @@ -86,7 +86,25 @@ export function main( parsed.fileNames.push(name); } - const program = createProgram(host); + const tsickleCompilerHostOptions: tsickle.Options = { + googmodule: false, + untyped: true, + convertIndexImportShorthand: + ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too + }; + + const tsickleHost: tsickle.TsickleHost = { + shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName), + pathToModuleName: (context, importPath) => '', + shouldIgnoreWarningsForPath: (filePath) => false, + fileNameToModuleId: (fileName) => fileName, + }; + + const tsickleCompilerHost = + new tsickle.TsickleCompilerHost(host, ngOptions, tsickleCompilerHostOptions, tsickleHost); + + const program = createProgram(tsickleCompilerHost); + const errors = program.getOptionsDiagnostics(); check(errors); @@ -97,35 +115,16 @@ export function main( if (diagnostics) console.time('NG codegen'); return codegen(ngOptions, cliOptions, program, host).then(() => { if (diagnostics) console.timeEnd('NG codegen'); - let definitionsHost = host; + let definitionsHost: ts.CompilerHost = tsickleCompilerHost; if (!ngOptions.skipMetadataEmit) { - definitionsHost = new MetadataWriterHost(host, ngOptions); + definitionsHost = new MetadataWriterHost(tsickleCompilerHost, ngOptions); } // Create a new program since codegen files were created after making the old program let programWithCodegen = createProgram(definitionsHost, program); tsc.typeCheck(host, programWithCodegen); - let preprocessHost = host; let programForJsEmit = programWithCodegen; - - const tsickleCompilerHostOptions: tsickle.Options = { - googmodule: false, - untyped: true, - convertIndexImportShorthand: - ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too - }; - - const tsickleHost: tsickle.TsickleHost = { - shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName), - pathToModuleName: (context, importPath) => '', - shouldIgnoreWarningsForPath: (filePath) => false, - fileNameToModuleId: (fileName) => fileName, - }; - - const tsickleCompilerHost = new tsickle.TsickleCompilerHost( - preprocessHost, ngOptions, tsickleCompilerHostOptions, tsickleHost); - if (ngOptions.annotationsAs !== 'decorators') { if (diagnostics) console.time('NG downlevel'); tsickleCompilerHost.reconfigureForRun(programForJsEmit, tsickle.Pass.DECORATOR_DOWNLEVEL); @@ -133,7 +132,6 @@ export function main( // metadataWriter programForJsEmit = createProgram(tsickleCompilerHost); check(tsickleCompilerHost.diagnostics); - preprocessHost = tsickleCompilerHost; if (diagnostics) console.timeEnd('NG downlevel'); } diff --git a/tools/@angular/tsc-wrapped/test/main.spec.ts b/tools/@angular/tsc-wrapped/test/main.spec.ts index 0734acc2ee..b6132885a0 100644 --- a/tools/@angular/tsc-wrapped/test/main.spec.ts +++ b/tools/@angular/tsc-wrapped/test/main.spec.ts @@ -264,4 +264,35 @@ describe('tsc-wrapped', () => { }) .catch(e => done.fail(e)); }); + + it('should accept input source maps', (done) => { + write('tsconfig.json', `{ + "compilerOptions": { + "experimentalDecorators": true, + "types": [], + "outDir": "built", + "declaration": true, + "moduleResolution": "node", + "target": "es2015", + "sourceMap": true + }, + "angularCompilerOptions": { + "annotateForClosureCompiler": true + }, + "files": ["test.ts"] + }`); + // Provide a file called test.ts that has an inline source map + // which says that it was transpiled from a file other_test.ts + // with exactly the same content. + write('test.ts', `const x = 3; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm90aGVyX3Rlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxFQUFFLEVBQUUsQ0FBQyIsImZpbGUiOiIuLi90ZXN0LnRzIiwic291cmNlUm9vdCI6IiJ9`); + + main(basePath, {basePath}) + .then(() => { + const out = readOut('js.map'); + expect(out).toContain('"sources":["other_test.ts"]'); + done(); + }) + .catch(e => done.fail(e)); + }); });