Skip to content

Commit 7725aa8

Browse files
committed
Compiler: fix freevar in presence of assignTarget
1 parent 1102ff0 commit 7725aa8

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

compiler/lib/js_traverse.ml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,14 @@ class map : mapper =
239239
match m#statement (Class_declaration (id, f)) with
240240
| Class_declaration (id, f) -> ExportClass (id, f)
241241
| _ -> assert false)
242-
| ExportNames l -> ExportNames (List.map ~f:(fun (id, s) -> m#ident id, s) l)
242+
| ExportNames l ->
243+
ExportNames
244+
(List.map
245+
~f:(fun (id, s) ->
246+
match m#expression (EVar id) with
247+
| EVar id -> id, s
248+
| _ -> assert false)
249+
l)
243250
| ExportDefaultFun (Some id, decl) -> (
244251
match m#statement (Function_declaration (id, decl)) with
245252
| Function_declaration (id, decl) -> ExportDefaultFun (Some id, decl)
@@ -1020,6 +1027,20 @@ class free =
10201027
cbody#record_block Normal;
10211028
m#merge_block_info cbody;
10221029
EClass (ident_o, cl_decl)
1030+
| EAssignTarget (ArrayTarget l) ->
1031+
List.iter l ~f:(function
1032+
| TargetElementHole -> ()
1033+
| TargetElementId (i, _) -> m#use_var i
1034+
| TargetElement _ -> ()
1035+
| TargetElementSpread _ -> ());
1036+
super#expression x
1037+
| EAssignTarget (ObjectTarget l) ->
1038+
List.iter l ~f:(function
1039+
| TargetPropertyId (Prop_and_ident i, _) -> m#use_var i
1040+
| TargetProperty _ -> ()
1041+
| TargetPropertyMethod _ -> ()
1042+
| TargetPropertySpread _ -> ());
1043+
super#expression x
10231044
| _ -> super#expression x
10241045

10251046
method record_block _ = ()

compiler/tests-compiler/minify.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,12 @@ function f () {
504504
|};
505505
[%expect
506506
{|
507-
$ cat "test.min.js"
508-
1: function
509-
2: f(){var
510-
3: a=0;let
511-
4: b=0;switch(a){case
512-
5: 1:let
513-
6: b=1;return b;case
514-
7: 2:[b]=a}}
515-
|}])
507+
$ cat "test.min.js"
508+
1: function
509+
2: f(){var
510+
3: a=0;let
511+
4: b=0;switch(a){case
512+
5: 1:let
513+
6: c=1;return c;case
514+
7: 2:[b]=a}}
515+
|}])

0 commit comments

Comments
 (0)