Skip to content

Commit

Permalink
feature(tsc-wrapped): re-write /index imports for closure compiler (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored and juleskremer committed Aug 24, 2017
1 parent 3fec636 commit 8cd9113
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions tools/@angular/tsc-wrapped/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 8 additions & 5 deletions tools/@angular/tsc-wrapped/test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
`);
Expand Down Expand Up @@ -59,7 +60,8 @@ describe('tsc-wrapped', () => {
"types": [],
"outDir": "built",
"declaration": true,
"module": "es2015"
"moduleResolution": "node",
"target": "es2015"
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true
Expand All @@ -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
Expand All @@ -96,7 +98,8 @@ describe('tsc-wrapped', () => {
"types": [],
"outDir": "built",
"declaration": false,
"module": "es2015"
"module": "es2015",
"moduleResolution": "node"
},
"angularCompilerOptions": {
"annotateForClosureCompiler": false,
Expand Down

0 comments on commit 8cd9113

Please sign in to comment.