Skip to content

Commit 74a4bf8

Browse files
committed
make j and js allowed names for tag functions
1 parent 6e22765 commit 74a4bf8

File tree

29 files changed

+101
-90
lines changed

29 files changed

+101
-90
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#### :boom: Breaking Change
2323

24+
- Make `j` and `js` allowed names for tag functions. https://github.com/rescript-lang/rescript-compiler/pull/6817
2425
- `lazy` syntax is no longer supported. If you're using it, use `Lazy` module or `React.lazy_` instead. https://github.com/rescript-lang/rescript-compiler/pull/6342
2526
- Remove handling of attributes with `bs.` prefix (`@bs.as` -> `@as` etc.). https://github.com/rescript-lang/rescript-compiler/pull/6643
2627
- Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
We've found a bug for you!
3-
/.../fixtures/jinterp.res:3:10-21
3+
/.../fixtures/jinterp.res:3:9
44

55
1 │
66
2 │ let a = 11
7-
3 │ let b = j`number $(a)`
7+
3 │ let b = j`number $(a)`
88

9-
The unsafe j`$(a)$(b)` interpolation was removed, use string template `${a}${b}` instead.
9+
The value j can't be found

jscomp/frontend/ast_utf8_string_interp.ml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,8 @@ module Delim = struct
280280
type interpolation =
281281
| Js (* string interpolation *)
282282
| Unrecognized (* no interpolation: delimiter not recognized *)
283-
let parse_unprocessed loc = function
283+
let parse_unprocessed = function
284284
| "js" -> Js
285-
| "j" ->
286-
Location.raise_errorf ~loc
287-
"The unsafe j`$(a)$(b)` interpolation was removed, use string template \
288-
`${a}${b}` instead."
289285
| _ -> Unrecognized
290286

291287
let escaped_j_delimiter = "*j" (* not user level syntax allowed *)
@@ -294,14 +290,14 @@ module Delim = struct
294290
end
295291

296292
let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
297-
match Delim.parse_unprocessed e.pexp_loc delim with
293+
match Delim.parse_unprocessed delim with
298294
| Js ->
299295
let js_str = Ast_utf8_string.transform e.pexp_loc s in
300296
{e with pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped))}
301297
| Unrecognized -> e
302298

303299
let transform_pat (p : Parsetree.pattern) s delim : Parsetree.pattern =
304-
match Delim.parse_unprocessed p.ppat_loc delim with
300+
match Delim.parse_unprocessed delim with
305301
| Js ->
306302
let js_str = Ast_utf8_string.transform p.ppat_loc s in
307303
{p with ppat_desc = Ppat_constant (Pconst_string (js_str, Delim.escaped))}

jscomp/syntax/src/res_core.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ and parse_primary_expr ~operand ?(no_call = false) p =
21042104
~end_pos:expr.pexp_loc.loc_end p
21052105
(Diagnostics.message
21062106
"Tagged template literals are currently restricted to names like: \
2107-
json`null`.");
2107+
myTagFunction`foo ${bar}`.");
21082108
parse_template_expr p)
21092109
| _ -> expr
21102110
in
@@ -2279,11 +2279,10 @@ and parse_binary_expr ?(context = OrdinaryExpr) ?a p prec =
22792279

22802280
and parse_template_expr ?prefix p =
22812281
let part_prefix =
2282-
(* we could stop treating js and j prefix as something special
2283-
for json, we would first need to remove @as(json`true`) feature *)
2282+
(* we could stop treating json prefix as something special
2283+
but we would first need to remove @as(json`true`) feature *)
22842284
match prefix with
2285-
| Some {txt = Longident.Lident (("js" | "j" | "json") as prefix); _} ->
2286-
Some prefix
2285+
| Some {txt = Longident.Lident ("json" as prefix); _} -> Some prefix
22872286
| _ -> Some "js"
22882287
in
22892288

@@ -2367,8 +2366,7 @@ and parse_template_expr ?prefix p =
23672366
in
23682367

23692368
match prefix with
2370-
| Some {txt = Longident.Lident ("js" | "j" | "json"); _} | None ->
2371-
gen_interpolated_string ()
2369+
| Some {txt = Longident.Lident "json"; _} | None -> gen_interpolated_string ()
23722370
| Some lident_loc -> gen_tagged_template_call lident_loc
23732371

