Skip to content
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

Preserve unicode format strings #1001

Merged
merged 3 commits into from
Dec 26, 2023
Merged
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
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Unreleased
([#995](https://github.com/melange-re/melange/pull/995))
- PPXes will no longer see the internal `*j` delimiter in unicode strings
and can hook on either `j` or `js`
- Preserve unicode in format strings
([#1001](https://github.com/melange-re/melange/pull/1001))

2.2.0 2023-12-05
---------------
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions test/blackbox-tests/unicode-format-strings.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

$ . ./setup.sh
$ cat > dune-project <<EOF
> (lang dune 3.8)
> (using melange 0.1)
> EOF
$ cat > dune <<EOF
> (melange.emit
> (target output)
> (alias mel)
> (preprocess (pps melange.ppx)))
> EOF

$ cat > x.ml <<EOF
> let () = Js.log (Format.sprintf {js|你 %s|js} "xx")
> EOF

$ dune build @mel
$ cat _build/default/output/x.js
// Generated by Melange
'use strict';

var Curry = require("melange.js/curry.js");
var Stdlib__Format = require("melange/format.js");

console.log(Curry._1(Stdlib__Format.sprintf(/* Format */{
_0: {
TAG: /* String_literal */11,
_0: "你 ",
_1: {
TAG: /* String */2,
_0: /* No_padding */0,
_1: /* End_of_format */0
}
},
_1: "你 %s"
}), "xx"));

/* Not a pure module */

$ node _build/default/output/x.js
你 xx

Show that `{j| ... |j}` with interpolation doesn't work because string
concatenation isn't a literal

$ cat > x.ml <<EOF
> let x = "xx"
> let () = Js.log (Format.sprintf {j|你 \$(x) %s|j} "xx")
> EOF
$ dune build @mel
File "x.ml", line 1:
Error: This expression has type string but an expression was expected of type
('a -> 'b, unit, string) format =
('a -> 'b, unit, string, string, string, string) format6
[1]
2 changes: 1 addition & 1 deletion vendor/melange-compiler-libs