mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
37 lines
1.1 KiB
Zig
37 lines
1.1 KiB
Zig
const js_ast = @import("js_ast.zig");
|
|
usingnamespace @import("global.zig");
|
|
const std = @import("std");
|
|
const logger = @import("logger.zig");
|
|
|
|
// This is...poorly named
|
|
// It does not rename
|
|
// It merely names
|
|
pub const Renamer = struct {
|
|
symbols: js_ast.Symbol.Map,
|
|
source: *const logger.Source,
|
|
|
|
pub fn init(symbols: js_ast.Symbol.Map, source: *const logger.Source) Renamer {
|
|
return Renamer{ .symbols = symbols, .source = source };
|
|
}
|
|
|
|
pub fn nameForSymbol(renamer: *Renamer, ref: js_ast.Ref) string {
|
|
if (ref.is_source_contents_slice) {
|
|
return renamer.source.contents[ref.source_index .. ref.source_index + ref.inner_index];
|
|
}
|
|
|
|
const resolved = renamer.symbols.follow(ref);
|
|
if (renamer.symbols.get(resolved)) |symbol| {
|
|
return symbol.original_name;
|
|
} else {
|
|
Global.panic("Invalid symbol {s}", .{ref});
|
|
}
|
|
}
|
|
};
|
|
|
|
pub const DisabledRenamer = struct {
|
|
pub fn init(symbols: js_ast.Symbol.Map) DisabledRenamer {}
|
|
pub fn nameForSymbol(renamer: *Renamer, ref: js_ast.Ref) callconv(.Inline) string {
|
|
@compileError("DisabledRunner called");
|
|
}
|
|
};
|