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

Support "syntheticNamedExports"? #1919

Closed
hyrious opened this issue Jan 7, 2022 · 3 comments
Closed

Support "syntheticNamedExports"? #1919

hyrious opened this issue Jan 7, 2022 · 3 comments

Comments

@hyrious
Copy link

hyrious commented Jan 7, 2022

It is about importing named exports from commonjs modules, similar to this rollup feature.

// a.js, with { syntheticNamedExports: '__exports' } info
var foo = 1
var __exports = { bar: 2 }
export { foo, __exports }
// main.js
import { foo, bar, buzz } from "./a.js"
foo  // 1
bar  // 2, equal to __exports['bar']
buzz // undefined, equal to __exports['buzz']

It's good to know if you plan to support this feature, or as non-goal.

@evanw
Copy link
Owner

evanw commented Jan 7, 2022

No, I'm not planning on supporting that feature at the moment. That's not how the JavaScript specification works and esbuild tries to follow the specification. Note that esbuild's bundler already supports importing named exports from CommonJS modules without needing a mechanism like this.

@hyrious
Copy link
Author

hyrious commented Jan 7, 2022

Yes esbuild can bundle cjs module with named imports, with the downside of no tree-shaking on the cjs modules. This feature allows to mark a named export in es module as "module.exports", so that the input are all esm and tree-shaking still happens.

Rollup made this to support re-export in its commonjs plugin, so that it doesn't have to analyse too deep. I recently tried to repeat that plugin in esbuild and find that it requires such feature to be enabled in plugin side.

Anyway, it's ok if you're not planning to support it.

@evanw
Copy link
Owner

evanw commented Feb 16, 2022

Closing as out of scope.

@evanw evanw closed this as completed Feb 16, 2022
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