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)
This commit is contained in:
parent
535d9da6b6
commit
ea8a43def0
|
@ -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));
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue