Skip to content

Commit 5047d97

Browse files
alexeaglemhevery
authored andcommitted
feature(tsc-wrapped): re-write /index imports for closure compiler (angular#13471)
1 parent b1e3dda commit 5047d97

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

tools/@angular/tsc-wrapped/src/compiler_host.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ export class TsickleCompilerHost extends DelegatingHost {
9999
// Don't tsickle-process any d.ts that isn't a compilation target;
100100
// this means we don't process e.g. lib.d.ts.
101101
if (isDefinitions) return sourceFile;
102-
103-
let {output, externs, diagnostics} =
104-
tsickle.annotate(this.oldProgram, sourceFile, {untyped: true});
102+
const es2015Target = this.options.target == ts.ScriptTarget.ES2015; // This covers ES6 too
103+
let {output, externs, diagnostics} = tsickle.annotate(
104+
this.oldProgram, sourceFile, {untyped: true, convertIndexImportShorthand: es2015Target},
105+
this.delegate, this.options);
105106
this.diagnostics = diagnostics;
106107
return ts.createSourceFile(fileName, output, languageVersion, true);
107108
}

tools/@angular/tsc-wrapped/test/main.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe('tsc-wrapped', () => {
2323
fs.writeFileSync(path.join(basePath, fileName), content, {encoding: 'utf-8'});
2424
};
2525
write('decorators.ts', '/** @Annotation */ export var Component: Function;');
26-
write('dep.ts', `
26+
fs.mkdirSync(path.join(basePath, 'dep'));
27+
write('dep/index.ts', `
2728
export const A = 1;
2829
export const B = 2;
2930
`);
@@ -59,7 +60,8 @@ describe('tsc-wrapped', () => {
5960
"types": [],
6061
"outDir": "built",
6162
"declaration": true,
62-
"module": "es2015"
63+
"moduleResolution": "node",
64+
"target": "es2015"
6365
},
6466
"angularCompilerOptions": {
6567
"annotateForClosureCompiler": true
@@ -72,8 +74,8 @@ describe('tsc-wrapped', () => {
7274
const out = readOut('js');
7375
// No helpers since decorators were lowered
7476
expect(out).not.toContain('__decorate');
75-
// Expand `export *`
76-
expect(out).toContain('export { A, B }');
77+
// Expand `export *` and fix index import
78+
expect(out).toContain(`export { A, B } from './dep/index'`);
7779
// Annotated for Closure compiler
7880
expect(out).toContain('* @param {?} x');
7981
// Comments should stay multi-line
@@ -96,7 +98,8 @@ describe('tsc-wrapped', () => {
9698
"types": [],
9799
"outDir": "built",
98100
"declaration": false,
99-
"module": "es2015"
101+
"module": "es2015",
102+
"moduleResolution": "node"
100103
},
101104
"angularCompilerOptions": {
102105
"annotateForClosureCompiler": false,

0 commit comments

Comments
 (0)