@@ -117,30 +117,13 @@ pub const TransformTask = struct {
117117 const name = this .loader .stdinName ();
118118 const source = logger .Source .initPathString (name , this .input_code .slice ());
119119
120- const prev_memory_allocators = .{ JSAst .Stmt .Data .Store .memory_allocator , JSAst .Expr .Data .Store .memory_allocator };
121- defer {
122- JSAst .Stmt .Data .Store .memory_allocator = prev_memory_allocators [0 ];
123- JSAst .Expr .Data .Store .memory_allocator = prev_memory_allocators [1 ];
124- }
125-
126120 var arena = Mimalloc .Arena .init () catch unreachable ;
121+ defer arena .deinit ();
127122
128123 const allocator = arena .allocator ();
129-
130124 var ast_memory_allocator = allocator .create (JSAst .ASTMemoryAllocator ) catch bun .outOfMemory ();
131- ast_memory_allocator .* = .{
132- .allocator = allocator ,
133- };
134- ast_memory_allocator .reset ();
135-
136- JSAst .Stmt .Data .Store .memory_allocator = ast_memory_allocator ;
137- JSAst .Expr .Data .Store .memory_allocator = ast_memory_allocator ;
138-
139- defer {
140- JSAst .Stmt .Data .Store .reset ();
141- JSAst .Expr .Data .Store .reset ();
142- arena .deinit ();
143- }
125+ var ast_scope = ast_memory_allocator .enter (allocator );
126+ defer ast_scope .exit ();
144127
145128 this .transpiler .setAllocator (allocator );
146129 this .transpiler .setLog (& this .log );
@@ -847,7 +830,8 @@ pub fn scan(this: *JSTranspiler, globalThis: *JSC.JSGlobalObject, callframe: *JS
847830
848831 var arena = Mimalloc .Arena .init () catch unreachable ;
849832 const prev_allocator = this .transpiler .allocator ;
850- this .transpiler .setAllocator (arena .allocator ());
833+ const allocator = arena .allocator ();
834+ this .transpiler .setAllocator (allocator );
851835 var log = logger .Log .init (arena .backingAllocator ());
852836 defer log .deinit ();
853837 this .transpiler .setLog (& log );
@@ -856,13 +840,11 @@ pub fn scan(this: *JSTranspiler, globalThis: *JSC.JSGlobalObject, callframe: *JS
856840 this .transpiler .setAllocator (prev_allocator );
857841 arena .deinit ();
858842 }
843+ var ast_memory_allocator = allocator .create (JSAst .ASTMemoryAllocator ) catch bun .outOfMemory ();
844+ var ast_scope = ast_memory_allocator .enter (allocator );
845+ defer ast_scope .exit ();
859846
860- defer {
861- JSAst .Stmt .Data .Store .reset ();
862- JSAst .Expr .Data .Store .reset ();
863- }
864-
865- var parse_result = getParseResult (this , arena .allocator (), code , loader , Transpiler .MacroJSValueType .zero ) orelse {
847+ var parse_result = getParseResult (this , allocator , code , loader , Transpiler .MacroJSValueType .zero ) orelse {
866848 if ((this .transpiler .log .warnings + this .transpiler .log .errors ) > 0 ) {
867849 return globalThis .throwValue (try this .transpiler .log .toJS (globalThis , globalThis .allocator (), "Parse error" ));
868850 }
@@ -991,15 +973,14 @@ pub fn transformSync(
991973 }
992974 }
993975
994- JSAst .Stmt .Data .Store .reset ();
995- JSAst .Expr .Data .Store .reset ();
996- defer {
997- JSAst .Stmt .Data .Store .reset ();
998- JSAst .Expr .Data .Store .reset ();
999- }
976+ const allocator = arena .allocator ();
977+
978+ var ast_memory_allocator = allocator .create (JSAst .ASTMemoryAllocator ) catch bun .outOfMemory ();
979+ var ast_scope = ast_memory_allocator .enter (allocator );
980+ defer ast_scope .exit ();
1000981
1001982 const prev_bundler = this .transpiler ;
1002- this .transpiler .setAllocator (arena . allocator () );
983+ this .transpiler .setAllocator (allocator );
1003984 this .transpiler .macro_context = null ;
1004985 var log = logger .Log .init (arena .backingAllocator ());
1005986 log .level = this .transpiler_options .log .level ;
@@ -1010,7 +991,7 @@ pub fn transformSync(
1010991 }
1011992 const parse_result = getParseResult (
1012993 this ,
1013- arena . allocator () ,
994+ allocator ,
1014995 code ,
1015996 loader ,
1016997 js_ctx_value ,
@@ -1132,7 +1113,12 @@ pub fn scanImports(this: *JSTranspiler, globalThis: *JSC.JSGlobalObject, callfra
11321113
11331114 var arena = Mimalloc .Arena .init () catch unreachable ;
11341115 const prev_allocator = this .transpiler .allocator ;
1135- this .transpiler .setAllocator (arena .allocator ());
1116+ const allocator = arena .allocator ();
1117+ var ast_memory_allocator = allocator .create (JSAst .ASTMemoryAllocator ) catch bun .outOfMemory ();
1118+ var ast_scope = ast_memory_allocator .enter (allocator );
1119+ defer ast_scope .exit ();
1120+
1121+ this .transpiler .setAllocator (allocator );
11361122 var log = logger .Log .init (arena .backingAllocator ());
11371123 defer log .deinit ();
11381124 this .transpiler .setLog (& log );
@@ -1155,14 +1141,6 @@ pub fn scanImports(this: *JSTranspiler, globalThis: *JSC.JSGlobalObject, callfra
11551141 }
11561142 opts .macro_context = & this .transpiler .macro_context .? ;
11571143
1158- JSAst .Stmt .Data .Store .reset ();
1159- JSAst .Expr .Data .Store .reset ();
1160-
1161- defer {
1162- JSAst .Stmt .Data .Store .reset ();
1163- JSAst .Expr .Data .Store .reset ();
1164- }
1165-
11661144 transpiler .resolver .caches .js .scan (
11671145 transpiler .allocator ,
11681146 & this .scan_pass_result ,
0 commit comments