Files
bun.sh/src/renamer.zig
Jarred Sumner e75c711c68 Upgrade to latest Zig, remove dependency on patched version of Zig (#96)
* Prepare to upgrade zig

* zig fmt

* AllocGate

* Update data_url.zig

* wip

* few files

* just headers now?

* I think everything works?

* Update mimalloc

* Update hash_map.zig

* Perf improvements to compensate for Allocgate

* Bump

* 📷

* Update bun.lockb

* Less branching

* [js parser] Slightly reduce memory usage

* Update js_parser.zig

* WIP remove unused

* [JS parser] WIP support for `with` keyword

* Remove more dead code

* Fix all the build errors!

* cleanup

* Move `network_thread` up

* Bump peechy

* Update README.md
2021-12-30 21:12:32 -08:00

48 lines
1.5 KiB
Zig

const js_ast = @import("js_ast.zig");
const _global = @import("global.zig");
const string = _global.string;
const Output = _global.Output;
const Global = _global.Global;
const Environment = _global.Environment;
const strings = _global.strings;
const MutableString = _global.MutableString;
const stringZ = _global.stringZ;
const default_allocator = _global.default_allocator;
const C = _global.C;
const std = @import("std");
const Ref = @import("./ast/base.zig").Ref;
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: 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(_: js_ast.Symbol.Map) DisabledRenamer {}
pub inline fn nameForSymbol(_: *Renamer, _: js_ast.Ref) string {
@compileError("DisabledRunner called");
}
};