GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — esm: fix module.exports export on CJS modules · nodejs/node@5c20dcc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/modules/esm
    • translators.js
  • test/fixtures/es-modules
    • exports-cases.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/modules/esm/translators.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/translators.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,13 @@ function createCJSModuleWrap(url, source, isMain, format, loadCJS = loadCJSModul
188188
const { exportNames, module } = cjsPreparseModuleExports(filename, source, format);
189189
cjsCache.set(url, module);
190190

191-
const wrapperNames = [...exportNames, 'module.exports'];
191+
const wrapperNames = [...exportNames];
192192
if (!exportNames.has('default')) {
193193
ArrayPrototypePush(wrapperNames, 'default');
194194
}
195+
if (!exportNames.has('module.exports')) {
196+
ArrayPrototypePush(wrapperNames, 'module.exports');
197+
}
195198

196199
if (isMain) {
197200
setOwnProperty(process, 'mainModule', module);
@@ -212,7 +215,8 @@ function createCJSModuleWrap(url, source, isMain, format, loadCJS = loadCJSModul
212215
({ exports } = module);
213216
}
214217
for (const exportName of exportNames) {
215-
if (!ObjectPrototypeHasOwnProperty(exports, exportName) || exportName === 'default') {
218+
if (exportName === 'default' || exportName === 'module.exports' ||
219+
!ObjectPrototypeHasOwnProperty(exports, exportName)) {
216220
continue;
217221
}
218222
// We might trigger a getter -> dont fail.
Collapse file

‎test/fixtures/es-modules/exports-cases.js‎

Copy file name to clipboard
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
if (global.maybe)
2-
module.exports = require('../is-object');
3-
exports['invalid identifier'] = 'yes';
4-
module.exports['?invalid'] = 'yes';
5-
module.exports['π'] = 'yes';
6-
exports['\u{D83C}'] = 'no';
7-
exports['\u{D83C}\u{DF10}'] = 'yes';
8-
exports.package = 10; // reserved word
9-
Object.defineProperty(exports, 'z', { value: 'yes' });
1+
if (global.maybe)
2+
module.exports = require('../is-object');
3+
exports['invalid identifier'] = 'yes';
4+
module.exports['?invalid'] = 'yes';
5+
module.exports['π'] = 'yes';
6+
exports['\u{D83C}'] = 'no';
7+
exports['\u{D83C}\u{DF10}'] = 'yes';
8+
exports.package = 10; // reserved word
9+
Object.defineProperty(exports, 'z', { value: 'yes' });
10+
exports['module.exports'] = 5;

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.