diff --git a/CHANGELOG.md b/CHANGELOG.md index e8dd113c65..581b0d1b21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,7 @@ These are only breaking changes for unformatted code. - Fix printing of uncurried application when the lhs is a function definition https://github.com/rescript-lang/rescript-compiler/pull/6084 - Fix parsing uncurried type starting with path https://github.com/rescript-lang/rescript-compiler/pull/6089 - Fix bigInt comparison https://github.com/rescript-lang/rescript-compiler/pull/6097 +- Fixed a bug where the async attribute was not preserved when using the `@this` decorator in ReScript functions. This fix allows proper handling of async functions with the `@this` decorator. Issue: https://github.com/rescript-lang/rescript-compiler/issues/6100 #### :nail_care: Polish diff --git a/jscomp/frontend/ast_uncurry_gen.ml b/jscomp/frontend/ast_uncurry_gen.ml index 71ebc172ed..f67bb81e1c 100644 --- a/jscomp/frontend/ast_uncurry_gen.ml +++ b/jscomp/frontend/ast_uncurry_gen.ml @@ -34,18 +34,18 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label Bs_syntaxerr.optional_err loc label; let rec aux acc (body : Parsetree.expression) = match Ast_attributes.process_attributes_rev body.pexp_attributes with - | Nothing, _ -> ( + | Nothing, attrs -> ( match body.pexp_desc with | Pexp_fun (arg_label, _, arg, body) -> Bs_syntaxerr.optional_err loc arg_label; - aux ((arg_label, self.pat self arg) :: acc) body + aux ((arg_label, self.pat self arg, attrs) :: acc) body | _ -> (self.expr self body, acc)) | _, _ -> (self.expr self body, acc) in - let result, rev_extra_args = aux [ (label, self_pat) ] body in + let result, rev_extra_args = aux [ (label, self_pat, []) ] body in let body = - Ext_list.fold_left rev_extra_args result (fun e (label, p) -> - Ast_helper.Exp.fun_ ~loc label None p e) + Ext_list.fold_left rev_extra_args result (fun e (label, p, attrs) -> + Ast_helper.Exp.fun_ ~loc ~attrs label None p e) in let arity = List.length rev_extra_args in let arity_s = string_of_int arity in diff --git a/jscomp/test/UncurriedExternals.js b/jscomp/test/UncurriedExternals.js index 73837d340d..d9007c054a 100644 --- a/jscomp/test/UncurriedExternals.js +++ b/jscomp/test/UncurriedExternals.js @@ -71,6 +71,13 @@ var StandardNotation = { set: StandardNotation_set }; +function methodWithAsync(param) { + var $$this = this ; + return (async function (arg) { + return $$this + arg | 0; + })(param); +} + function dd$1(param) { throw { RE_EXN_ID: "Not_found", @@ -120,11 +127,19 @@ var match$1 = React.useState(function (param) { return 3; }); +function methodWithAsyncU() { + var $$this = this ; + return async function (arg) { + return $$this + arg | 0; + }; +} + var get = match$1[0]; var set = match$1[1]; exports.StandardNotation = StandardNotation; +exports.methodWithAsync = methodWithAsync; exports.dd = dd$1; exports.h = h$1; exports.M = M$1; @@ -138,4 +153,5 @@ exports.tsiC = tsiC$1; exports.tsiU = tsiU$1; exports.get = get; exports.set = set; +exports.methodWithAsyncU = methodWithAsyncU; /* h Not a pure module */ diff --git a/jscomp/test/UncurriedExternals.res b/jscomp/test/UncurriedExternals.res index 7cea6830a1..baf95a0474 100644 --- a/jscomp/test/UncurriedExternals.res +++ b/jscomp/test/UncurriedExternals.res @@ -39,6 +39,8 @@ module StandardNotation = { let (get, set) = useState(() => 3) } +let methodWithAsync = @this this => async arg => this + arg + @@uncurried.swap external raise: exn => 'a = "%raise" @@ -78,3 +80,5 @@ let tsiU = c => setIncrementU(c, @this (me, amount) => Js.log(. me)) @module("react") external useState: (@uncurry (unit => 'state)) => ('state, ('state => 'state) => unit) = "useState" let (get, set) = useState(() => 3) + +let methodWithAsyncU = @this this => async arg => this + arg