-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix(es/module): Improve compatibility with cjs-module-lexer
#5835
Conversation
Why is this required? Do you have any real-world usecase related to this? |
Sometimes you need CommonJS while allowing them to be imported into node esm.
There are two issues about compatibility with
The following code will output // page.js
export const page = "page"; // app.js
export * from "./page.js";
export const app = "app"; // index.js
import { app, page } from "./app.js";
console.log(app, page); When compiling We emit This is similar to the way used by esbuild.
Take the same example as above, we will get the following transformed code. Object.defineProperty(exports, "page", {
enumerable: true,
get: ()=>page
}); Once https://github.com/nodejs/cjs-module-lexer/blob/4641ae5419634deeefa41f943080f2eb7b2c925e/src/lexer.c#L442-L444
We need to change the output to a method/function getter until |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense, thanks!
swc-bump:
- swc_ecma_transforms_module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automated review comment generated by auto-rebase script
Description:
Support reexport by emitting TS
__export
function call.BREAKING CHANGE:
Related issue (if exists):