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 |
kdy1
left a comment
There was a problem hiding this comment.
It makes sense, thanks!
swc-bump:
- swc_ecma_transforms_module
swc-bot
left a comment
There was a problem hiding this comment.
Automated review comment generated by auto-rebase script
Description:
Support reexport by emitting TS
__exportfunction call.BREAKING CHANGE:
Related issue (if exists):