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.
This commit is contained in:
Lucas Sloan 2017-02-22 13:11:15 -08:00 committed by Chuck Jazdzewski
parent 49764a5bff
commit 5c0ea20bd0
2 changed files with 52 additions and 23 deletions

View File

@ -86,29 +86,6 @@ export function main(
parsed.fileNames.push(name); parsed.fileNames.push(name);
} }
const program = createProgram(host);
const errors = program.getOptionsDiagnostics();
check(errors);
if (ngOptions.skipTemplateCodegen || !codegen) {
codegen = () => Promise.resolve(null);
}
if (diagnostics) console.time('NG codegen');
return codegen(ngOptions, cliOptions, program, host).then(() => {
if (diagnostics) console.timeEnd('NG codegen');
let definitionsHost = host;
if (!ngOptions.skipMetadataEmit) {
definitionsHost = new MetadataWriterHost(host, 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 = { const tsickleCompilerHostOptions: tsickle.Options = {
googmodule: false, googmodule: false,
untyped: true, untyped: true,
@ -123,8 +100,30 @@ export function main(
fileNameToModuleId: (fileName) => fileName, fileNameToModuleId: (fileName) => fileName,
}; };
const tsickleCompilerHost = new tsickle.TsickleCompilerHost( const tsickleCompilerHost =
preprocessHost, ngOptions, tsickleCompilerHostOptions, tsickleHost); new tsickle.TsickleCompilerHost(host, ngOptions, tsickleCompilerHostOptions, tsickleHost);
const program = createProgram(tsickleCompilerHost);
const errors = program.getOptionsDiagnostics();
check(errors);
if (ngOptions.skipTemplateCodegen || !codegen) {
codegen = () => Promise.resolve(null);
}
if (diagnostics) console.time('NG codegen');
return codegen(ngOptions, cliOptions, program, host).then(() => {
if (diagnostics) console.timeEnd('NG codegen');
let definitionsHost: ts.CompilerHost = tsickleCompilerHost;
if (!ngOptions.skipMetadataEmit) {
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 programForJsEmit = programWithCodegen;
if (ngOptions.annotationsAs !== 'decorators') { if (ngOptions.annotationsAs !== 'decorators') {
if (diagnostics) console.time('NG downlevel'); if (diagnostics) console.time('NG downlevel');
@ -133,7 +132,6 @@ export function main(
// metadataWriter // metadataWriter
programForJsEmit = createProgram(tsickleCompilerHost); programForJsEmit = createProgram(tsickleCompilerHost);
check(tsickleCompilerHost.diagnostics); check(tsickleCompilerHost.diagnostics);
preprocessHost = tsickleCompilerHost;
if (diagnostics) console.timeEnd('NG downlevel'); if (diagnostics) console.timeEnd('NG downlevel');
} }

View File

@ -264,4 +264,35 @@ describe('tsc-wrapped', () => {
}) })
.catch(e => done.fail(e)); .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));
});
}); });