Skip to content

support utf8 in tagged templates #6810

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

Merged
merged 1 commit into from
Jun 15, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#### :bug: Bug Fix

- Fix encoding inside tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6810
- Fix unhandled cases for exotic idents (allow to use exotic PascalCased identifiers for types). https://github.com/rescript-lang/rescript-compiler/pull/6777
- PPX v4: mark props type in externals as `@live` to avoid dead code warnings for prop fields in the editor tooling. https://github.com/rescript-lang/rescript-compiler/pull/6796
- Fix unused attribute check for `@as`. https://github.com/rescript-lang/rescript-compiler/pull/6795
Expand Down
3 changes: 1 addition & 2 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2284,8 +2284,7 @@ and parse_template_expr ?prefix p =
match prefix with
| Some {txt = Longident.Lident (("js" | "j" | "json") as prefix); _} ->
Some prefix
| Some _ -> None
| None -> Some "js"
| _ -> Some "js"
in
let start_pos = p.Parser.start_pos in

Expand Down
20 changes: 20 additions & 0 deletions jscomp/syntax/tests/parsing/other/expected/stringLiterals.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let s = {js|some unicode é £ |js}
let s = (({js|foo|js})[@res.template ])
let s =
(((((({js|foo |js})[@res.template ]) ^ bar)[@res.template ]) ^
(({js| baz|js})[@res.template ]))
[@res.template ])
let s =
(((((({js|some unicode é |js})[@res.template ]) ^ bar)[@res.template ]) ^
(({js| £ |js})[@res.template ]))
[@res.template ])
let s = ((x [|(({js|foo|js})[@res.template ])|] [||])[@res.taggedTemplate ])
let s =
((x [|(({js|foo |js})[@res.template ]);(({js| baz|js})[@res.template ])|]
[|bar|])
[@res.taggedTemplate ])
let s =
((x
[|(({js|some unicode é |js})[@res.template ]);(({js| £ |js})
[@res.template ])|] [|bar|])
[@res.taggedTemplate ])
7 changes: 7 additions & 0 deletions jscomp/syntax/tests/parsing/other/stringLiterals.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let s = "some unicode é £ "
let s = `foo`
let s = `foo ${bar} baz`
let s = `some unicode é ${bar} £ `
let s = x`foo`
let s = x`foo ${bar} baz`
let s = x`some unicode é ${bar} £ `
6 changes: 3 additions & 3 deletions jscomp/test/tagged_template_test.js

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

6 changes: 3 additions & 3 deletions jscomp/test/tagged_template_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let foo = (strings, values) => {
res.contents ++ strings[valueCount]
}

let res = foo`| 5 * 10 = ${5} |`
let res = foo`| 5 × 10 = ${5} |`

Mt.from_pair_suites(
"tagged templates",
Expand All @@ -44,8 +44,8 @@ Mt.from_pair_suites(
() => Eq(length, 52),
),
(
"with rescript function, it should return a string with the correct interpolations",
() => Eq(res, "| 5 * 10 = 50 |"),
"with rescript function, it should return a string with the correct encoding and interpolations",
() => Eq(res, "| 5 × 10 = 50 |"),
),
(
"a template literal tagged with json should generate a regular string interpolation for now",
Expand Down