Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS bundling & general fixes #16486

Merged
merged 28 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8eeaedf
comment
zackradisic Dec 23, 2024
6e9460a
Make bundling with @layer, @media, @supports and imports work better
zackradisic Dec 30, 2024
1ecafe0
Bundler css fixes
zackradisic Jan 2, 2025
2e71b74
Hash stuff
zackradisic Jan 2, 2025
50a9e8e
Fix some tests, don't include additional file if inlined by CSS if po…
zackradisic Jan 4, 2025
52df0a4
Fix lots of tests
zackradisic Jan 6, 2025
f30bd09
Merge branch 'main' into zack/cascading-style-sheets
zackradisic Jan 6, 2025
4c455cd
bigg css import tests
zackradisic Jan 7, 2025
46fd753
MOAR tests
zackradisic Jan 7, 2025
4dee124
Fix test
zackradisic Jan 7, 2025
aa8166f
more test
zackradisic Jan 15, 2025
9a7736d
Merge branch 'main' into zack/cascading-style-sheets
zackradisic Jan 15, 2025
222dc9c
fix fonts
zackradisic Jan 15, 2025
8c8015a
Big border thang WIP
zackradisic Jan 17, 2025
1810047
WOW
zackradisic Jan 18, 2025
e9f2242
Merge branch 'main' into zack/cascading-style-sheets
zackradisic Jan 18, 2025
c66b5d5
Fix tests
zackradisic Jan 18, 2025
c03c945
Fix test
zackradisic Jan 18, 2025
3042d46
fix crash
zackradisic Jan 18, 2025
f0a9794
fix test i broke
zackradisic Jan 18, 2025
ee6a0d7
Fix this dataurl stuff
zackradisic Jan 18, 2025
88aa222
update snapshot
zackradisic Jan 18, 2025
0809844
Skip test
zackradisic Jan 18, 2025
f34a851
comment
zackradisic Jan 18, 2025
5e70265
Resolve comments
zackradisic Jan 18, 2025
8007de9
Fix compile error
zackradisic Jan 18, 2025
5898e57
Merge branch 'main' into zack/cascading-style-sheets
zackradisic Jan 18, 2025
85c1d8f
Woops broke something
zackradisic Jan 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/baby_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ pub fn BabyList(comptime Type: type) type {
}

