Skip to content

Commit 23069b1

Browse files
committed
support utf8 in tagged templates (fixes #6750)
1 parent e4439c9 commit 23069b1

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#### :bug: Bug Fix
2929

30+
- Fix encoding inside tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6810
3031
- Fix unhandled cases for exotic idents (allow to use exotic PascalCased identifiers for types). https://github.com/rescript-lang/rescript-compiler/pull/6777
3132
- 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
3233
- Fix unused attribute check for `@as`. https://github.com/rescript-lang/rescript-compiler/pull/6795

jscomp/syntax/src/res_core.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2284,8 +2284,7 @@ and parse_template_expr ?prefix p =
22842284
match prefix with
22852285
| Some {txt = Longident.Lident (("js" | "j" | "json") as prefix); _} ->
22862286
Some prefix
2287-
| Some _ -> None
2288-
| None -> Some "js"
2287+
| _ -> Some "js"
22892288
in
22902289
let start_pos = p.Parser.start_pos in
22912290

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
let s = {js|some unicode é £ |js}
2+
let s = (({js|foo|js})[@res.template ])
3+
let s =
4+
(((((({js|foo |js})[@res.template ]) ^ bar)[@res.template ]) ^
5+
(({js| baz|js})[@res.template ]))
6+
[@res.template ])
7+
let s =
8+
(((((({js|some unicode é |js})[@res.template ]) ^ bar)[@res.template ]) ^
9+
(({js| £ |js})[@res.template ]))
10+
[@res.template ])
11+
let s = ((x [|(({js|foo|js})[@res.template ])|] [||])[@res.taggedTemplate ])
12+
let s =
13+
((x [|(({js|foo |js})[@res.template ]);(({js| baz|js})[@res.template ])|]
14+
[|bar|])
15+
[@res.taggedTemplate ])
16+
let s =
17+
((x
18+
[|(({js|some unicode é |js})[@res.template ]);(({js| £ |js})
19+
[@res.template ])|] [|bar|])
20+
[@res.taggedTemplate ])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let s = "some unicode é £ "
2+
let s = `foo`
3+
let s = `foo ${bar} baz`
4+
let s = `some unicode é ${bar} £ `
5+
let s = x`foo`
6+
let s = x`foo ${bar} baz`
7+
let s = x`some unicode é ${bar} £ `

jscomp/test/tagged_template_test.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/tagged_template_test.res

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let foo = (strings, values) => {
2626
res.contents ++ strings[valueCount]
2727
}
2828

29-
let res = foo`| 5 * 10 = ${5} |`
29+
let res = foo`| 5 × 10 = ${5} |`
3030

3131
Mt.from_pair_suites(
3232
"tagged templates",
@@ -44,8 +44,8 @@ Mt.from_pair_suites(
4444
() => Eq(length, 52),
4545
),
4646
(
47-
"with rescript function, it should return a string with the correct interpolations",
48-
() => Eq(res, "| 5 * 10 = 50 |"),
47+
"with rescript function, it should return a string with the correct encoding and interpolations",
48+
() => Eq(res, "| 5 × 10 = 50 |"),
4949
),
5050
(
5151
"a template literal tagged with json should generate a regular string interpolation for now",

0 commit comments

Comments
 (0)