Skip to content

Commit d9e13a2

Browse files
tsnobipcknitt
authored andcommitted
support utf8 in tagged templates (fixes #6750) (#6810)
1 parent 940f517 commit d9e13a2

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Fix issue where optional labels were not taken into account when disambiguating record value construction. https://github.com/rescript-lang/rescript-compiler/pull/6798
2020
- Fix issue in gentype when type `Jsx.element` surfaces to the user. https://github.com/rescript-lang/rescript-compiler/pull/6808
2121
- Fix inclusion check (impl vs interface) for untagged variants, and fix the outcome printer to show tags. https://github.com/rescript-lang/rescript-compiler/pull/6669
22+
- Fix encoding inside tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6810
2223

2324
# 11.1.1
2425

jscomp/syntax/src/res_core.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,8 +2265,7 @@ and parseTemplateExpr ?prefix p =
22652265
match prefix with
22662266
| Some {txt = Longident.Lident (("js" | "j" | "json") as prefix); _} ->
22672267
Some prefix
2268-
| Some _ -> None
2269-
| None -> Some "js"
2268+
| _ -> Some "js"
22702269
in
22712270
let startPos = p.Parser.startPos in
22722271

Lines changed: 20 additions & 0 deletions
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 ])
Lines changed: 7 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/tagged_template_test.res

Lines changed: 3 additions & 3 deletions
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)