aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/api/JSBundler.zig5
-rw-r--r--test/bundler/build.test.ts10
2 files changed, 15 insertions, 0 deletions
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig
index c95c359f1..741d956bf 100644
--- a/src/bun.js/api/JSBundler.zig
+++ b/src/bun.js/api/JSBundler.zig
@@ -494,6 +494,11 @@ pub const JSBundler = struct {
globalThis: *JSC.JSGlobalObject,
arguments: []const JSC.JSValue,
) JSC.JSValue {
+ if (arguments.len == 0 or !arguments[0].isObject()) {
+ globalThis.throwInvalidArguments("Expected a config object to be passed to Bun.build", .{});
+ return JSC.JSValue.jsUndefined();
+ }
+
var plugins: ?*Plugin = null;
const config = Config.fromJS(globalThis, arguments[0], &plugins, globalThis.allocator()) catch {
return JSC.JSValue.jsUndefined();
diff --git a/test/bundler/build.test.ts b/test/bundler/build.test.ts
index 054f24bc3..921481a4b 100644
--- a/test/bundler/build.test.ts
+++ b/test/bundler/build.test.ts
@@ -4,6 +4,16 @@ import { bunEnv, bunExe } from "harness";
import { join } from "path";
describe("Bun.build", () => {
+ test("passing undefined doesnt segfault", () => {
+ try {
+ // @ts-ignore
+ Bun.build();
+ } catch (error) {
+ return;
+ }
+ throw new Error("should have thrown");
+ });
+
test("invalid options throws", async () => {
expect(() => Bun.build({} as any)).toThrow();
expect(() =>