Skip to content

Commit d8815e6

Browse files
committed
support utf8 in tagged templates
1 parent e4439c9 commit d8815e6

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

jscomp/syntax/src/res_core.ml

Lines changed: 1 addition & 2 deletions
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

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)