microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.15k stars 12.51k forks source link

BUG: Dynamic import with concatenation generates invalid javascript #18040

Closed kukjevov closed 7 years ago

kukjevov commented 7 years ago

TypeScript Version: 2.4.2 / nightly (2.5.0-dev.201xxxxx)

Code

Dynamic import with concatenation generates invalid code.

If you have in typescript this code

import('./dynamicFolder/dynamic').then(all => console.log(all));

it will generate this javascript

import('./dynamicFolder/dynamic').then(function (all) { return console.log(all); });

but if you make it more dynamic by doing this

const dyn = "dynamic";
import(`./dynamicFolder/${dyn}`).then(all => console.log(all));

it will generate this javascript

(import)("./dynamicFolder/" + dyn).then(function (all) { return console.log(all); });

see https://github.com/webpack/webpack/issues/5568 Here is reproduction so you can see it. https://github.com/kukjevov/dynamic-import

Any suggestions?

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

Expected behavior:

It should generate same import statement, because now it cant be used with webpack.

Actual behavior:

ikatyang commented 7 years ago

Duplicate of #16763, should be fixed by #17025 (v2.5).

kukjevov commented 7 years ago

Ok looks same :)