aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-01 22:21:03 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-01 22:21:03 -0800
commit149bbc12b523119d7be8739cd8f55e2867b8a866 (patch)
tree1b55d610f01c54885998a4086b9d111b1179e402
parent78cae049d2c8f7fa4f7cde8ed5b8895b3e32b5fc (diff)
downloadbun-149bbc12b523119d7be8739cd8f55e2867b8a866.tar.gz
bun-149bbc12b523119d7be8739cd8f55e2867b8a866.tar.zst
bun-149bbc12b523119d7be8739cd8f55e2867b8a866.zip
add `allowBunRuntime` and `autoImportJSX` flags to Bun.Transpiler
-rw-r--r--src/javascript/jsc/api/transpiler.zig33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/javascript/jsc/api/transpiler.zig b/src/javascript/jsc/api/transpiler.zig
index 3993768f3..5863f0a69 100644
--- a/src/javascript/jsc/api/transpiler.zig
+++ b/src/javascript/jsc/api/transpiler.zig
@@ -40,6 +40,8 @@ const JSParser = @import("../../../js_parser.zig");
const JSPrinter = @import("../../../js_printer.zig");
const ScanPassResult = JSParser.ScanPassResult;
const Mimalloc = @import("../../../mimalloc_arena.zig");
+const Runtime = @import("../../../runtime.zig").Runtime;
+
bundler: Bundler.Bundler,
arena: std.heap.ArenaAllocator,
transpiler_options: TranspilerOptions,
@@ -94,6 +96,7 @@ const TranspilerOptions = struct {
macros_buf: []const u8 = "",
log: logger.Log,
pending_tasks: u32 = 0,
+ runtime: Runtime.Features = Runtime.Features{ .top_level_await = true },
};
// Mimalloc gets unstable if we try to move this to a different thread
@@ -438,6 +441,8 @@ fn transformOptionsFromJSC(ctx: JSC.C.JSContextRef, temp_allocator: std.mem.Allo
}
}
+ transpiler.runtime.allow_runtime = false;
+
if (object.getIfPropertyExists(globalThis, "macro")) |macros| {
macros: {
if (macros.isUndefinedOrNull()) break :macros;
@@ -468,6 +473,14 @@ fn transformOptionsFromJSC(ctx: JSC.C.JSContextRef, temp_allocator: std.mem.Allo
}
}
+ if (object.get(globalThis, "autoImportJSX")) |flag| {
+ transpiler.runtime.auto_import_jsx = flag.toBoolean();
+ }
+
+ if (object.get(globalThis, "allowBunRuntime")) |flag| {
+ transpiler.runtime.allow_runtime = flag.toBoolean();
+ }
+
return transpiler;
}
@@ -530,6 +543,12 @@ pub fn constructor(
bundler.options.macro_remap = transpiler_options.macro_map;
}
+ bundler.options.allow_runtime = transpiler_options.runtime.allow_runtime;
+ bundler.options.auto_import_jsx = transpiler_options.runtime.auto_import_jsx;
+ bundler.options.hot_module_reloading = transpiler_options.runtime.hot_module_reloading;
+ bundler.options.jsx.supports_fast_refresh = bundler.options.hot_module_reloading and
+ bundler.options.allow_runtime and transpiler_options.runtime.react_fast_refresh;
+
var transpiler = getAllocator(ctx).create(Transpiler) catch unreachable;
transpiler.* = Transpiler{
.transpiler_options = transpiler_options,
@@ -578,7 +597,19 @@ fn getParseResult(this: *Transpiler, allocator: std.mem.Allocator, code: []const
// .allocator = this.
};
- return this.bundler.parse(parse_options, null);
+ var parse_result = this.bundler.parse(parse_options, null);
+
+ // necessary because we don't run the linker
+ if (parse_result) |*res| {
+ for (res.ast.import_records) |*import| {
+ if (import.kind.isCommonJS()) {
+ import.wrap_with_to_module = true;
+ import.module_id = @truncate(u32, std.hash.Wyhash.hash(0, import.path.pretty));
+ }
+ }
+ }
+
+ return parse_result;
}
pub fn scan(