aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/module_loader.zig148
-rw-r--r--src/bundler.zig2
-rw-r--r--src/js_ast.zig8
-rw-r--r--src/js_parser.zig84
-rw-r--r--src/runtime.zig2
5 files changed, 1 insertions, 243 deletions
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index d37410131..765cf70a6 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -398,7 +398,6 @@ pub const RuntimeTranspilerStore = struct {
.macro_remappings = macro_remappings,
.jsx = bundler.options.jsx,
.virtual_source = null,
- .hoist_bun_plugin = false,
.dont_bundle_twice = true,
.allow_commonjs = true,
.inject_jest_globals = bundler.options.rewrite_jest_for_tests and
@@ -1436,7 +1435,6 @@ pub const ModuleLoader = struct {
.macro_remappings = macro_remappings,
.jsx = jsc_vm.bundler.options.jsx,
.virtual_source = virtual_source,
- .hoist_bun_plugin = true,
.dont_bundle_twice = true,
.allow_commonjs = true,
.inject_jest_globals = jsc_vm.bundler.options.rewrite_jest_for_tests and is_main,
@@ -1553,12 +1551,6 @@ pub const ModuleLoader = struct {
};
}
- const has_bun_plugin = parse_result.ast.bun_plugin.hoisted_stmts.items.len > 0;
-
- if (has_bun_plugin) {
- try ModuleLoader.runBunPlugin(jsc_vm, JSC.VirtualMachine.source_code_printer.?, &parse_result, ret);
- }
-
const start_count = jsc_vm.bundler.linker.import_counter;
// We _must_ link because:
@@ -1611,7 +1603,7 @@ pub const ModuleLoader = struct {
var printer = source_code_printer.*;
printer.ctx.reset();
- const written = brk: {
+ _ = brk: {
defer source_code_printer.* = printer;
break :brk try jsc_vm.bundler.printWithSourceMap(
parse_result,
@@ -1622,25 +1614,6 @@ pub const ModuleLoader = struct {
);
};
- if (written == 0) {
-
- // if it's an empty file but there were plugins
- // we don't want it to break if you try to import from it
- if (has_bun_plugin) {
- return ResolvedSource{
- .allocator = null,
- .source_code = String.static("module.exports=undefined"),
- .specifier = input_specifier,
- .source_url = ZigString.init(path.text),
- // // TODO: change hash to a bitfield
- // .hash = 1,
-
- // having JSC own the memory causes crashes
- .hash = 0,
- };
- }
- }
-
if (comptime Environment.dump_source) {
try dumpSource(specifier, &printer);
}
@@ -1832,125 +1805,6 @@ pub const ModuleLoader = struct {
}
}
- pub fn runBunPlugin(
- jsc_vm: *VirtualMachine,
- source_code_printer: *js_printer.BufferPrinter,
- parse_result: *ParseResult,
- ret: *ErrorableResolvedSource,
- ) !void {
- var printer = source_code_printer.*;
- printer.ctx.reset();
-
- defer printer.ctx.reset();
- // If we start transpiling in the middle of an existing transpilation session
- // we will hit undefined memory bugs
- // unless we disable resetting the store until we are done transpiling
- const prev_disable_reset = js_ast.Stmt.Data.Store.disable_reset;
- js_ast.Stmt.Data.Store.disable_reset = true;
- js_ast.Expr.Data.Store.disable_reset = true;
-
- // flip the source code we use
- // unless we're already transpiling a plugin
- // that case could happen when
- const was_printing_plugin = jsc_vm.is_printing_plugin;
- const prev = jsc_vm.bundler.resolver.caches.fs.use_alternate_source_cache;
- jsc_vm.is_printing_plugin = true;
- defer {
- js_ast.Stmt.Data.Store.disable_reset = prev_disable_reset;
- js_ast.Expr.Data.Store.disable_reset = prev_disable_reset;
- if (!was_printing_plugin) jsc_vm.bundler.resolver.caches.fs.use_alternate_source_cache = prev;
- jsc_vm.is_printing_plugin = was_printing_plugin;
- }
- // we flip use_alternate_source_cache
- if (!was_printing_plugin) jsc_vm.bundler.resolver.caches.fs.use_alternate_source_cache = !prev;
-
- // this is a bad idea, but it should work for now.
- const original_name = parse_result.ast.symbols.mut(parse_result.ast.bun_plugin.ref.innerIndex()).original_name;
- parse_result.ast.symbols.mut(parse_result.ast.bun_plugin.ref.innerIndex()).original_name = "globalThis.Bun.plugin";
- defer {
- parse_result.ast.symbols.mut(parse_result.ast.bun_plugin.ref.innerIndex()).original_name = original_name;
- }
- const hoisted_stmts = parse_result.ast.bun_plugin.hoisted_stmts.items;
-
- var parts = [1]js_ast.Part{
- js_ast.Part{
- .stmts = hoisted_stmts,
- },
- };
- var ast_copy = parse_result.ast;
- ast_copy.import_records.set(try jsc_vm.allocator.dupe(ImportRecord, ast_copy.import_records.slice()));
- defer ast_copy.import_records.deinitWithAllocator(jsc_vm.allocator);
- ast_copy.parts.set(&parts);
- ast_copy.prepend_part = null;
- var temporary_source = parse_result.source;
- var source_name = try std.fmt.allocPrint(jsc_vm.allocator, "{s}.plugin.{s}", .{ temporary_source.path.text, temporary_source.path.name.ext[1..] });
- temporary_source.path = Fs.Path.init(source_name);
-
- var temp_parse_result = parse_result.*;
- temp_parse_result.ast = ast_copy;
-
- try jsc_vm.bundler.linker.link(
- temporary_source.path,
- &temp_parse_result,
- jsc_vm.origin,
- .absolute_path,
- false,
- true,
- );
-
- _ = brk: {
- defer source_code_printer.* = printer;
- break :brk try jsc_vm.bundler.printWithSourceMapMaybe(
- temp_parse_result.ast,
- &temporary_source,
- @TypeOf(&printer),
- &printer,
- .esm_ascii,
- true,
- SavedSourceMap.SourceMapHandler.init(&jsc_vm.source_mappings),
- );
- };
- const wrote = printer.ctx.getWritten();
-
- if (wrote.len > 0) {
- if (comptime Environment.dump_source)
- try dumpSource(temporary_source.path.text, &printer);
-
- var exception = [1]JSC.JSValue{JSC.JSValue.zero};
- const promise = JSC.JSModuleLoader.evaluate(
- jsc_vm.global,
- wrote.ptr,
- wrote.len,
- temporary_source.path.text.ptr,
- temporary_source.path.text.len,
- parse_result.source.path.text.ptr,
- parse_result.source.path.text.len,
- JSC.JSValue.jsUndefined(),
- &exception,
- );
- if (!exception[0].isEmpty()) {
- ret.* = JSC.ErrorableResolvedSource.err(
- error.JSErrorObject,
- exception[0].asVoid(),
- );
- return error.PluginError;
- }
-
- if (!promise.isEmptyOrUndefinedOrNull()) {
- if (promise.asAnyPromise()) |promise_value| {
- jsc_vm.waitForPromise(promise_value);
-
- if (promise_value.status(jsc_vm.global.vm()) == .Rejected) {
- ret.* = JSC.ErrorableResolvedSource.err(
- error.JSErrorObject,
- promise_value.result(jsc_vm.global.vm()).asVoid(),
- );
- return error.PluginError;
- }
- }
- }
- }
- }
pub fn normalizeSpecifier(jsc_vm: *VirtualMachine, slice_: string, string_to_use_for_source: *[]const u8) string {
var slice = slice_;
if (slice.len == 0) return slice;
diff --git a/src/bundler.zig b/src/bundler.zig
index 3f744b8fc..b3e62a43d 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -1258,7 +1258,6 @@ pub const Bundler = struct {
macro_js_ctx: MacroJSValueType = default_macro_js_value,
virtual_source: ?*const logger.Source = null,
replace_exports: runtime.Runtime.Features.ReplaceableExport.Map = .{},
- hoist_bun_plugin: bool = false,
inject_jest_globals: bool = false,
dont_bundle_twice: bool = false,
@@ -1412,7 +1411,6 @@ pub const Bundler = struct {
strings.eqlComptime(jsx.import_source.production, "react/jsx-runtime");
opts.features.jsx_optimization_hoist = bundler.options.jsx_optimization_hoist orelse opts.features.jsx_optimization_inline;
- opts.features.hoist_bun_plugin = this_parse.hoist_bun_plugin;
opts.features.inject_jest_globals = this_parse.inject_jest_globals;
opts.features.minify_syntax = bundler.options.minify_syntax;
opts.features.minify_identifiers = bundler.options.minify_identifiers;
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 62089b3b2..b37e93be5 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -5947,8 +5947,6 @@ pub const Ast = struct {
wrapper_ref: Ref = Ref.None,
require_ref: Ref = Ref.None,
- bun_plugin: BunPlugin = .{},
-
prepend_part: ?Part = null,
// These are used when bundling. They are filled in during the parser pass
@@ -6420,7 +6418,6 @@ pub const Part = struct {
cjs_imports,
react_fast_refresh,
dirname_filename,
- bun_plugin,
bun_test,
dead_due_to_inlining,
commonjs_named_export,
@@ -6688,11 +6685,6 @@ pub fn printmem(comptime format: string, args: anytype) void {
Output.print(format, args);
}
-pub const BunPlugin = struct {
- ref: Ref = Ref.None,
- hoisted_stmts: std.ArrayListUnmanaged(Stmt) = .{},
-};
-
pub const Macro = struct {
const JavaScript = @import("root").bun.JSC;
const JSCBase = @import("./bun.js/base.zig");
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 076815e54..392d7d922 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -4803,7 +4803,6 @@ fn NewParser_(
filename_ref: Ref = Ref.None,
dirname_ref: Ref = Ref.None,
import_meta_ref: Ref = Ref.None,
- bun_plugin: js_ast.BunPlugin = .{},
scopes_in_order_visitor_index: usize = 0,
has_classic_runtime_warned: bool = false,
macro_call_count: MacroCallCountType = 0,
@@ -8146,38 +8145,6 @@ fn NewParser_(
return p.s(S.Empty{}, loc);
}
- if (p.options.features.hoist_bun_plugin and strings.eqlComptime(path.text, "bun")) {
- var plugin_i: usize = std.math.maxInt(usize);
- const items = stmt.items;
- for (items, 0..) |item, i| {
- // Mark Bun.plugin()
- // TODO: remove if they have multiple imports of the same name?
- if (strings.eqlComptime(item.alias, "plugin")) {
- const name = p.loadNameFromRef(item.name.ref.?);
- const ref = try p.declareSymbol(.other, item.name.loc, name);
- try p.is_import_item.put(p.allocator, ref, {});
- p.bun_plugin.ref = ref;
- plugin_i = i;
- break;
- }
- }
-
- if (plugin_i != std.math.maxInt(usize)) {
- var list = std.ArrayListUnmanaged(@TypeOf(stmt.items[0])){
- .items = stmt.items,
- .capacity = stmt.items.len,
- };
- // remove it from the list
- _ = list.swapRemove(plugin_i);
- stmt.items = list.items;
- }
-
- // if the import statement is now empty, remove it completely
- if (stmt.items.len == 0 and stmt.default_name == null and stmt.star_name_loc == null) {
- return p.s(S.Empty{}, loc);
- }
- }
-
const macro_remap = if ((comptime allow_macros) and !is_macro)
p.options.macro_context.getRemap(path.text)
else
@@ -14563,10 +14530,6 @@ fn NewParser_(
var partStmts = ListManaged(Stmt).fromOwnedSlice(allocator, stmts);
//
- const bun_plugin_usage_count_before: usize = if (p.options.features.hoist_bun_plugin and !p.bun_plugin.ref.isNull())
- p.symbols.items[p.bun_plugin.ref.innerIndex()].use_count_estimate
- else
- 0;
try p.visitStmtsAndPrependTempRefs(&partStmts, &opts);
@@ -14602,52 +14565,6 @@ fn NewParser_(
if (partStmts.items.len > 0) {
const _stmts = partStmts.items;
- // -- hoist_bun_plugin --
- if (_stmts.len == 1 and p.options.features.hoist_bun_plugin and !p.bun_plugin.ref.isNull()) {
- const bun_plugin_usage_count_after: usize = p.symbols.items[p.bun_plugin.ref.innerIndex()].use_count_estimate;
- if (bun_plugin_usage_count_after > bun_plugin_usage_count_before) {
- var previous_parts: []js_ast.Part = parts.items;
-
- for (previous_parts, 0..) |*previous_part, j| {
- if (previous_part.stmts.len == 0) continue;
-
- var refs = previous_part.declared_symbols.refs();
-
- for (refs) |ref| {
- if (p.symbol_uses.contains(ref)) {
- // we move this part to our other file
- for (previous_parts[0..j]) |*this_part| {
- if (this_part.stmts.len == 0) continue;
- const other_refs = this_part.declared_symbols.refs();
-
- for (other_refs) |other_ref| {
- if (previous_part.symbol_uses.contains(other_ref)) {
- try p.bun_plugin.hoisted_stmts.appendSlice(p.allocator, this_part.stmts);
- this_part.stmts = &.{};
- break;
- }
- }
- }
-
- try p.bun_plugin.hoisted_stmts.appendSlice(p.allocator, previous_part.stmts);
- break;
- }
- }
- }
- p.bun_plugin.hoisted_stmts.append(p.allocator, _stmts[0]) catch unreachable;
-
- // Single-statement part which uses Bun.plugin()
- // It's effectively an unrelated file
- if (p.declared_symbols.len() > 0 or p.symbol_uses.count() > 0) {
- p.clearSymbolUsagesFromDeadPart(.{ .stmts = undefined, .declared_symbols = p.declared_symbols, .symbol_uses = p.symbol_uses });
- p.declared_symbols.clearRetainingCapacity();
- p.import_records_for_current_part.items.len = 0;
- }
- return;
- }
- }
- // -- hoist_bun_plugin --
-
try parts.append(js_ast.Part{
.stmts = _stmts,
.symbol_uses = p.symbol_uses,
@@ -21922,7 +21839,6 @@ fn NewParser_(
else
false,
// .top_Level_await_keyword = p.top_level_await_keyword,
- .bun_plugin = p.bun_plugin,
.commonjs_named_exports = p.commonjs_named_exports,
.commonjs_export_names = p.commonjs_export_names.keys(),
diff --git a/src/runtime.zig b/src/runtime.zig
index 89fd66e77..790f5b197 100644
--- a/src/runtime.zig
+++ b/src/runtime.zig
@@ -314,8 +314,6 @@ pub const Runtime = struct {
replace_exports: ReplaceableExport.Map = .{},
- hoist_bun_plugin: bool = false,
-
dont_bundle_twice: bool = false,
/// This is a list of packages which even when require() is used, we will