diff options
Diffstat (limited to 'src/js_printer.zig')
-rw-r--r-- | src/js_printer.zig | 106 |
1 files changed, 24 insertions, 82 deletions
diff --git a/src/js_printer.zig b/src/js_printer.zig index 1613500a1..a47cc1a23 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -741,7 +741,7 @@ fn NewPrinter( pub fn writeByteNTimes(self: *Printer, byte: u8, n: usize) !void { var bytes: [256]u8 = undefined; - std.mem.set(u8, bytes[0..], byte); + @memset(bytes[0..], byte); var remaining: usize = n; while (remaining > 0) { @@ -845,7 +845,14 @@ fn NewPrinter( fn printBunJestImportStatement(p: *Printer, import: S.Import) void { if (comptime !is_bun_platform) unreachable; - printInternalBunImport(p, import, @TypeOf("globalThis.Bun.jest(import.meta.path)"), "globalThis.Bun.jest(import.meta.path)"); + switch (p.options.module_type) { + .cjs => { + printInternalBunImport(p, import, @TypeOf("globalThis.Bun.jest(__filename)"), "globalThis.Bun.jest(__filename)"); + }, + else => { + printInternalBunImport(p, import, @TypeOf("globalThis.Bun.jest(import.meta.path)"), "globalThis.Bun.jest(import.meta.path)"); + }, + } } fn printGlobalBunImportStatement(p: *Printer, import: S.Import) void { @@ -1333,7 +1340,7 @@ fn NewPrinter( // In JavaScript, numbers are represented as 64 bit floats // However, they could also be signed or unsigned int 32 (when doing bit shifts) // In this case, it's always going to unsigned since that conversion has already happened. - const val = @floatToInt(u64, float); + const val = @intFromFloat(u64, float); switch (val) { 0 => { p.print("0"); @@ -2395,7 +2402,7 @@ fn NewPrinter( // This is more efficient than creating a new Part just for the JSX auto imports when bundling if (comptime rewrite_esm_to_cjs) { - if (@ptrToInt(p.options.prepend_part_key) > 0 and @ptrToInt(e.body.stmts.ptr) == @ptrToInt(p.options.prepend_part_key)) { + if (@intFromPtr(p.options.prepend_part_key) > 0 and @intFromPtr(e.body.stmts.ptr) == @intFromPtr(p.options.prepend_part_key)) { p.printTwoBlocksInOne(e.body.loc, e.body.stmts, p.options.prepend_part_value.?.stmts); wasPrinted = true; } @@ -2527,7 +2534,7 @@ fn NewPrinter( p.print("{"); const props = expr.data.e_object.properties.slice(); if (props.len > 0) { - p.options.indent += @as(usize, @boolToInt(!e.is_single_line)); + p.options.indent += @as(usize, @intFromBool(!e.is_single_line)); if (e.is_single_line) { p.printSpace(); @@ -3465,7 +3472,7 @@ fn NewPrinter( .b_array => |b| { p.print("["); if (b.items.len > 0) { - p.options.indent += @as(usize, @boolToInt(!b.is_single_line)); + p.options.indent += @as(usize, @intFromBool(!b.is_single_line)); for (b.items, 0..) |*item, i| { if (i != 0) { @@ -3508,7 +3515,7 @@ fn NewPrinter( p.print("{"); if (b.properties.len > 0) { p.options.indent += - @as(usize, @boolToInt(!b.is_single_line)); + @as(usize, @intFromBool(!b.is_single_line)); for (b.properties, 0..) |*property, i| { if (i != 0) { @@ -4372,10 +4379,10 @@ fn NewPrinter( p.printGlobalBunImportStatement(s.*); return; }, - .hardcoded => { - p.printHardcodedImportStatement(s.*); - return; - }, + // .hardcoded => { + // p.printHardcodedImportStatement(s.*); + // return; + // }, else => {}, } } @@ -4385,71 +4392,6 @@ fn NewPrinter( const module_id = record.module_id; - if (comptime is_bun_platform) { - if (!record.path.is_disabled) { - if (record.contains_import_star) { - p.print("var "); - p.printSymbol(s.namespace_ref); - p.@"print = "(); - p.print("import.meta.require("); - p.printImportRecordPath(record); - p.print(")"); - p.printSemicolonAfterStatement(); - } - - if (s.items.len > 0 or s.default_name != null) { - p.printIndent(); - p.printSpaceBeforeIdentifier(); - p.printWhitespacer(ws("var {")); - - if (s.default_name) |default_name| { - p.printSpace(); - p.print("default:"); - p.printSpace(); - p.printSymbol(default_name.ref.?); - - if (s.items.len > 0) { - p.printSpace(); - p.print(","); - p.printSpace(); - for (s.items, 0..) |item, i| { - p.printClauseItemAs(item, .@"var"); - - if (i < s.items.len - 1) { - p.print(","); - p.printSpace(); - } - } - } - } else { - for (s.items, 0..) |item, i| { - p.printClauseItemAs(item, .@"var"); - - if (i < s.items.len - 1) { - p.print(","); - p.printSpace(); - } - } - } - - p.print("}"); - p.@"print = "(); - - if (record.contains_import_star) { - p.printSymbol(s.namespace_ref); - p.printSemicolonAfterStatement(); - } else { - p.print("import.meta.require("); - p.printImportRecordPath(record); - p.print(")"); - p.printSemicolonAfterStatement(); - } - } - - return; - } - } - if (!record.path.is_disabled and std.mem.indexOfScalar(u32, p.imported_module_ids.items, module_id) == null) { p.printWhitespacer(ws("import * as")); p.print(" "); @@ -5561,13 +5503,13 @@ pub const BufferWriter = struct { } pub fn writeByte(ctx: *BufferWriter, byte: u8) anyerror!usize { try ctx.buffer.appendChar(byte); - ctx.approximate_newline_count += @boolToInt(byte == '\n'); + ctx.approximate_newline_count += @intFromBool(byte == '\n'); ctx.last_bytes = .{ ctx.last_bytes[1], byte }; return 1; } pub fn writeAll(ctx: *BufferWriter, bytes: anytype) anyerror!usize { try ctx.buffer.append(bytes); - ctx.approximate_newline_count += @boolToInt(bytes.len > 0 and bytes[bytes.len - 1] == '\n'); + ctx.approximate_newline_count += @intFromBool(bytes.len > 0 and bytes[bytes.len - 1] == '\n'); if (bytes.len >= 2) { ctx.last_bytes = bytes[bytes.len - 2 ..][0..2].*; @@ -5779,7 +5721,7 @@ pub fn printAst( } } - std.sort.sort(rename.StableSymbolCount, top_level_symbols.items, {}, rename.StableSymbolCount.lessThan); + std.sort.block(rename.StableSymbolCount, top_level_symbols.items, {}, rename.StableSymbolCount.lessThan); try minify_renamer.allocateTopLevelSymbolSlots(top_level_symbols); var minifier = tree.char_freq.?.compile(allocator); @@ -5861,9 +5803,9 @@ pub fn printJSON( var stmt = Stmt{ .loc = logger.Loc.Empty, .data = .{ .s_expr = &s_expr, } }; - var stmts = &[_]js_ast.Stmt{stmt}; - var parts = &[_]js_ast.Part{.{ .stmts = stmts }}; - const ast = Ast.initTest(parts); + var stmts = [_]js_ast.Stmt{stmt}; + var parts = [_]js_ast.Part{.{ .stmts = &stmts }}; + const ast = Ast.initTest(&parts); var list = js_ast.Symbol.List.init(ast.symbols.slice()); var nested_list = js_ast.Symbol.NestedList.init(&[_]js_ast.Symbol.List{list}); var renamer = rename.NoOpRenamer.init(js_ast.Symbol.Map.initList(nested_list), source); |