23742372
(* Overparse: let f = a : int => a + 1, is it (a : int) => or (a): int =>

jscomp/syntax/tests/conversion/reason/expected/string.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ let y = "\n"
1111
(<> {"\n"->React.string} </>)
1212

1313
// The `//` should not result into an extra comment
14-
let x = j`https://www.apple.com`
14+
let x = `https://www.apple.com`
1515
let x = `https://www.apple.com`
1616
let x = `https://www.apple.com`
1717
let x = `https://www.apple.com`
1818
let x = sql`https://www.apple.com`
1919

2020
// /* */ should not result in an extra comments
21-
let x = j`/* https://www.apple.com */`
21+
let x = `/* https://www.apple.com */`
2222
let x = `/* https://www.apple.com*/`
2323
let x = `/*https://www.apple.com*/`
2424
let x = `/*https://www.apple.com*/`

jscomp/syntax/tests/conversion/reason/string.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ let y = "\n"
1111
(<> {"\n"->React.string} </>)
1212

1313
// The `//` should not result into an extra comment
14-
let x = j`https://www.apple.com`
14+
let x = `https://www.apple.com`
1515
let x = `https://www.apple.com`
1616
let x = `https://www.apple.com`
1717
let x = `https://www.apple.com`
1818
let x = sql`https://www.apple.com`
1919

2020
// /* */ should not result in an extra comments
21-
let x = j`/* https://www.apple.com */`
21+
let x = `/* https://www.apple.com */`
2222
let x = `/* https://www.apple.com*/`
2323
let x = `/*https://www.apple.com*/`
2424
let x = `/*https://www.apple.com*/`

jscomp/syntax/tests/idempotency/bs-css/Css_AtomicTypes.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ module Content = {
18021802
| #noOpenQuote => "no-open-quote"
18031803
| #noCloseQuote => "no-close-quote"
18041804
| #attr(name) => "attr(" ++ (name ++ ")")
1805-
| #text(string) => j`"$string"`
1805+
| #text(string) => `"$string"`
18061806
}
18071807
}
18081808

jscomp/syntax/tests/idempotency/bs-css/Css_Js_Core.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,8 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
16901690
src
16911691
->Belt.Array.map(x =>
16921692
switch x {
1693-
| #localUrl(value) => j`local("$(value)")`
1694-
| #url(value) => j`url("$(value)")`
1693+
| #localUrl(value) => `local("$(value)")`
1694+
| #url(value) => `url("$(value)")`
16951695
}
16961696
)
16971697
->join(", ")
@@ -1710,7 +1710,7 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
17101710
"font-display: " ++ (FontDisplay.toString(f) ++ ";")
17111711
)
17121712

1713-
j`@font-face {
1713+
`@font-face {
17141714
font-family: $fontFamily;
17151715
src: $src;
17161716
$(fontStyle)

jscomp/syntax/tests/idempotency/bs-css/Css_Legacy_Core.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,8 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
17011701
src
17021702
|> List.map(x =>
17031703
switch x {
1704-
| #localUrl(value) => j`local("$(value)")`
1705-
| #url(value) => j`url("$(value)")`
1704+
| #localUrl(value) => `local("$(value)")`
1705+
| #url(value) => `url("$(value)")`
17061706
}
17071707
)
17081708
|> String.concat(", ")
@@ -1721,7 +1721,7 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
17211721
"font-display: " ++ (FontDisplay.toString(f) ++ ";")
17221722
)
17231723

1724-
j`@font-face {
1724+
`@font-face {
17251725
font-family: $fontFamily;
17261726
src: $src;
17271727
$(fontStyle)

jscomp/syntax/tests/idempotency/covid-19charts.com/src/UseQueryParam.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ let hook = (makeInitial, ~queryFragment, ~coder) => {
2828

2929
{
3030
open Window
31-
window.history.replaceState(. state, "", j`$protocol//$host$pathname$search`)
31+
window.history.replaceState(. state, "", `$protocol//$host$pathname$search`)
3232
}
3333

3434
None

0 commit comments

Comments
 (0)