Skip to content

Commit

Permalink
support utf8 in tagged templates (fixes #6750) (#6810)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnobip authored and cknitt committed Jun 16, 2024
1 parent c148a3d commit 9de2ad1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fix issue where optional labels were not taken into account when disambiguating record value construction. https://github.com/rescript-lang/rescript-compiler/pull/6798
- Fix issue in gentype when type `Jsx.element` surfaces to the user. https://github.com/rescript-lang/rescript-compiler/pull/6808
- 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
- Fix encoding inside tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6810

# 11.1.1

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 @@ -2265,8 +2265,7 @@ and parseTemplateExpr ?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 startPos = p.Parser.startPos 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

0 comments on commit 9de2ad1

Please sign in to comment.