Skip to content

Commit ea8a43d

Browse files
devversionvicb
authored andcommitted
feat(tsc-wrapped): always convert shorthand imports (#16898)
Now converts shorthand imports for every TypeScript target. Tsickle is able to expand index shorthand imports for every TypeScript target and module possibility. Expanding shorthand imports for CommonJS modules is also helpful when testing in the browser. Module loaders like SystemJS are not able to understand directory imports (or index shorthand imports)
1 parent 535d9da commit ea8a43d

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,8 @@ export function main(
9999
addGeneratedFileName(name);
100100
}
101101

102-
const tsickleCompilerHostOptions: tsickle.Options = {
103-
googmodule: false,
104-
untyped: true,
105-
convertIndexImportShorthand:
106-
ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too
107-
};
102+
const tsickleCompilerHostOptions:
103+
tsickle.Options = {googmodule: false, untyped: true, convertIndexImportShorthand: true};
108104

109105
const tsickleHost: tsickle.TsickleHost = {
110106
shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName),

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,57 @@ describe('tsc-wrapped', () => {
366366
})
367367
.catch(e => done.fail(e));
368368
});
369+
370+
it('should expand shorthand imports for ES2015 modules', (done) => {
371+
write('tsconfig.json', `{
372+
"compilerOptions": {
373+
"experimentalDecorators": true,
374+
"types": [],
375+
"outDir": "built",
376+
"declaration": true,
377+
"moduleResolution": "node",
378+
"target": "es2015",
379+
"module": "es2015"
380+
},
381+
"angularCompilerOptions": {
382+
"annotateForClosureCompiler": true
383+
},
384+
"files": ["test.ts"]
385+
}`);
386+
387+
main(basePath, {basePath})
388+
.then(() => {
389+
const fileOutput = readOut('js');
390+
expect(fileOutput).toContain(`export { A, B } from './dep/index'`);
391+
done();
392+
})
393+
.catch(e => done.fail(e));
394+
});
395+
396+
it('should expand shorthand imports for ES5 CommonJS modules', (done) => {
397+
write('tsconfig.json', `{
398+
"compilerOptions": {
399+
"experimentalDecorators": true,
400+
"types": [],
401+
"outDir": "built",
402+
"declaration": true,
403+
"moduleResolution": "node",
404+
"target": "es5",
405+
"module": "commonjs"
406+
},
407+
"angularCompilerOptions": {
408+
"annotateForClosureCompiler": true
409+
},
410+
"files": ["test.ts"]
411+
}`);
412+
413+
main(basePath, {basePath})
414+
.then(() => {
415+
const fileOutput = readOut('js');
416+
expect(fileOutput).toContain(`var index_1 = require("./dep/index");`);
417+
done();
418+
})
419+
.catch(e => done.fail(e));
420+
});
421+
369422
});

0 commit comments

Comments
 (0)