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

Helper methods do not need to be export functions #9203

Closed
kdy1 opened this issue Jul 11, 2024 · 4 comments · Fixed by #9225
Closed

Helper methods do not need to be export functions #9203

kdy1 opened this issue Jul 11, 2024 · 4 comments · Fixed by #9225

Comments

@kdy1
Copy link
Member

kdy1 commented Jul 11, 2024

Describe the feature

_ export is enough, and we can rename them while exporting.

Babel plugin or link to the feature description

No response

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Jul 11, 2024
@kdy1 kdy1 self-assigned this Jul 11, 2024
@kdy1
Copy link
Member Author

kdy1 commented Jul 11, 2024

cc @magic-akari Is there a reason we use export function while we can use _?

@magic-akari
Copy link
Member

It is used only within helpers. We can retain only the _ name.

@kdy1
Copy link
Member Author

kdy1 commented Jul 12, 2024

Guide for GFI

You need to patch

modules.forEach((p) => {
const importBinding = p.slice(0, -3);
main_package_json.exports[`./_/${importBinding}`] = {
import: `./esm/${importBinding}.js`,
default: `./cjs/${importBinding}.cjs`,
};
const alias_package = {
main: `../../cjs/${importBinding}.cjs`,
module: `../../esm/${importBinding}.js`,
};
task_queue.push(
fs.outputJSON(root("_", importBinding, "package.json"), alias_package, {
encoding: "utf-8",
spaces: 4,
}),
);
if (importBinding === "index") {
return;
}
task_queue.push(
fs.outputFile(root("src", `${importBinding}.mjs`), re_export_esm(importBinding), {
encoding: "utf-8",
}),
);
indexESM.push(`export { ${importBinding} } from "./${importBinding}.js";`);
cjs_module_lexer.push(`${importBinding}: null,`);
cjs_export_list.push(`get ${importBinding}() {
return require("./${importBinding}.cjs")._;
},`);
});
to use _ as the original name for re-export.

After then, you can patch files like https://github.com/swc-project/swc/blob/260f806d3e2a8350864c6e751949566f6a9654ff/packages/helpers/esm/_apply_decorated_descriptor.js to export only _

@swc-bot
Copy link
Collaborator

swc-bot commented Aug 17, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

3 participants