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

fix: handle __proto__ exports name in CJS/AMD/UMD #16015

Merged
merged 4 commits into from Oct 13, 2023
Merged

fix: handle __proto__ exports name in CJS/AMD/UMD #16015

merged 4 commits into from Oct 13, 2023

Conversation

magic-akari
Copy link
Contributor

Q                       A
Fixed Issues? Fixes #16014
Patch: Bug Fix? 👍
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 1, 2023

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/55663/

@magic-akari magic-akari changed the title fix: handle __proto__ exports name in CommonJS fix: handle __proto__ exports name in CJS/AMD/UMD Oct 1, 2023
@liuxingbaoyu
Copy link
Member

liuxingbaoyu commented Oct 2, 2023

This doesn't seem to be detected as an ESM-available named export in nodejs. 🤦‍♂️
it only accepts

Object.defineProperty(exports, "__proto__", {
   enumerable: true,
   value: void 0
})
Object.defineProperty(exports, "__proto__", {
   value: void 0
})
exports.__proto__ = void 0

run in browser

const { init, parse } = await import(
  "https://cdn.skypack.dev/cjs-module-lexer"
);
await init();
const code = `
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.a = Object.defineProperty(exports, "__proto__", {
  enumerable: true,
  writable: true,
  value: void 0
})["__proto__"] = exports._ = void 0;
var _input = require("./input.js");
const __proto__ = exports.__proto__ = null;
const a = exports.a = 1;
const _ = exports._ = 2;
console.log(_input.__proto__);
`;

console.log(parse(code));

@magic-akari
Copy link
Contributor Author

I will update the template.
I think the following codes will work

Object.defineProperty(exports, "__proto__", {
  enumerable: true,
  value: void 0,
  writable: true
})["__proto__"]

Copy link
Member

@liuxingbaoyu liuxingbaoyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@liuxingbaoyu liuxingbaoyu added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Oct 2, 2023
@nicolo-ribaudo nicolo-ribaudo merged commit 418dd21 into babel:main Oct 13, 2023
46 checks passed
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 30, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Wrong export value of __proto__ in CommonJS
5 participants