Permalink
Browse files

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)
  • Loading branch information...
DevVersion authored and vicb committed May 30, 2017
1 parent 535d9da commit ea8a43def0d8e6da19cc9fad9c00d37014c332d2
Showing with 55 additions and 6 deletions.
  1. +2 −6 tools/@angular/tsc-wrapped/src/main.ts
  2. +53 −0 tools/@angular/tsc-wrapped/test/main.spec.ts
@@ -99,12 +99,8 @@ export function main(
addGeneratedFileName(name);
}
const tsickleCompilerHostOptions: tsickle.Options = {
googmodule: false,
untyped: true,
convertIndexImportShorthand:
ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too
};
const tsickleCompilerHostOptions:
tsickle.Options = {googmodule: false, untyped: true, convertIndexImportShorthand: true};
const tsickleHost: tsickle.TsickleHost = {
shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName),
@@ -366,4 +366,57 @@ describe('tsc-wrapped', () => {
})
.catch(e => done.fail(e));
});
it('should expand shorthand imports for ES2015 modules', (done) => {
write('tsconfig.json', `{
"compilerOptions": {
"experimentalDecorators": true,
"types": [],
"outDir": "built",
"declaration": true,
"moduleResolution": "node",
"target": "es2015",
"module": "es2015"
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true
},
"files": ["test.ts"]
}`);
main(basePath, {basePath})
.then(() => {
const fileOutput = readOut('js');
expect(fileOutput).toContain(`export { A, B } from './dep/index'`);
done();
})
.catch(e => done.fail(e));
});
it('should expand shorthand imports for ES5 CommonJS modules', (done) => {
write('tsconfig.json', `{
"compilerOptions": {
"experimentalDecorators": true,
"types": [],
"outDir": "built",
"declaration": true,
"moduleResolution": "node",
"target": "es5",
"module": "commonjs"
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true
},
"files": ["test.ts"]
}`);
main(basePath, {basePath})
.then(() => {
const fileOutput = readOut('js');
expect(fileOutput).toContain(`var index_1 = require("./dep/index");`);
done();
})
.catch(e => done.fail(e));
});
});

0 comments on commit ea8a43d

Please sign in to comment.