Skip to content

Tests the effect of es6 #2062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
## Bug fixes
* Compiler: fix stack overflow issues with double translation (#1869)
* Compiler: minifier fix (#1867)
* Compiler: fix shortvar with --enable es6 (AssignTarget was not properly handled)
* Compiler: fix assert failure with double translation (#1870)
* Compiler: fix path rewriting of Wasm source maps (#1882)
* Compiler: fix global dead code in presence of dead tailcall (#2010)
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module Flag = struct

let auto_link = o ~name:"auto-link" ~default:true

let es6 = o ~name:"es6" ~default:false
let es6 = o ~name:"es6" ~default:true

let load_shapes_auto = o ~name:"load-shapes-auto" ~default:false
end
Expand Down
23 changes: 22 additions & 1 deletion compiler/lib/js_traverse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,14 @@ class map : mapper =
match m#statement (Class_declaration (id, f)) with
| Class_declaration (id, f) -> ExportClass (id, f)
| _ -> assert false)
| ExportNames l -> ExportNames (List.map ~f:(fun (id, s) -> m#ident id, s) l)
| ExportNames l ->
ExportNames
(List.map
~f:(fun (id, s) ->
match m#expression (EVar id) with
| EVar id -> id, s
| _ -> assert false)
l)
| ExportDefaultFun (Some id, decl) -> (
match m#statement (Function_declaration (id, decl)) with
| Function_declaration (id, decl) -> ExportDefaultFun (Some id, decl)
Expand Down Expand Up @@ -1020,6 +1027,20 @@ class free =
cbody#record_block Normal;
m#merge_block_info cbody;
EClass (ident_o, cl_decl)
| EAssignTarget (ArrayTarget l) ->
List.iter l ~f:(function
| TargetElementHole -> ()
| TargetElementId (i, _) -> m#use_var i
| TargetElement _ -> ()
| TargetElementSpread _ -> ());
super#expression x
| EAssignTarget (ObjectTarget l) ->
List.iter l ~f:(function
| TargetPropertyId (Prop_and_ident i, _) -> m#use_var i
| TargetProperty _ -> ()
| TargetPropertyMethod _ -> ()
| TargetPropertySpread _ -> ());
super#expression x
| _ -> super#expression x

method record_block _ = ()
Expand Down
28 changes: 27 additions & 1 deletion compiler/tests-compiler/minify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,30 @@ function h(f) {
{|
$ cat "test.min.js"
1: function
2: h(a){var{toto:b}=a();console.log({toto:b})} |}])
2: h(a){var{toto:b}=a();console.log({toto:b})}
|}];
minify
{|
function f () {
var x = 0;
let z = 0;
switch(x) {
case 1:
let y = 1;
return y
case 2:
[z] = x;
}
}
|};
[%expect
{|
$ cat "test.min.js"
1: function
2: f(){var
3: a=0;let
4: b=0;switch(a){case
5: 1:let
6: c=1;return c;case
7: 2:[b]=a}}
|}])
Loading