aboutsummaryrefslogtreecommitdiff
path: root/src/logger.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-17 21:19:45 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-17 21:19:45 -0700
commit6585226de721bc43b17a66fad90738a38937f210 (patch)
tree92150bb914b508c022f83ad6324496340006c0f5 /src/logger.zig
parentbbe0a3d58ccb420fe94b8d59934b2b54ed71f295 (diff)
downloadbun-6585226de721bc43b17a66fad90738a38937f210.tar.gz
bun-6585226de721bc43b17a66fad90738a38937f210.tar.zst
bun-6585226de721bc43b17a66fad90738a38937f210.zip
Ignore
Former-commit-id: b2c4fce705222612b0457481657db3f42db41d1c
Diffstat (limited to '')
-rw-r--r--src/logger.zig36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/logger.zig b/src/logger.zig
index a5f4eeae2..8904ee1e1 100644
--- a/src/logger.zig
+++ b/src/logger.zig
@@ -365,6 +365,25 @@ pub const Log = struct {
self.msgs.deinit();
}
+ pub fn appendToMaybeRecycled(self: *Log, other: *Log, source: *const Source) !void {
+ if (source.contents_is_recycled) {
+ for (self.msgs.items) |*_msg| {
+ var msg: *Msg = _msg;
+ if (msg.data.location) |*location| {
+ if (location.line_text) |line_text| {
+ location.line_text = try other.msgs.allocator.dupe(u8, line_text);
+ }
+ }
+ }
+ }
+
+ try other.msgs.appendSlice(self.msgs.items);
+ other.warnings += self.warnings;
+ other.errors += self.errors;
+
+ self.msgs.deinit();
+ }
+
pub fn deinit(self: *Log) void {
self.msgs.deinit();
}
@@ -547,6 +566,7 @@ pub const Source = struct {
key_path: fs.Path,
index: u32 = 0,
contents: string,
+ contents_is_recycled: bool = false,
// An identifier that is mixed in to automatically-generated symbol names to
// improve readability. For example, if the identifier is "util" then the
@@ -574,6 +594,22 @@ pub const Source = struct {
return source;
}
+ pub fn initRecycledFile(file: fs.File, allocator: *std.mem.Allocator) !Source {
+ var name = file.path.name;
+ var identifier_name = name.nonUniqueNameString(allocator) catch unreachable;
+
+ var source = Source{
+ .path = file.path,
+ .key_path = fs.Path.init(file.path.text),
+ .identifier_name = identifier_name,
+ .contents = file.contents,
+ .contents_is_recycled = true,
+ };
+ source.path.namespace = "file";
+
+ return source;
+ }
+
pub fn initPathString(pathString: string, contents: string) Source {
var path = fs.Path.init(pathString);
return Source{ .key_path = path, .path = path, .identifier_name = path.name.base, .contents = contents };