mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Ignore
Former-commit-id: b2c4fce705222612b0457481657db3f42db41d1c
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -48,4 +48,5 @@ txt.js
|
||||
.vscode/cpp*
|
||||
|
||||
node_modules_*
|
||||
*.jsb
|
||||
*.jsb
|
||||
.zip
|
||||
@@ -993,7 +993,7 @@ pub fn NewBundler(cache_files: bool) type {
|
||||
true,
|
||||
null,
|
||||
);
|
||||
const source = logger.Source.initFile(Fs.File{ .path = file_path, .contents = entry.contents }, bundler.allocator) catch return null;
|
||||
const source = logger.Source.initRecycledFile(Fs.File{ .path = file_path, .contents = entry.contents }, bundler.allocator) catch return null;
|
||||
const source_dir = file_path.name.dirWithTrailingSlash();
|
||||
|
||||
var jsx = bundler.options.jsx;
|
||||
@@ -1275,7 +1275,7 @@ pub fn NewBundler(cache_files: bool) type {
|
||||
null,
|
||||
) catch return;
|
||||
|
||||
const source = logger.Source.initFile(Fs.File{ .path = file_path, .contents = entry.contents }, bundler.allocator) catch return null;
|
||||
const source = logger.Source.initRecycledFile(Fs.File{ .path = file_path, .contents = entry.contents }, bundler.allocator) catch return null;
|
||||
const source_dir = file_path.name.dirWithTrailingSlash();
|
||||
|
||||
var jsx = bundler.options.jsx;
|
||||
@@ -1594,8 +1594,8 @@ pub fn NewBundler(cache_files: bool) type {
|
||||
) catch return null;
|
||||
|
||||
const _file = Fs.File{ .path = file_path, .contents = entry.contents };
|
||||
const source = try logger.Source.initFile(_file, bundler.allocator);
|
||||
|
||||
var source = try logger.Source.initFile(_file, bundler.allocator);
|
||||
source.contents_is_recycled = !cache_files;
|
||||
var css_writer = CSSWriter.init(
|
||||
&source,
|
||||
file,
|
||||
@@ -1792,7 +1792,7 @@ pub fn NewBundler(cache_files: bool) type {
|
||||
file_descriptor,
|
||||
) catch return null;
|
||||
input_fd = entry.fd;
|
||||
break :brk logger.Source.initFile(Fs.File{ .path = path, .contents = entry.contents }, bundler.allocator) catch return null;
|
||||
break :brk logger.Source.initRecycledFile(Fs.File{ .path = path, .contents = entry.contents }, bundler.allocator) catch return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ pub fn NewCache(comptime cache_files: bool) type {
|
||||
source: *const logger.Source,
|
||||
) anyerror!?js_ast.Ast {
|
||||
var temp_log = logger.Log.init(allocator);
|
||||
defer temp_log.appendTo(log) catch {};
|
||||
defer temp_log.appendToMaybeRecycled(log, source) catch {};
|
||||
var parser = js_parser.Parser.init(opts, &temp_log, source, defines, allocator) catch |err| {
|
||||
return null;
|
||||
};
|
||||
@@ -205,7 +205,7 @@ pub fn NewCache(comptime cache_files: bool) type {
|
||||
source: *const logger.Source,
|
||||
) anyerror!void {
|
||||
var temp_log = logger.Log.init(allocator);
|
||||
defer temp_log.appendTo(log) catch {};
|
||||
defer temp_log.appendToMaybeRecycled(log, source) catch {};
|
||||
|
||||
var parser = js_parser.Parser.init(opts, &temp_log, source, defines, allocator) catch |err| {
|
||||
return;
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user