From faa9510c422d270cc4a03917b383a75453e52d8d Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Sat, 23 Jul 2022 15:28:06 +0900 Subject: [PATCH 1/3] add test of pipe "->" eats up attrs in 1 arity fn --- jscomp/test/res_debug.js | 11 +++++++++++ jscomp/test/res_debug.res | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/jscomp/test/res_debug.js b/jscomp/test/res_debug.js index 7ae8a31c70..b177a6057f 100644 --- a/jscomp/test/res_debug.js +++ b/jscomp/test/res_debug.js @@ -49,6 +49,14 @@ var bad = { name: bad_name }; +function identity(x) { + return x; +} + +var ok1 = {}; + +var bad1 = {}; + var v2 = newrecord; var v1 = { @@ -73,4 +81,7 @@ exports.optionMap = optionMap; exports.name = name; exports.ok = ok; exports.bad = bad; +exports.identity = identity; +exports.ok1 = ok1; +exports.bad1 = bad1; /* Not a pure module */ diff --git a/jscomp/test/res_debug.res b/jscomp/test/res_debug.res index e2cae86f9f..142f8f580c 100644 --- a/jscomp/test/res_debug.res +++ b/jscomp/test/res_debug.res @@ -65,4 +65,11 @@ type props<'name> = {key?: string, name?: string} let name = None let ok = {name: ?optionMap(name, x => x)} -let bad = {name: ?name->optionMap(x => x)} \ No newline at end of file +let bad = {name: ?name->optionMap(x => x)} + +let identity = x => x + +let name1 = Some("ReScript") + +let ok1 = {name: ?identity(name1)} +let bad1 = {name: ?name1->identity} From d5b55b5ec0068262cc38ceb790a15e7fdb827a83 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Sat, 23 Jul 2022 16:08:44 +0900 Subject: [PATCH 2/3] fix pipe "->" eats up attrs in 1 arity fn --- jscomp/frontend/ast_exp_apply.ml | 6 ++++++ jscomp/test/res_debug.js | 11 +++++++++-- lib/4.06.1/unstable/js_compiler.ml | 6 ++++++ lib/4.06.1/unstable/js_playground_compiler.ml | 6 ++++++ lib/4.06.1/whole_compiler.ml | 6 ++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/jscomp/frontend/ast_exp_apply.ml b/jscomp/frontend/ast_exp_apply.ml index 847340b252..90e9ab8c21 100644 --- a/jscomp/frontend/ast_exp_apply.ml +++ b/jscomp/frontend/ast_exp_apply.ml @@ -128,6 +128,12 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } + | Pexp_ident _ -> + { + pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); + pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; + } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, diff --git a/jscomp/test/res_debug.js b/jscomp/test/res_debug.js index b177a6057f..bd4779d995 100644 --- a/jscomp/test/res_debug.js +++ b/jscomp/test/res_debug.js @@ -53,9 +53,15 @@ function identity(x) { return x; } -var ok1 = {}; +var name1 = "ReScript"; -var bad1 = {}; +var ok1 = { + name: name1 +}; + +var bad1 = { + name: name1 +}; var v2 = newrecord; @@ -82,6 +88,7 @@ exports.name = name; exports.ok = ok; exports.bad = bad; exports.identity = identity; +exports.name1 = name1; exports.ok1 = ok1; exports.bad1 = bad1; /* Not a pure module */ diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 75dfe915af..22ef6f2793 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -269546,6 +269546,12 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } + | Pexp_ident _ -> + { + pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); + pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; + } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index a8c679ca54..489a14c90a 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -271009,6 +271009,12 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } + | Pexp_ident _ -> + { + pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); + pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; + } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 1b32d1bdfc..14f813a600 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -281299,6 +281299,12 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } + | Pexp_ident _ -> + { + pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); + pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; + } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, From 16a42b70d675f7b69f008ea659754c01e264fd52 Mon Sep 17 00:00:00 2001 From: Woonki Moon Date: Sat, 23 Jul 2022 16:45:33 +0900 Subject: [PATCH 3/3] fix pipe "-> eats up attrs in comprehensive cases --- jscomp/frontend/ast_exp_apply.ml | 10 +++------- lib/4.06.1/unstable/js_compiler.ml | 10 +++------- lib/4.06.1/unstable/js_playground_compiler.ml | 10 +++------- lib/4.06.1/whole_compiler.ml | 10 +++------- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/jscomp/frontend/ast_exp_apply.ml b/jscomp/frontend/ast_exp_apply.ml index 90e9ab8c21..817facc16c 100644 --- a/jscomp/frontend/ast_exp_apply.ml +++ b/jscomp/frontend/ast_exp_apply.ml @@ -128,12 +128,6 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } - | Pexp_ident _ -> - { - pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); - pexp_loc = e.pexp_loc; - pexp_attributes = e.pexp_attributes; - } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, @@ -186,7 +180,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_attributes = []; pexp_loc = loc; } - | _ -> Ast_compatible.app1 ~loc fn new_obj_arg)) + | _ -> + Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn + new_obj_arg)) | Some { op = "##"; loc; args = [ obj; rest ] } -> ( (* - obj##property - obj#(method a b ) diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 22ef6f2793..481c949428 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -269546,12 +269546,6 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } - | Pexp_ident _ -> - { - pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); - pexp_loc = e.pexp_loc; - pexp_attributes = e.pexp_attributes; - } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, @@ -269604,7 +269598,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_attributes = []; pexp_loc = loc; } - | _ -> Ast_compatible.app1 ~loc fn new_obj_arg)) + | _ -> + Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn + new_obj_arg)) | Some { op = "##"; loc; args = [ obj; rest ] } -> ( (* - obj##property - obj#(method a b ) diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 489a14c90a..0d25a58228 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -271009,12 +271009,6 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } - | Pexp_ident _ -> - { - pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); - pexp_loc = e.pexp_loc; - pexp_attributes = e.pexp_attributes; - } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, @@ -271067,7 +271061,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_attributes = []; pexp_loc = loc; } - | _ -> Ast_compatible.app1 ~loc fn new_obj_arg)) + | _ -> + Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn + new_obj_arg)) | Some { op = "##"; loc; args = [ obj; rest ] } -> ( (* - obj##property - obj#(method a b ) diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 14f813a600..a7f38284a1 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -281299,12 +281299,6 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_loc = e.pexp_loc; pexp_attributes = e.pexp_attributes; } - | Pexp_ident _ -> - { - pexp_desc = Pexp_apply (fn, [ (Nolabel, new_obj_arg) ]); - pexp_loc = e.pexp_loc; - pexp_attributes = e.pexp_attributes; - } | _ -> ( match Ast_open_cxt.destruct fn [] with | ( { pexp_desc = Pexp_tuple xs; pexp_attributes = tuple_attrs }, @@ -281357,7 +281351,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) pexp_attributes = []; pexp_loc = loc; } - | _ -> Ast_compatible.app1 ~loc fn new_obj_arg)) + | _ -> + Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn + new_obj_arg)) | Some { op = "##"; loc; args = [ obj; rest ] } -> ( (* - obj##property - obj#(method a b )