feature(tsc-wrapped): re-write /index imports for closure compiler (#13471)

This commit is contained in:
Alex Eagle 2017-01-12 17:33:44 -08:00 committed by Miško Hevery
parent b1e3dda5cb
commit 5047d9780d
2 changed files with 12 additions and 8 deletions

View File

@ -99,9 +99,10 @@ export class TsickleCompilerHost extends DelegatingHost {
// Don't tsickle-process any d.ts that isn't a compilation target; // Don't tsickle-process any d.ts that isn't a compilation target;
// this means we don't process e.g. lib.d.ts. // this means we don't process e.g. lib.d.ts.
if (isDefinitions) return sourceFile; if (isDefinitions) return sourceFile;
const es2015Target = this.options.target == ts.ScriptTarget.ES2015; // This covers ES6 too
let {output, externs, diagnostics} = let {output, externs, diagnostics} = tsickle.annotate(
tsickle.annotate(this.oldProgram, sourceFile, {untyped: true}); this.oldProgram, sourceFile, {untyped: true, convertIndexImportShorthand: es2015Target},
this.delegate, this.options);
this.diagnostics = diagnostics; this.diagnostics = diagnostics;
return ts.createSourceFile(fileName, output, languageVersion, true); return ts.createSourceFile(fileName, output, languageVersion, true);
} }

View File

@ -23,7 +23,8 @@ describe('tsc-wrapped', () => {
fs.writeFileSync(path.join(basePath, fileName), content, {encoding: 'utf-8'}); fs.writeFileSync(path.join(basePath, fileName), content, {encoding: 'utf-8'});
}; };
write('decorators.ts', '/** @Annotation */ export var Component: Function;'); write('decorators.ts', '/** @Annotation */ export var Component: Function;');
write('dep.ts', ` fs.mkdirSync(path.join(basePath, 'dep'));
write('dep/index.ts', `
export const A = 1; export const A = 1;
export const B = 2; export const B = 2;
`); `);
@ -59,7 +60,8 @@ describe('tsc-wrapped', () => {
"types": [], "types": [],
"outDir": "built", "outDir": "built",
"declaration": true, "declaration": true,
"module": "es2015" "moduleResolution": "node",
"target": "es2015"
}, },
"angularCompilerOptions": { "angularCompilerOptions": {
"annotateForClosureCompiler": true "annotateForClosureCompiler": true
@ -72,8 +74,8 @@ describe('tsc-wrapped', () => {
const out = readOut('js'); const out = readOut('js');
// No helpers since decorators were lowered // No helpers since decorators were lowered
expect(out).not.toContain('__decorate'); expect(out).not.toContain('__decorate');
// Expand `export *` // Expand `export *` and fix index import
expect(out).toContain('export { A, B }'); expect(out).toContain(`export { A, B } from './dep/index'`);
// Annotated for Closure compiler // Annotated for Closure compiler
expect(out).toContain('* @param {?} x'); expect(out).toContain('* @param {?} x');
// Comments should stay multi-line // Comments should stay multi-line
@ -96,7 +98,8 @@ describe('tsc-wrapped', () => {
"types": [], "types": [],
"outDir": "built", "outDir": "built",
"declaration": false, "declaration": false,
"module": "es2015" "module": "es2015",
"moduleResolution": "node"
}, },
"angularCompilerOptions": { "angularCompilerOptions": {
"annotateForClosureCompiler": false, "annotateForClosureCompiler": false,