diff options
author | 2022-01-04 22:12:37 -0800 | |
---|---|---|
committer | 2022-01-04 22:12:37 -0800 | |
commit | 8837c3c10b2cece5536a758079f55659f5bc7285 (patch) | |
tree | d5a944320512b3a313666e8a7f79e168c11b8353 /src/cache.zig | |
parent | 0d0dd65a6a227a7c674128bd518a1954b40db408 (diff) | |
download | bun-8837c3c10b2cece5536a758079f55659f5bc7285.tar.gz bun-8837c3c10b2cece5536a758079f55659f5bc7285.tar.zst bun-8837c3c10b2cece5536a758079f55659f5bc7285.zip |
[Bun.js][bun dev] Support macros inside of Bun.js
Closes #36
Diffstat (limited to 'src/cache.zig')
-rw-r--r-- | src/cache.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/cache.zig b/src/cache.zig index 3a3429105..25acce57a 100644 --- a/src/cache.zig +++ b/src/cache.zig @@ -48,6 +48,7 @@ pub const Set = struct { .js = JavaScript.init(allocator), .fs = Fs{ .shared_buffer = MutableString.init(allocator, 0) catch unreachable, + .macro_shared_buffer = MutableString.init(allocator, 0) catch unreachable, }, .json = Json{}, }; @@ -57,6 +58,18 @@ pub const Fs = struct { const Entry = FsCacheEntry; shared_buffer: MutableString, + macro_shared_buffer: MutableString, + + is_macro_mode: bool = false, + + // When we are in a macro, the shared buffer may be in use by the in-progress macro. + // so we have to dynamically switch it out. + pub inline fn sharedBuffer(this: *Fs) *MutableString { + return if (!this.is_macro_mode) + &this.shared_buffer + else + &this.macro_shared_buffer; + } pub fn deinit(c: *Fs) void { var iter = c.entries.iterator(); @@ -138,7 +151,7 @@ pub const Fs = struct { } } - const file = rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, &c.shared_buffer) catch |err| { + const file = rfs.readFileWithHandle(path, null, file_handle, use_shared_buffer, c.sharedBuffer()) catch |err| { if (Environment.isDebug) { Output.printError("{s}: readFile error -- {s}", .{ path, @errorName(err) }); } |