File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
oxc_minifier/tests/mangler Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -232,13 +232,22 @@ impl Mangler {
232
232
{
233
233
slots[ symbol_id. index ( ) ] = assigned_slot;
234
234
235
+ let declared_scope_id =
236
+ ast_nodes. get_node ( symbol_table. get_declaration ( * symbol_id) ) . scope_id ( ) ;
237
+
235
238
// Calculate the scope ids that this symbol is alive in.
236
239
let lived_scope_ids = symbol_table
237
240
. get_resolved_references ( * symbol_id)
238
241
. flat_map ( |reference| {
239
242
let used_scope_id = ast_nodes. get_node ( reference. node_id ( ) ) . scope_id ( ) ;
240
243
scope_tree. ancestors ( used_scope_id) . take_while ( |s_id| * s_id != scope_id)
241
244
} )
245
+ // also include scopes that this symbol was declared (for cases like `function foo() { { var x; let y; } }`)
246
+ . chain (
247
+ scope_tree
248
+ . ancestors ( declared_scope_id)
249
+ . take_while ( |s_id| * s_id != scope_id) ,
250
+ )
242
251
. chain ( iter:: once ( scope_id) ) ;
243
252
244
253
// Since the slot is now assigned to this symbol, it is alive in all the scopes that this symbol is alive in.
Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ fn mangler() {
40
40
"function _() { var x; try { throw 0 } catch (e) { e } }" , // e can shadow x
41
41
"function _() { var x; try { throw 0 } catch (e) { var e } }" , // e can shadow x (not implemented)
42
42
"function _() { var x; try { throw 0 } catch { var e } }" , // e should not shadow x
43
+ "function _() { var x; var y; }" , // x and y should have different names
44
+ "function _() { var x; let y; }" , // x and y should have different names
45
+ "function _() { { var x; var y; } }" , // x and y should have different names
46
+ "function _() { { var x; let y; } }" , // x and y should have different names
43
47
] ;
44
48
let top_level_cases = [
45
49
"function foo(a) {a}" ,
Original file line number Diff line number Diff line change @@ -153,6 +153,34 @@ function _() {
153
153
}
154
154
}
155
155
156
+ function _() { var x; var y; }
157
+ function _() {
158
+ var a;
159
+ var b;
160
+ }
161
+
162
+ function _() { var x; let y; }
163
+ function _() {
164
+ var a;
165
+ let b;
166
+ }
167
+
168
+ function _() { { var x; var y; } }
169
+ function _() {
170
+ {
171
+ var a;
172
+ var b;
173
+ }
174
+ }
175
+
176
+ function _() { { var x; let y; } }
177
+ function _() {
178
+ {
179
+ var a;
180
+ let b;
181
+ }
182
+ }
183
+
156
184
function foo(a ) {a }
157
185
function a(a ) {
158
186
a ;
You can’t perform that action at this time.
0 commit comments