diff --git a/CHANGELOG.md b/CHANGELOG.md index f189ddb803..ebd1deee81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ - Initial support for JSX V4, still work in progress. - :boom: when V4 is activated, at most one component is allowed for each module. +#### :bug: Bug Fix + +- Fix issue where pipe `->` processing eats up attributes https://github.com/rescript-lang/rescript-compiler/pull/5581 + #### :nail_care: Polish - Print patterns in warnings using rescript printer https://github.com/rescript-lang/rescript-compiler/pull/5492 diff --git a/jscomp/frontend/ast_exp_apply.ml b/jscomp/frontend/ast_exp_apply.ml index 304de42b0c..847340b252 100644 --- a/jscomp/frontend/ast_exp_apply.ml +++ b/jscomp/frontend/ast_exp_apply.ml @@ -70,7 +70,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option = | _ -> None let inner_ops = [ "##"; "#@" ] - let infix_ops = [ "|."; "#="; "##" ] let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) @@ -110,16 +109,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) let fn = self.expr self fn in match fn.pexp_desc with | Pexp_variant (label, None) -> - { fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc } + { + fn with + pexp_desc = Pexp_variant (label, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } | Pexp_construct (ctor, None) -> - { fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc } - | Pexp_apply (fn, args) -> + { + fn with + pexp_desc = Pexp_construct (ctor, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } + | Pexp_apply (fn1, args) -> Bs_ast_invariant.warn_discarded_unused_attributes - fn.pexp_attributes; + fn1.pexp_attributes; { - pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args); - pexp_attributes = []; + pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args); pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; } | _ -> ( match Ast_open_cxt.destruct fn [] with diff --git a/jscomp/test/res_debug.js b/jscomp/test/res_debug.js index e69bda1ade..7ae8a31c70 100644 --- a/jscomp/test/res_debug.js +++ b/jscomp/test/res_debug.js @@ -1,6 +1,8 @@ 'use strict'; +var Curry = require("../../lib/js/curry.js"); var Caml_obj = require("../../lib/js/caml_obj.js"); +var Caml_option = require("../../lib/js/caml_option.js"); function f($$window, a, b) { return $$window.location(a, b); @@ -24,6 +26,29 @@ function testMatch(v) { } } +function optionMap(x, f) { + if (x !== undefined) { + return Caml_option.some(Curry._1(f, Caml_option.valFromOption(x))); + } + +} + +var ok_name = optionMap(undefined, (function (x) { + return x; + })); + +var ok = { + name: ok_name +}; + +var bad_name = optionMap(undefined, (function (x) { + return x; + })); + +var bad = { + name: bad_name +}; + var v2 = newrecord; var v1 = { @@ -35,6 +60,8 @@ var h = /* '\522' */128522; var hey = "hello, δΈ–η•Œ"; +var name; + exports.f = f; exports.v0 = v0; exports.v2 = v2; @@ -42,4 +69,8 @@ exports.v1 = v1; exports.testMatch = testMatch; exports.h = h; exports.hey = hey; +exports.optionMap = optionMap; +exports.name = name; +exports.ok = ok; +exports.bad = bad; /* Not a pure module */ diff --git a/jscomp/test/res_debug.res b/jscomp/test/res_debug.res index a74a48535f..e2cae86f9f 100644 --- a/jscomp/test/res_debug.res +++ b/jscomp/test/res_debug.res @@ -53,3 +53,16 @@ let testMatch = v => let h = '😊' let hey = "hello, δΈ–η•Œ" // failed to type check + +let optionMap = (x, f) => + switch x { + | None => None + | Some(v) => Some(f(v)) + } + +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 diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 117b803a57..47e01766e9 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -269488,7 +269488,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option = | _ -> None let inner_ops = [ "##"; "#@" ] - let infix_ops = [ "|."; "#="; "##" ] let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) @@ -269528,16 +269527,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) let fn = self.expr self fn in match fn.pexp_desc with | Pexp_variant (label, None) -> - { fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc } + { + fn with + pexp_desc = Pexp_variant (label, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } | Pexp_construct (ctor, None) -> - { fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc } - | Pexp_apply (fn, args) -> + { + fn with + pexp_desc = Pexp_construct (ctor, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } + | Pexp_apply (fn1, args) -> Bs_ast_invariant.warn_discarded_unused_attributes - fn.pexp_attributes; + fn1.pexp_attributes; { - pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args); - pexp_attributes = []; + pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args); pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; } | _ -> ( match Ast_open_cxt.destruct fn [] with diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index cef995eaf0..63bbe0978a 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -270951,7 +270951,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option = | _ -> None let inner_ops = [ "##"; "#@" ] - let infix_ops = [ "|."; "#="; "##" ] let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) @@ -270991,16 +270990,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) let fn = self.expr self fn in match fn.pexp_desc with | Pexp_variant (label, None) -> - { fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc } + { + fn with + pexp_desc = Pexp_variant (label, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } | Pexp_construct (ctor, None) -> - { fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc } - | Pexp_apply (fn, args) -> + { + fn with + pexp_desc = Pexp_construct (ctor, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } + | Pexp_apply (fn1, args) -> Bs_ast_invariant.warn_discarded_unused_attributes - fn.pexp_attributes; + fn1.pexp_attributes; { - pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args); - pexp_attributes = []; + pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args); pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; } | _ -> ( match Ast_open_cxt.destruct fn [] with diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 096691d32d..c0177feed6 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -281241,7 +281241,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option = | _ -> None let inner_ops = [ "##"; "#@" ] - let infix_ops = [ "|."; "#="; "##" ] let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) @@ -281281,16 +281280,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp) let fn = self.expr self fn in match fn.pexp_desc with | Pexp_variant (label, None) -> - { fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc } + { + fn with + pexp_desc = Pexp_variant (label, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } | Pexp_construct (ctor, None) -> - { fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc } - | Pexp_apply (fn, args) -> + { + fn with + pexp_desc = Pexp_construct (ctor, Some new_obj_arg); + pexp_loc = e.pexp_loc; + } + | Pexp_apply (fn1, args) -> Bs_ast_invariant.warn_discarded_unused_attributes - fn.pexp_attributes; + fn1.pexp_attributes; { - pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args); - pexp_attributes = []; + pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args); pexp_loc = e.pexp_loc; + pexp_attributes = e.pexp_attributes; } | _ -> ( match Ast_open_cxt.destruct fn [] with