GeezerVison is showing github.com — esm: fix module.exports export on CJS modules · nodejs/node@5c20dcc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/translators.js +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -188,10 +188,13 @@ function createCJSModuleWrap(url, source, isMain, format, loadCJS = loadCJSModul | 188 | 188 | const { exportNames, module } = cjsPreparseModuleExports(filename, source, format); | 189 | 189 | cjsCache.set(url, module); | 190 | 190 |
| 191 | | - const wrapperNames = [...exportNames, 'module.exports']; | | 191 | + const wrapperNames = [...exportNames]; | 192 | 192 | if (!exportNames.has('default')) { | 193 | 193 | ArrayPrototypePush(wrapperNames, 'default'); | 194 | 194 | } | | 195 | + if (!exportNames.has('module.exports')) { | | 196 | + ArrayPrototypePush(wrapperNames, 'module.exports'); | | 197 | + } | 195 | 198 |
| 196 | 199 | if (isMain) { | 197 | 200 | setOwnProperty(process, 'mainModule', module); | @@ -212,7 +215,8 @@ function createCJSModuleWrap(url, source, isMain, format, loadCJS = loadCJSModul | 212 | 215 | ({ exports } = module); | 213 | 216 | } | 214 | 217 | for (const exportName of exportNames) { | 215 | | - if (!ObjectPrototypeHasOwnProperty(exports, exportName) || exportName === 'default') { | | 218 | + if (exportName === 'default' || exportName === 'module.exports' || | | 219 | + !ObjectPrototypeHasOwnProperty(exports, exportName)) { | 216 | 220 | continue; | 217 | 221 | } | 218 | 222 | // We might trigger a getter -> dont fail. | |
Collapse file Copy file name to clipboard +10-9Lines changed: 10 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 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; |
|