Skip to content
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

Named re-exports tree shaking? #2193

Closed
HanabishiRecca opened this issue Apr 19, 2022 · 2 comments
Closed

Named re-exports tree shaking? #2193

HanabishiRecca opened this issue Apr 19, 2022 · 2 comments

Comments

@HanabishiRecca
Copy link

Sorry if the problem was already discussed, not found it here in the issues.

Example code:

index.js

import { submodule } from './lib';
submodule.foo();

lib.js

export * as submodule from './submodule';

submodule.js

export const foo = () => {};
export const bar = () => {};
export const baz = () => {};
export const whatever = () => {};

Output (--bundle --format=esm):

var __defProp = Object.defineProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};

// submodule.js
var submodule_exports = {};
__export(submodule_exports, {
  bar: () => bar,
  baz: () => baz,
  foo: () => foo,
  whatever: () => whatever
});
var foo = () => {
};
var bar = () => {
};
var baz = () => {
};
var whatever = () => {
};

// index.js
submodule_exports.foo();

I think you understand the problem here. Is it possible to eliminate the dead code?

@evanw
Copy link
Owner

evanw commented Apr 19, 2022

I believe this is a duplicate of #1420. Lack of tracking of exports through multiple levels of re-exports is a known limitation of esbuild. It's not possible to use esbuild to eliminate this as dead code.

@HanabishiRecca
Copy link
Author

Oops, indeed a duplicate. Thanks for the answer.

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

No branches or pull requests

2 participants