aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-08-08 19:37:36 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-08 19:37:36 -0700
commit1941dbbd71c6d6730ca78b21ef2fd20f51124950 (patch)
tree3ac2c26307fcdd2beafff8131218c7c8861e9eda
parent320cdcf97e549c45ab50bbbc3c415dc011260f20 (diff)
downloadbun-1941dbbd71c6d6730ca78b21ef2fd20f51124950.tar.gz
bun-1941dbbd71c6d6730ca78b21ef2fd20f51124950.tar.zst
bun-1941dbbd71c6d6730ca78b21ef2fd20f51124950.zip
Set exports to {} in user-constructed CommonJSModuleRecords (#4076)
-rw-r--r--src/bun.js/modules/NodeModuleModule.h4
-rw-r--r--test/js/node/module/node-module-module.test.js5
2 files changed, 8 insertions, 1 deletions
diff --git a/src/bun.js/modules/NodeModuleModule.h b/src/bun.js/modules/NodeModuleModule.h
index 0be647c39..7c8f6ee14 100644
--- a/src/bun.js/modules/NodeModuleModule.h
+++ b/src/bun.js/modules/NodeModuleModule.h
@@ -138,6 +138,10 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeModuleModuleConstructor,
out->putDirect(vm, JSC::Identifier::fromString(vm, "parent"_s), parentValue,
0);
+ out->putDirect(vm, JSC::Identifier::fromString(vm, "exports"_s),
+ JSC::constructEmptyObject(globalObject,
+ globalObject->objectPrototype(), 0),
+ 0);
return JSValue::encode(out);
}
diff --git a/test/js/node/module/node-module-module.test.js b/test/js/node/module/node-module-module.test.js
index 58a81fb98..08955a7b7 100644
--- a/test/js/node/module/node-module-module.test.js
+++ b/test/js/node/module/node-module-module.test.js
@@ -26,8 +26,11 @@ test("Module exists", () => {
expect(Module).toBeDefined();
});
-test("module.Module exists", () => {
+test("module.Module works", () => {
expect(Module.Module === Module).toBeTrue();
+
+ const m = new Module("asdf");
+ expect(m.exports).toEqual({});
});
test("_nodeModulePaths() works", () => {