aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/allocators.zig25
-rw-r--r--src/fs.zig6
-rw-r--r--src/js_parser/js_parser.zig10
-rw-r--r--src/logger.zig61
-rw-r--r--src/resolver/dir_info.zig2
-rw-r--r--src/test/fixtures/tsx-bug.tsx1
6 files changed, 73 insertions, 32 deletions
diff --git a/src/allocators.zig b/src/allocators.zig
index b2b8244f4..29f660a12 100644
--- a/src/allocators.zig
+++ b/src/allocators.zig
@@ -134,6 +134,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type {
const max_index = count - 1;
var list_type: type = undefined;
var list_count = count;
+ const overflow_init_count = std.math.max(count / 8, 32);
return struct {
pub var backing_buf: [count]ValueType = undefined;
pub var backing_buf_used: u16 = 0;
@@ -183,7 +184,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type {
backing_buf[result.index] = value;
backing_buf_used += 1;
if (backing_buf_used >= max_index) {
- self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count);
+ self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count);
}
}
@@ -201,7 +202,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type {
backing_buf[result.index] = value;
backing_buf_used += 1;
if (backing_buf_used >= max_index) {
- self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count);
+ self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count);
}
return Pair{ .index = result, .value = &backing_buf[result.index] };
}
@@ -216,7 +217,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type {
result.index.index = backing_buf_used;
backing_buf_used += 1;
if (backing_buf_used >= max_index) {
- self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count);
+ self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count);
}
}
}
@@ -282,6 +283,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
const count = _count * 2;
const max_index = count - 1;
const ValueType = []const u8;
+ const overflow_init_count = std.math.max(count / 8, 32);
return struct {
pub var slice_buf: [count][]const u8 = undefined;
@@ -417,7 +419,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
result.index = slice_buf_used;
slice_buf_used += 1;
if (slice_buf_used >= max_index) {
- self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count);
+ self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count);
}
}
@@ -466,8 +468,9 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
};
}
-pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: bool, estimated_key_length: usize) type {
+pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: bool, estimated_key_length: usize, remove_trailing_slashes: bool) type {
const max_index = count - 1;
+ const overflow_init_count = std.math.max(count / 8, 32);
const BSSMapType = struct {
pub var backing_buf: [count]ValueType = undefined;
pub var backing_buf_used: u16 = 0;
@@ -494,7 +497,8 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo
return backing_buf_used >= @as(u16, count);
}
- pub fn getOrPut(self: *Self, key: []const u8) !Result {
+ pub fn getOrPut(self: *Self, denormalized_key: []const u8) !Result {
+ const key = if (comptime remove_trailing_slashes) std.mem.trimRight(u8, denormalized_key, "/") else denormalized_key;
const _key = Wyhash.hash(Seed, key);
var index = try self.index.getOrPut(self.allocator, _key);
@@ -518,7 +522,8 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo
};
}
- pub fn get(self: *const Self, key: []const u8) ?*ValueType {
+ pub fn get(self: *const Self, denormalized_key: []const u8) ?*ValueType {
+ const key = if (comptime remove_trailing_slashes) std.mem.trimRight(u8, denormalized_key, "/") else denormalized_key;
const _key = Wyhash.hash(Seed, key);
const index = self.index.get(_key) orelse return null;
return self.atIndex(index);
@@ -547,7 +552,7 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo
result.index.index = backing_buf_used;
backing_buf_used += 1;
if (backing_buf_used >= max_index) {
- self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count);
+ self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count);
}
}
}
@@ -570,7 +575,9 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo
}
}
- pub fn remove(self: *Self, key: []const u8) void {
+ pub fn remove(self: *Self, denormalized_key: []const u8) void {
+ const key = if (comptime remove_trailing_slashes) std.mem.trimRight(u8, denormalized_key, "/") else denormalized_key;
+
const _key = Wyhash.hash(Seed, key);
_ = self.index.remove(_key);
// const index = self.index.get(_key) orelse return;
diff --git a/src/fs.zig b/src/fs.zig
index 80473692b..2bed1ee47 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -15,8 +15,8 @@ const hash_map = @import("hash_map.zig");
pub const Preallocate = struct {
pub const Counts = struct {
- pub const dir_entry: usize = 512;
- pub const files: usize = 4096;
+ pub const dir_entry: usize = 4096;
+ pub const files: usize = 8096;
};
};
@@ -665,7 +665,7 @@ pub const FileSystem = struct {
// This custom map implementation:
// - Preallocates a fixed amount of directory name space
// - Doesn't store directory names which don't exist.
- pub const Map = allocators.BSSMap(EntriesOption, Preallocate.Counts.dir_entry, false, 128);
+ pub const Map = allocators.BSSMap(EntriesOption, Preallocate.Counts.dir_entry, false, 128, true);
};
// Limit the number of files open simultaneously to avoid ulimit issues
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index 957da2857..ca6e38edb 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -3698,7 +3698,7 @@ pub fn NewParser(
.is_computed = item.flags.is_computed,
},
.key = (if (is_spread) item.value orelse item.key else item.key) orelse p.panic("Internal error: Expected {s} to have a key.", .{item}),
- .value = tup.binding orelse p.panic("Internal error: Expected {s} to have a binding.", .{tup}),
+ .value = tup.binding orelse p.b(B.Missing{}, expr.loc),
.default_value = initializer,
});
}
@@ -8498,9 +8498,11 @@ pub fn NewParser(
}
}
- // Stop now if this token is forbidden to follow a TypeScript "as" cast
- if (p.forbid_suffix_after_as_loc.start > -1 and p.lexer.loc().start == p.forbid_suffix_after_as_loc.start) {
- return left;
+ if (comptime is_typescript_enabled) {
+ // Stop now if this token is forbidden to follow a TypeScript "as" cast
+ if (p.forbid_suffix_after_as_loc.start > -1 and p.lexer.loc().start == p.forbid_suffix_after_as_loc.start) {
+ return left;
+ }
}
// Reset the optional chain flag by default. That way we won't accidentally
diff --git a/src/logger.zig b/src/logger.zig
index 8ccffd06f..397a49a11 100644
--- a/src/logger.zig
+++ b/src/logger.zig
@@ -454,6 +454,39 @@ pub const Log = struct {
});
}
+ inline fn _addResolveError(log: *Log, source: *const Source, r: Range, allocator: *std.mem.Allocator, comptime fmt: string, args: anytype, import_kind: ImportKind, comptime dupe_text: bool) !void {
+ const text = try std.fmt.allocPrint(allocator, fmt, args);
+ // TODO: fix this. this is stupid, it should be returned in allocPrint.
+ const specifier = BabyString.in(text, args.@"0");
+ log.errors += 1;
+
+ const data = if (comptime dupe_text) brk: {
+ var _data = rangeData(
+ source,
+ r,
+ text,
+ );
+ if (_data.location != null) {
+ if (_data.location.?.line_text) |line| {
+ _data.location.?.line_text = allocator.dupe(u8, line) catch unreachable;
+ }
+ }
+ break :brk _data;
+ } else rangeData(
+ source,
+ r,
+ text,
+ );
+
+ const msg = Msg{
+ .kind = .err,
+ .data = data,
+ .metadata = .{ .resolve = Msg.Metadata.Resolve{ .specifier = specifier, .import_kind = import_kind } },
+ };
+
+ try log.addMsg(msg);
+ }
+
pub fn addResolveError(
log: *Log,
source: *const Source,
@@ -463,21 +496,19 @@ pub const Log = struct {
args: anytype,
import_kind: ImportKind,
) !void {
- const text = try std.fmt.allocPrint(allocator, fmt, args);
- // TODO: fix this. this is stupid, it should be returned in allocPrint.
- const specifier = BabyString.in(text, args.@"0");
- log.errors += 1;
- try log.addMsg(
- Msg{
- .kind = .err,
- .data = rangeData(
- source,
- r,
- text,
- ),
- .metadata = .{ .resolve = Msg.Metadata.Resolve{ .specifier = specifier, .import_kind = import_kind } },
- },
- );
+ return try _addResolveError(log, source, r, allocator, fmt, args, import_kind, false);
+ }
+
+ pub fn addResolveErrorWithTextDupe(
+ log: *Log,
+ source: *const Source,
+ r: Range,
+ allocator: *std.mem.Allocator,
+ comptime fmt: string,
+ args: anytype,
+ import_kind: ImportKind,
+ ) !void {
+ return try _addResolveError(log, source, r, allocator, fmt, args, import_kind, true);
}
pub fn addRangeError(log: *Log, source: ?*const Source, r: Range, text: string) !void {
diff --git a/src/resolver/dir_info.zig b/src/resolver/dir_info.zig
index c175cf2f2..5d3c53f96 100644
--- a/src/resolver/dir_info.zig
+++ b/src/resolver/dir_info.zig
@@ -71,4 +71,4 @@ pub fn getEnclosingBrowserScope(i: *const DirInfo) ?*DirInfo {
// 2. Don't expect a provided key to exist after it's queried
// 3. Store whether a directory has been queried and whether that query was successful.
// 4. Allocate onto the https://en.wikipedia.org/wiki/.bss#BSS_in_C instead of the heap, so we can avoid memory leaks
-pub const HashMap = allocators.BSSMap(DirInfo, Fs.Preallocate.Counts.dir_entry, false, 128);
+pub const HashMap = allocators.BSSMap(DirInfo, Fs.Preallocate.Counts.dir_entry, false, 128, true);
diff --git a/src/test/fixtures/tsx-bug.tsx b/src/test/fixtures/tsx-bug.tsx
new file mode 100644
index 000000000..9018b1514
--- /dev/null
+++ b/src/test/fixtures/tsx-bug.tsx
@@ -0,0 +1 @@
+const subtitleProps = searchQuery ? ({ mt: 3, size: "sm" } as const) : {};