Skip to content

ES6 modules for ES5 output #5806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pkozlowski-opensource opened this issue Nov 26, 2015 · 1 comment
Closed

ES6 modules for ES5 output #5806

pkozlowski-opensource opened this issue Nov 26, 2015 · 1 comment

Comments

@pkozlowski-opensource
Copy link

As of today specifying ES6 as a module format to transpile to with ES5 as a target will result in the "error TS1204: Cannot compile modules into 'es2015' when targeting 'ES5' or lower." error.

But having ES6 modules in the ES5 output would be beneficial for ES6-based tree-shakers like Rollup.

Currently one can ES5 output with ES6 modules by using ts.transpileModule(...) but the output is broken in some cases. For example transpiling:

ts.version // 1.7.4
ts.transpileModule('export class A {}', {
  compilerOptions: {
    target: ts.ScriptTarget.ES5,
    module: ts.ModuleKind.ES6
  }
})

yields:

var A = (function () {
    function A() {
    }
    return A;
})();
A = A;

Notice: A = A; which should probably be export { A };

In-depth discussion and more examples in rollup/rollup-plugin-typescript#9

Given the above I've got a question: do you plan to support ES6 modules for ES5 output? If not are you planning to provide a TS-specific tree-shaking bundler?

@pkozlowski-opensource
Copy link
Author

Oh, it looks like @Victorystick opened a similar #5790, closing this one as a duplicate and moving the discussion in there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant