diff --git a/Makefile b/Makefile index 97ae9dbfcc..f1dac0b062 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ dev: .PHONY: test test: - opam exec -- dune runtest -p melange,reactjs-jsx-ppx + opam exec -- dune runtest -p melange,reactjs-jsx-ppx,rescript-syntax .PHONY: opam-create-switch opam-create-switch: ## Create opam switch diff --git a/rescript-syntax/ppx_rescript_compat/ppx_rescript_compat.ml b/rescript-syntax/ppx_rescript_compat/ppx_rescript_compat.ml index 99bc7fbb89..b160276d83 100644 --- a/rescript-syntax/ppx_rescript_compat/ppx_rescript_compat.ml +++ b/rescript-syntax/ppx_rescript_compat/ppx_rescript_compat.ml @@ -47,10 +47,11 @@ let expr_mapper (self : mapper) (expr : Parsetree.expression) = args; } | Pexp_send - ( ({ pexp_desc = Pexp_apply _ | Pexp_ident _; pexp_loc; _ } as subexpr), + ( ({ pexp_desc = Pexp_apply _ | Pexp_ident _ | Pexp_send _; pexp_loc; _ } as subexpr), arg ) -> (* ReScript removed the OCaml object system and abuses `Pexp_send` for `obj##property`. Here, we make that conversion. *) + let subexpr = self.expr self subexpr in { expr with pexp_desc = diff --git a/test/rescript-syntax/dune b/test/rescript-syntax/dune new file mode 100644 index 0000000000..69d36bd3ec --- /dev/null +++ b/test/rescript-syntax/dune @@ -0,0 +1,3 @@ +(cram + (package rescript-syntax) + (deps %{bin:melc} %{bin:rescript_syntax})) diff --git a/test/rescript-syntax/gh489.t b/test/rescript-syntax/gh489.t new file mode 100644 index 0000000000..27ab2ed014 --- /dev/null +++ b/test/rescript-syntax/gh489.t @@ -0,0 +1,42 @@ +Repro for GitHub issue 489, first try setting values in nested objects with OCaml syntax + + $ cat > foo.ml < type person = < age :int [@bs.set ] > Js.t + > type entry = < person :person [@bs.set ] > Js.t + > external entry : entry = "entry"[@@bs.val ] + > let () = ((entry ## person) ## age) #= 99 + > EOF + $ melc foo.ml + // Generated by Melange + 'use strict'; + + + entry.person.age = 99; + + /* Not a pure module */ + +Now let's try with ReScript syntax + + $ cat > foo.res < type person = {@set "age": int} + > type entry = {@set "person": person} + > type deep = {@set "deep": entry} + > @val external deep: deep = "deep" + > deep["deep"]["person"]["age"] = 99 + $ rescript_syntax -print=ml foo.res + type nonrec person = < age: int [@set ] > Js.t + type nonrec entry = < person: person [@set ] > Js.t + type nonrec deep = < deep: entry [@set ] > Js.t + external deep : deep = "deep"[@@val ] + ;;(((deep ## deep) ## person) ## age) #= 99 + + $ rescript_syntax -print=ml foo.res > foo.ml + + $ melc foo.ml + // Generated by Melange + 'use strict'; + + + deep.deep.person.age = 99; + + /* Not a pure module */