fn assertValidDeepClone(comptime T: type) void {
if (@hasDecl(T, "deepClone")) return;
return switch (T) {
bun.JSAst.Expr, bun.JSAst.G.Property, bun.css.ImportConditions => {},
bun.JSAst.Expr, bun.JSAst.G.Property, bun.css.ImportConditions, bun.css.LayerName => {},
else => {
@compileError("Unsupported type for BabyList.deepClone(): " ++ @typeName(Type));
},
Expand All @@ -130,11 +131,12 @@ pub fn BabyList(comptime Type: type) type {
}

/// Same as `deepClone` but doesn't return an error
pub fn deepClone2(this: @This(), allocator: std.mem.Allocator) @This() {
pub fn deepClone2(this: *const @This(), allocator: std.mem.Allocator) @This() {
assertValidDeepClone(Type);
var list_ = initCapacity(allocator, this.len) catch bun.outOfMemory();
for (this.slice()) |item| {
list_.appendAssumeCapacity(item.deepClone(allocator));
list_.len = this.len;
for (this.sliceConst(), list_.slice()) |*old, *new| {
new.* = old.deepClone(allocator);
}

return list_;
Expand Down Expand Up @@ -308,6 +310,12 @@ pub fn BabyList(comptime Type: type) type {
this.update(list__);
}

pub fn insert(this: *@This(), allocator: std.mem.Allocator, index: usize, val: Type) !void {
var list__ = this.listManaged(allocator);
try list__.insert(index, val);
this.update(list__);
}

pub fn append(this: *@This(), allocator: std.mem.Allocator, value: []const Type) !void {
var list__ = this.listManaged(allocator);
try list__.appendSlice(value);
Expand Down
4 changes: 4 additions & 0 deletions src/bitflags.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ pub fn Bitflags(comptime T: type) type {
return @bitCast(@as(IntType, asBits(lhs) & asBits(rhs)));
}

pub inline fn intersect(lhs: T, rhs: T) T {
return bitwiseAnd(lhs, rhs);
}

pub inline fn insert(this: *T, other: T) void {
this.* = bitwiseOr(this.*, other);
}
Expand Down
6 changes: 4 additions & 2 deletions src/bun.js/node/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ pub const TimeLike = if (Environment.isWindows) f64 else std.posix.timespec;
/// - "path"
/// - "errno"
pub fn Maybe(comptime ReturnTypeT: type, comptime ErrorTypeT: type) type {
const hasRetry = ErrorTypeT != void and @hasDecl(ErrorTypeT, "retry");
const hasTodo = ErrorTypeT != void and @hasDecl(ErrorTypeT, "todo");
// can't call @hasDecl on void, anyerror, etc
const has_any_decls = ErrorTypeT != void and ErrorTypeT != anyerror;
const hasRetry = has_any_decls and @hasDecl(ErrorTypeT, "retry");
const hasTodo = has_any_decls and @hasDecl(ErrorTypeT, "todo");

return union(Tag) {
pub const ErrorType = ErrorTypeT;
Expand Down
86 changes: 86 additions & 0 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4147,6 +4147,16 @@ pub inline fn take(val: anytype) ?bun.meta.OptionalChild(@TypeOf(val)) {
return null;
}

/// `val` must be a pointer to an optional type (e.g. `*?T`)
///
/// This function deinitializes the value and sets the optional to null.
pub inline fn clear(val: anytype, allocator: std.mem.Allocator) void {
if (val.*) |*v| {
v.deinit(allocator);
val.* = null;
}
}

pub inline fn wrappingNegation(val: anytype) @TypeOf(val) {
return 0 -% val;
}
Expand Down Expand Up @@ -4175,6 +4185,82 @@ pub inline fn itemOrNull(comptime T: type, slice: []const T, index: usize) ?T {
return if (index < slice.len) slice[index] else null;
}

pub const Maybe = bun.JSC.Node.Maybe;

/// Type which could be borrowed or owned
/// The name is from the Rust std's `Cow` type
/// Can't think of a better name
pub fn Cow(comptime T: type, comptime VTable: type) type {
const Handler = struct {
fn copy(this: *const T, allocator: std.mem.Allocator) T {
if (!@hasDecl(VTable, "copy")) @compileError(@typeName(VTable) ++ " needs `copy()` function");
return VTable.copy(this, allocator);
}

fn deinit(this: *T, allocator: std.mem.Allocator) void {
if (!@hasDecl(VTable, "deinit")) @compileError(@typeName(VTable) ++ " needs `deinit()` function");
return VTable.deinit(this, allocator);
}
};

return union(enum) {
borrowed: *const T,
owned: T,

pub fn borrow(val: *const T) @This() {
return .{
.borrowed = val,
};
}

pub fn own(val: T) @This() {
return .{
.owned = val,
};
}

pub fn replace(this: *@This(), allocator: std.mem.Allocator, newval: T) void {
if (this.* == .owned) {
this.deinit(allocator);
}
this.* = .{ .owned = newval };
}

/// Get the underlying value.
pub inline fn inner(this: *const @This()) *const T {
return switch (this.*) {
.borrowed => this.borrowed,
.owned => &this.owned,
};
}

pub inline fn innerMut(this: *@This()) ?*T {
return switch (this.*) {
.borrowed => null,
.owned => &this.owned,
};
}

pub fn toOwned(this: *@This(), allocator: std.mem.Allocator) *T {
switch (this.*) {
.borrowed => {
this.* = .{
.owned = Handler.copy(this.borrowed, allocator),
};
},
.owned => {},
}
return &this.owned;
}

pub fn deinit(this: *@This(), allocator: std.mem.Allocator) void {
if (this.* == .owned) {
Handler.deinit(&this.owned, allocator);
}
}
};
}

/// To handle stack overflows:
/// 1. StackCheck.init()
/// 2. .isSafeToRecurse()
Expand Down
Loading
Loading