Skip to content

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

Merged
nicolo-ribaudo merged 4 commits intobabel:mainfrom
magic-akari:fix/issue-16014
Oct 13, 2023
Merged

fix: handle __proto__ exports name in CJS/AMD/UMD#16015
nicolo-ribaudo merged 4 commits intobabel:mainfrom
magic-akari:fix/issue-16014

Conversation

@magic-akari
Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread packages/babel-helper-module-transforms/src/index.ts Outdated
@liuxingbaoyu
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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