mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 19:08:50 +00:00
### What does this PR do? Originally, we attempted to avoid the "dual package hazard" right before we enqueue a parse task, but that code gets called in a non-deterministic order. This meant that some of your modules would use the right variant and some of them would not. We have to instead do that in a separate pass, after all the files are parsed. The thing to watch out for with this PR is how it impacts the dev server. ### How did you verify your code works? Unskipped tests. Plus manual. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
47 lines
1.4 KiB
Zig
47 lines
1.4 KiB
Zig
const PathToSourceIndexMap = @This();
|
|
|
|
/// The lifetime of the keys are not owned by this map.
|
|
///
|
|
/// We assume it's arena allocated.
|
|
map: Map = .{},
|
|
|
|
const Map = bun.StringHashMapUnmanaged(Index.Int);
|
|
|
|
pub fn getPath(this: *const PathToSourceIndexMap, path: *const Fs.Path) ?Index.Int {
|
|
return this.get(path.text);
|
|
}
|
|
|
|
pub fn get(this: *const PathToSourceIndexMap, text: []const u8) ?Index.Int {
|
|
return this.map.get(text);
|
|
}
|
|
|
|
pub fn putPath(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, path: *const Fs.Path, value: Index.Int) bun.OOM!void {
|
|
try this.map.put(allocator, path.text, value);
|
|
}
|
|
|
|
pub fn put(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, text: []const u8, value: Index.Int) bun.OOM!void {
|
|
try this.map.put(allocator, text, value);
|
|
}
|
|
|
|
pub fn getOrPutPath(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, path: *const Fs.Path) bun.OOM!Map.GetOrPutResult {
|
|
return this.getOrPut(allocator, path.text);
|
|
}
|
|
|
|
pub fn getOrPut(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, text: []const u8) bun.OOM!Map.GetOrPutResult {
|
|
return try this.map.getOrPut(allocator, text);
|
|
}
|
|
|
|
pub fn remove(this: *PathToSourceIndexMap, text: []const u8) bool {
|
|
return this.map.remove(text);
|
|
}
|
|
|
|
pub fn removePath(this: *PathToSourceIndexMap, path: *const Fs.Path) bool {
|
|
return this.remove(path.text);
|
|
}
|
|
|
|
const std = @import("std");
|
|
|
|
const bun = @import("bun");
|
|
const Fs = bun.fs;
|
|
const Index = bun.ast.Index;
|