From 8cd9113d3b314743537cab88b3429ed1a1c823cb Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 12 Jan 2017 17:33:44 -0800 Subject: [PATCH] feature(tsc-wrapped): re-write /index imports for closure compiler (#13471) --- tools/@angular/tsc-wrapped/src/compiler_host.ts | 7 ++++--- tools/@angular/tsc-wrapped/test/main.spec.ts | 13 ++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/@angular/tsc-wrapped/src/compiler_host.ts b/tools/@angular/tsc-wrapped/src/compiler_host.ts index 6afcb127eeb39..a7ff069a933f3 100644 --- a/tools/@angular/tsc-wrapped/src/compiler_host.ts +++ b/tools/@angular/tsc-wrapped/src/compiler_host.ts @@ -99,9 +99,10 @@ export class TsickleCompilerHost extends DelegatingHost { // Don't tsickle-process any d.ts that isn't a compilation target; // this means we don't process e.g. lib.d.ts. if (isDefinitions) return sourceFile; - - let {output, externs, diagnostics} = - tsickle.annotate(this.oldProgram, sourceFile, {untyped: true}); + const es2015Target = this.options.target == ts.ScriptTarget.ES2015; // This covers ES6 too + let {output, externs, diagnostics} = tsickle.annotate( + this.oldProgram, sourceFile, {untyped: true, convertIndexImportShorthand: es2015Target}, + this.delegate, this.options); this.diagnostics = diagnostics; return ts.createSourceFile(fileName, output, languageVersion, true); } diff --git a/tools/@angular/tsc-wrapped/test/main.spec.ts b/tools/@angular/tsc-wrapped/test/main.spec.ts index a9f925f91f53b..0a47a813abdeb 100644 --- a/tools/@angular/tsc-wrapped/test/main.spec.ts +++ b/tools/@angular/tsc-wrapped/test/main.spec.ts @@ -23,7 +23,8 @@ describe('tsc-wrapped', () => { fs.writeFileSync(path.join(basePath, fileName), content, {encoding: 'utf-8'}); }; 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 B = 2; `); @@ -59,7 +60,8 @@ describe('tsc-wrapped', () => { "types": [], "outDir": "built", "declaration": true, - "module": "es2015" + "moduleResolution": "node", + "target": "es2015" }, "angularCompilerOptions": { "annotateForClosureCompiler": true @@ -72,8 +74,8 @@ describe('tsc-wrapped', () => { const out = readOut('js'); // No helpers since decorators were lowered expect(out).not.toContain('__decorate'); - // Expand `export *` - expect(out).toContain('export { A, B }'); + // Expand `export *` and fix index import + expect(out).toContain(`export { A, B } from './dep/index'`); // Annotated for Closure compiler expect(out).toContain('* @param {?} x'); // Comments should stay multi-line @@ -96,7 +98,8 @@ describe('tsc-wrapped', () => { "types": [], "outDir": "built", "declaration": false, - "module": "es2015" + "module": "es2015", + "moduleResolution": "node" }, "angularCompilerOptions": { "annotateForClosureCompiler": false,