aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-04-29 00:08:48 -0400
committerGravatar GitHub <noreply@github.com> 2023-04-28 21:08:48 -0700
commit96e113f41c0dae1ccd58c6d1e3b6dd2c54769636 (patch)
tree1f8c0b88d2daa925abff610f4a458d744bc0bf36 /src/bun.js
parentbc0c0f7d203567a5538f271a3bc37c450eeaee46 (diff)
downloadbun-96e113f41c0dae1ccd58c6d1e3b6dd2c54769636.tar.gz
bun-96e113f41c0dae1ccd58c6d1e3b6dd2c54769636.tar.zst
bun-96e113f41c0dae1ccd58c6d1e3b6dd2c54769636.zip
bundler tests: rest of default.test.ts and starting jsx tests (#2765)
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/JSBundler.zig14
-rw-r--r--src/bun.js/api/JSTranspiler.zig12
-rw-r--r--src/bun.js/builtins/cpp/BundlerPluginBuiltins.cpp22
-rw-r--r--src/bun.js/builtins/js/BundlerPlugin.js20
-rw-r--r--src/bun.js/config.zig2
-rw-r--r--src/bun.js/javascript.zig4
6 files changed, 53 insertions, 21 deletions
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig
index 1c774e1f4..022c83cb4 100644
--- a/src/bun.js/api/JSBundler.zig
+++ b/src/bun.js/api/JSBundler.zig
@@ -32,7 +32,7 @@ const TSConfigJSON = @import("../../resolver/tsconfig_json.zig").TSConfigJSON;
const PackageJSON = @import("../../resolver/package_json.zig").PackageJSON;
const logger = bun.logger;
const Loader = options.Loader;
-const Platform = options.Platform;
+const Target = options.Target;
const JSAst = bun.JSAst;
const JSParser = bun.js_parser;
const JSPrinter = bun.js_printer;
@@ -47,7 +47,7 @@ pub const JSBundler = struct {
const OwnedString = bun.MutableString;
pub const Config = struct {
- target: options.Platform = options.Platform.browser,
+ target: Target = Target.browser,
entry_points: bun.StringSet = bun.StringSet.init(bun.default_allocator),
hot: bool = false,
define: bun.StringMap = bun.StringMap.init(bun.default_allocator, true),
@@ -84,7 +84,7 @@ pub const JSBundler = struct {
errdefer this.deinit(allocator);
errdefer if (plugins.*) |plugin| plugin.deinit();
- if (try config.getOptionalEnum(globalThis, "target", options.Platform)) |target| {
+ if (try config.getOptionalEnum(globalThis, "target", options.Target)) |target| {
this.target = target;
}
@@ -175,7 +175,7 @@ pub const JSBundler = struct {
this.names.entry_point.data = this.names.owned_entry_point.list.items;
}
} else if (naming.isObject()) {
- if (try naming.getOptional(globalThis, "entrypoint", ZigString.Slice)) |slice| {
+ if (try naming.getOptional(globalThis, "entry", ZigString.Slice)) |slice| {
defer slice.deinit();
this.names.owned_entry_point.appendSliceExact(slice.slice()) catch unreachable;
this.names.entry_point.data = this.names.owned_entry_point.list.items;
@@ -414,7 +414,7 @@ pub const JSBundler = struct {
importer_source_index: ?u32 = null,
import_record_index: u32 = 0,
range: logger.Range = logger.Range.None,
- original_platform: options.Platform,
+ original_target: Target,
};
pub fn create(
@@ -424,7 +424,7 @@ pub const JSBundler = struct {
importer_source_index: u32,
import_record_index: u32,
source_file: []const u8 = "",
- original_platform: options.Platform,
+ original_target: Target,
record: *const bun.ImportRecord,
},
},
@@ -443,7 +443,7 @@ pub const JSBundler = struct {
.importer_source_index = file.importer_source_index,
.import_record_index = file.import_record_index,
.range = file.record.range,
- .original_platform = file.original_platform,
+ .original_target = file.original_target,
},
},
.completion = completion,
diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig
index c4968a6ee..f1b00f191 100644
--- a/src/bun.js/api/JSTranspiler.zig
+++ b/src/bun.js/api/JSTranspiler.zig
@@ -32,7 +32,7 @@ const TSConfigJSON = @import("../../resolver/tsconfig_json.zig").TSConfigJSON;
const PackageJSON = @import("../../resolver/package_json.zig").PackageJSON;
const logger = bun.logger;
const Loader = options.Loader;
-const Platform = options.Platform;
+const Target = options.Target;
const JSAst = bun.JSAst;
const Transpiler = @This();
const JSParser = bun.js_parser;
@@ -54,7 +54,7 @@ buffer_writer: ?JSPrinter.BufferWriter = null,
const default_transform_options: Api.TransformOptions = brk: {
var opts = std.mem.zeroes(Api.TransformOptions);
opts.disable_hmr = true;
- opts.platform = Api.Platform.browser;
+ opts.target = Api.Target.browser;
opts.serve = false;
break :brk opts;
};
@@ -427,9 +427,9 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
}
}
- if (object.get(globalThis, "platform")) |platform| {
- if (Platform.fromJS(globalThis, platform, exception)) |resolved| {
- transpiler.transform.platform = resolved.toAPI();
+ if (object.get(globalThis, "target")) |target| {
+ if (Target.fromJS(globalThis, target, exception)) |resolved| {
+ transpiler.transform.target = resolved.toAPI();
}
if (exception.* != null) {
@@ -471,7 +471,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
}
transpiler.runtime.allow_runtime = false;
- transpiler.runtime.dynamic_require = switch (transpiler.transform.platform orelse .browser) {
+ transpiler.runtime.dynamic_require = switch (transpiler.transform.target orelse .browser) {
.bun, .bun_macro => true,
else => false,
};
diff --git a/src/bun.js/builtins/cpp/BundlerPluginBuiltins.cpp b/src/bun.js/builtins/cpp/BundlerPluginBuiltins.cpp
index 1f2053ad5..552057d51 100644
--- a/src/bun.js/builtins/cpp/BundlerPluginBuiltins.cpp
+++ b/src/bun.js/builtins/cpp/BundlerPluginBuiltins.cpp
@@ -192,7 +192,7 @@ const char* const s_bundlerPluginRunOnResolvePluginsCode =
const JSC::ConstructAbility s_bundlerPluginRunSetupFunctionCodeConstructAbility = JSC::ConstructAbility::CannotConstruct;
const JSC::ConstructorKind s_bundlerPluginRunSetupFunctionCodeConstructorKind = JSC::ConstructorKind::None;
const JSC::ImplementationVisibility s_bundlerPluginRunSetupFunctionCodeImplementationVisibility = JSC::ImplementationVisibility::Public;
-const int s_bundlerPluginRunSetupFunctionCodeLength = 3262;
+const int s_bundlerPluginRunSetupFunctionCodeLength = 3786;
static const JSC::Intrinsic s_bundlerPluginRunSetupFunctionCodeIntrinsic = JSC::NoIntrinsic;
const char* const s_bundlerPluginRunSetupFunctionCode =
"(function (setup) {\n" \
@@ -248,6 +248,19 @@ const char* const s_bundlerPluginRunSetupFunctionCode =
" validate(filterObject, callback, onResolvePlugins);\n" \
" }\n" \
"\n" \
+ " function onStart(callback) {\n" \
+ " //\n" \
+ " @throwTypeError(\"On-start callbacks are not implemented yet. See https:/\\/github.com/oven-sh/bun/issues/2771\");\n" \
+ " }\n" \
+ "\n" \
+ " function onEnd(callback) {\n" \
+ " @throwTypeError(\"On-end callbacks are not implemented yet. See https:/\\/github.com/oven-sh/bun/issues/2771\");\n" \
+ " }\n" \
+ "\n" \
+ " function onDispose(callback) {\n" \
+ " @throwTypeError(\"On-dispose callbacks are not implemented yet. See https:/\\/github.com/oven-sh/bun/issues/2771\");\n" \
+ " }\n" \
+ "\n" \
" const processSetupResult = () => {\n" \
" var anyOnLoad = false,\n" \
" anyOnResolve = false;\n" \
@@ -277,7 +290,7 @@ const char* const s_bundlerPluginRunSetupFunctionCode =
" if (!existing) {\n" \
" onResolveObject.@set(namespace, callbacks);\n" \
" } else {\n" \
- " onResolveObject.@set(existing.concat(callbacks));\n" \
+ " onResolveObject.@set(namespace, existing.concat(callbacks));\n" \
" }\n" \
" }\n" \
" }\n" \
@@ -294,7 +307,7 @@ const char* const s_bundlerPluginRunSetupFunctionCode =
" if (!existing) {\n" \
" onLoadObject.@set(namespace, callbacks);\n" \
" } else {\n" \
- " onLoadObject.@set(existing.concat(callbacks));\n" \
+ " onLoadObject.@set(namespace, existing.concat(callbacks));\n" \
" }\n" \
" }\n" \
" }\n" \
@@ -304,8 +317,11 @@ const char* const s_bundlerPluginRunSetupFunctionCode =
" };\n" \
"\n" \
" var setupResult = setup({\n" \
+ " onDispose,\n" \
+ " onEnd,\n" \
" onLoad,\n" \
" onResolve,\n" \
+ " onStart,\n" \
" });\n" \
"\n" \
" if (setupResult && @isPromise(setupResult)) {\n" \
diff --git a/src/bun.js/builtins/js/BundlerPlugin.js b/src/bun.js/builtins/js/BundlerPlugin.js
index 9fbb323ed..4daa2dcbb 100644
--- a/src/bun.js/builtins/js/BundlerPlugin.js
+++ b/src/bun.js/builtins/js/BundlerPlugin.js
@@ -221,6 +221,19 @@ function runSetupFunction(setup) {
validate(filterObject, callback, onResolvePlugins);
}
+ function onStart(callback) {
+ // builtin generator thinks the // in the link is a comment and removes it
+ @throwTypeError("On-start callbacks are not implemented yet. See https:/\/github.com/oven-sh/bun/issues/2771");
+ }
+
+ function onEnd(callback) {
+ @throwTypeError("On-end callbacks are not implemented yet. See https:/\/github.com/oven-sh/bun/issues/2771");
+ }
+
+ function onDispose(callback) {
+ @throwTypeError("On-dispose callbacks are not implemented yet. See https:/\/github.com/oven-sh/bun/issues/2771");
+ }
+
const processSetupResult = () => {
var anyOnLoad = false,
anyOnResolve = false;
@@ -250,7 +263,7 @@ function runSetupFunction(setup) {
if (!existing) {
onResolveObject.@set(namespace, callbacks);
} else {
- onResolveObject.@set(existing.concat(callbacks));
+ onResolveObject.@set(namespace, existing.concat(callbacks));
}
}
}
@@ -267,7 +280,7 @@ function runSetupFunction(setup) {
if (!existing) {
onLoadObject.@set(namespace, callbacks);
} else {
- onLoadObject.@set(existing.concat(callbacks));
+ onLoadObject.@set(namespace, existing.concat(callbacks));
}
}
}
@@ -277,8 +290,11 @@ function runSetupFunction(setup) {
};
var setupResult = setup({
+ onDispose,
+ onEnd,
onLoad,
onResolve,
+ onStart,
});
if (setupResult && @isPromise(setupResult)) {
diff --git a/src/bun.js/config.zig b/src/bun.js/config.zig
index b3614854e..6e304d526 100644
--- a/src/bun.js/config.zig
+++ b/src/bun.js/config.zig
@@ -42,6 +42,6 @@ pub fn configureTransformOptionsForBunVM(allocator: std.mem.Allocator, _args: Ap
pub fn configureTransformOptionsForBun(_: std.mem.Allocator, _args: Api.TransformOptions) !Api.TransformOptions {
var args = _args;
- args.platform = Api.Platform.bun;
+ args.target = Api.Target.bun;
return args;
}
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index a0fd52546..06f833e3b 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -648,7 +648,7 @@ pub const VirtualMachine = struct {
this.macro_event_loop.concurrent_tasks = .{};
}
- this.bundler.options.platform = .bun_macro;
+ this.bundler.options.target = .bun_macro;
this.bundler.resolver.caches.fs.use_alternate_source_cache = true;
this.macro_mode = true;
this.event_loop = &this.macro_event_loop;
@@ -656,7 +656,7 @@ pub const VirtualMachine = struct {
}
pub fn disableMacroMode(this: *VirtualMachine) void {
- this.bundler.options.platform = .bun;
+ this.bundler.options.target = .bun;
this.bundler.resolver.caches.fs.use_alternate_source_cache = false;
this.macro_mode = false;
this.event_loop = &this.regular_event_loop;