aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ModuleLoader.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-05-29 11:23:10 -0700
committerGravatar GitHub <noreply@github.com> 2023-05-29 11:23:10 -0700
commite2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9 (patch)
tree219ad30067db8641999811b67744ce665f45dd46 /src/bun.js/bindings/ModuleLoader.cpp
parent2b04ef4fae088b6f39628da312643cf4c54921ad (diff)
downloadbun-e2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9.tar.gz
bun-e2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9.tar.zst
bun-e2de1f5c133ed3aac6fcea7e8e7c5fcd771d65f9.zip
Natively support CommonJS at runtime (#3104)
* Natively support CommonJS at runtime * cleanup how getters are handled, add fast path * more consistent with node * use * As * Remove thrown modules on exception * Handle exception better --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/ModuleLoader.cpp')
-rw-r--r--src/bun.js/bindings/ModuleLoader.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/bun.js/bindings/ModuleLoader.cpp b/src/bun.js/bindings/ModuleLoader.cpp
index 75981f5b3..f4e96130b 100644
--- a/src/bun.js/bindings/ModuleLoader.cpp
+++ b/src/bun.js/bindings/ModuleLoader.cpp
@@ -35,6 +35,7 @@
#include "../modules/NodeModuleModule.h"
#include "../modules/TTYModule.h"
#include "node_util_types.h"
+#include "CommonJSModuleRecord.h"
namespace Bun {
using namespace Zig;
@@ -475,6 +476,11 @@ static JSValue fetchSourceCode(
Bun__transpileFile(bunVM, globalObject, specifier, referrer, res, false);
}
+ if (res->success && res->result.value.commonJSExportsLen) {
+ auto source = Bun::createCommonJSModule(globalObject, res->result.value);
+ return rejectOrResolve(JSSourceCode::create(vm, WTFMove(source)));
+ }
+
if (!res->success) {
throwException(scope, res->result.err, globalObject);
auto* exception = scope.exception();