Skip to content

Commit 74a4bf8

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

29 files changed

+101
-90
lines changed

CHANGELOG.md

+1
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
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

+3-7
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

+5-7
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

+2-2
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

+2-2
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

+1-1
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

+3-3
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

+3-3
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

+1-1
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

jscomp/syntax/tests/idempotency/nook-exchange/FriendsPage.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ module Followee = {
243243
})}
244244
/>
245245
</Link>
246-
: <div> {React.string(followee.username ++ (" has no items! " ++ j`😞`))} </div>}
246+
: <div> {React.string(followee.username ++ (" has no items! " ++ `😞`))} </div>}
247247
</div>
248248
: React.null}
249249
</div>

jscomp/syntax/tests/idempotency/nook-exchange/ImportPage.res

+6-6
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ type itemDestination = [
148148

149149
let itemDestinationToEmoji = destination =>
150150
switch destination {
151-
| #ForTrade => j`🤝`
152-
| #CanCraft => j`🔨`
153-
| #CatalogOnly => j`📖`
154-
| #Wishlist => j`🙏`
155-
| #Ignore => j`🤝`
151+
| #ForTrade => `🤝`
152+
| #CanCraft => `🔨`
153+
| #CatalogOnly => `📖`
154+
| #Wishlist => `🙏`
155+
| #Ignore => `🤝`
156156
}
157157

158158
module VariantRow = {
@@ -729,7 +729,7 @@ let make = (~showLogin, ~url: ReasonReactRouter.url) => {
729729
setIsFetchingFromCatalogScanner(_ => true)
730730
%Repromise.Js({
731731
let response = Fetch.fetchWithInit(
732-
j`https://ehsan.lol/$catalogScannerId/raw`,
732+
`https://ehsan.lol/$catalogScannerId/raw`,
733733
Fetch.RequestInit.make(~method_=Get, ~mode=CORS, ()),
734734
)
735735
setIsFetchingFromCatalogScanner(_ => false)

jscomp/syntax/tests/idempotency/nook-exchange/ItemCard.res

+3-3
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,9 @@ let make = (~item: Item.t, ~isLoggedIn, ~showLogin) => {
544544
</span>
545545
{React.string(
546546
switch userItem.status {
547-
| Wishlist => j`In your Wishlist`
548-
| ForTrade => j`In your For Trade list`
549-
| CanCraft => j`In your Can Craft list`
547+
| Wishlist => `In your Wishlist`
548+
| ForTrade => `In your For Trade list`
549+
| CanCraft => `In your Can Craft list`
550550
| _ => raise(Constants.Uhoh)
551551
},
552552
)}

jscomp/syntax/tests/idempotency/nook-exchange/ItemDetailOverlay.res

+3-3
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ module MyStatusSection = {
391391
</span>
392392
{React.string(
393393
switch userItem.status {
394-
| Wishlist => j`In your Wishlist`
395-
| ForTrade => j`In your For Trade list`
396-
| CanCraft => j`In your Can Craft list`
394+
| Wishlist => `In your Wishlist`
395+
| ForTrade => `In your For Trade list`
396+
| CanCraft => `In your Can Craft list`
397397
| _ => raise(Constants.Uhoh)
398398
},
399399
)}

jscomp/syntax/tests/idempotency/nook-exchange/SettingsStore.res

+14-14
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ let languages: array<language> = [
3535

3636
let languageToString = (language: language) =>
3737
switch language {
38-
| #German => j`Deutsch`
39-
| #SpanishEurope => j`Español (Europe)`
40-
| #SpanishAmerica => j`Español (America)`
41-
| #FrenchEurope => j`Français (Europe)`
42-
| #FrenchAmerica => j`Français (America)`
43-
| #Italian => j`Italiano`
44-
| #Japanese => j`日本語`
45-
| #Korean => j`한국어`
46-
| #Dutch => j`Nederlands`
47-
| #Russian => j`Русский`
48-
| #ChineseSimplified => j`中文`
49-
| #ChineseTraditional => j`繁體中文`
50-
| #English => j`English`
51-
| #EnglishEurope => j`English (UK)`
38+
| #German => `Deutsch`
39+
| #SpanishEurope => `Español (Europe)`
40+
| #SpanishAmerica => `Español (America)`
41+
| #FrenchEurope => `Français (Europe)`
42+
| #FrenchAmerica => `Français (America)`
43+
| #Italian => `Italiano`
44+
| #Japanese => `日本語`
45+
| #Korean => `한국어`
46+
| #Dutch => `Nederlands`
47+
| #Russian => `Русский`
48+
| #ChineseSimplified => `中文`
49+
| #ChineseTraditional => `繁體中文`
50+
| #English => `English`
51+
| #EnglishEurope => `English (UK)`
5252
}
5353

5454
@val @scope("navigator")

jscomp/syntax/tests/idempotency/nook-exchange/User.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ type itemStatus =
77

88
let itemStatusToEmoji = itemStatus =>
99
switch itemStatus {
10-
| Wishlist => j`🙏`
11-
| ForTrade => j`🤝`
12-
| CanCraft => j`🔨`
13-
| CatalogOnly => j`📖`
10+
| Wishlist => `🙏`
11+
| ForTrade => `🤝`
12+
| CanCraft => `🔨`
13+
| CatalogOnly => `📖`
1414
}
1515
let itemStatusToString = itemStatus =>
1616
switch itemStatus {

jscomp/syntax/tests/idempotency/nook-exchange/UserItemCard.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ let make = (
211211
onBlur
212212
className=Styles.catalogStatusButton
213213
ref={ReactDOMRe.Ref.domRef(ref)}>
214-
{React.string(userItemStatus == Some(ForTrade) ? j`🤝` : j`🔨`)}
214+
{React.string(userItemStatus == Some(ForTrade) ? `🤝` : `🔨`)}
215215
</div>}
216216
</ReactAtmosphere.Tooltip>
217217
| _ => React.null

jscomp/syntax/tests/idempotency/nook-exchange/ViewingList.res

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ let urlToViewingList = url =>
2121
}
2222
let viewingListToEmoji = viewingList =>
2323
switch viewingList {
24-
| Wishlist => j`🙏`
25-
| ForTrade => j`🤝`
26-
| CanCraft => j`🔨`
27-
| Catalog => j`📖`
24+
| Wishlist => `🙏`
25+
| ForTrade => `🤝`
26+
| CanCraft => `🔨`
27+
| Catalog => `📖`
2828
}
2929
let viewingListToString = viewingList =>
3030
switch viewingList {

jscomp/syntax/tests/idempotency/reason-react-hackernews/StoryData.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ open Belt
22

33
let apiBaseUrl = "https://serverless-api.hackernewsmobile.com"
44

5-
let topStoriesUrl = page => j`$apiBaseUrl/topstories-25-$page.json`
5+
let topStoriesUrl = page => `$apiBaseUrl/topstories-25-$page.json`
66

7-
let storyUrl = id => j`$apiBaseUrl/stories/$id.json`
7+
let storyUrl = id => `$apiBaseUrl/stories/$id.json`
88

99
type story = {
1010
by: string,

jscomp/syntax/tests/idempotency/reasonml.org/components/Navigation.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module CollapsibleLink = {
8888

8989
let useOutsideClick: (ReactDOMRe.Ref.t, unit => unit) => unit = %raw(
9090
(outerRef, trigger) =>
91-
j`{
91+
`{
9292
function handleClickOutside(event) {
9393
if (outerRef.current && !outerRef.current.contains(event.target)) {
9494
trigger();
@@ -107,7 +107,7 @@ let useOutsideClick: (ReactDOMRe.Ref.t, unit => unit) => unit = %raw(
107107

108108
let useWindowWidth: unit => option<int> = %raw(
109109
() =>
110-
j`{
110+
`{
111111
const isClient = typeof window === 'object';
112112
113113
function getSize() {

jscomp/syntax/tests/idempotency/reasonml.org/layouts/DocsLayout.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module Sidebar = {
5757
{Belt.Array.map(items, m => {
5858
let hidden = isHidden ? "hidden" : "block"
5959
let active = isItemActive(m)
60-
? j` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
60+
? ` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
6161
: ""
6262

6363
let activeToc = switch getActiveToc {
@@ -144,7 +144,7 @@ module Sidebar = {
144144
<ul className="mt-3 text-night">
145145
{Belt.Array.map(items, m => {
146146
let active = isItemActive(m)
147-
? j` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
147+
? ` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
148148
: ""
149149
<li key=m.name className="leading-5 w-4/5">
150150
<Link href=m.href>

jscomp/syntax/tests/idempotency/reasonml.org/layouts/SidebarLayout.res

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ module Sidebar = {
142142
{Belt.Array.map(items, m => {
143143
let hidden = isHidden ? "hidden" : "block"
144144
let active = isItemActive(m)
145-
? j` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
145+
? ` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
146146
: ""
147147
<li
148148
key=m.name
@@ -213,7 +213,7 @@ module Sidebar = {
213213
<ul className="mt-3 text-night">
214214
{Belt.Array.mapWithIndex(items, (idx, m) => {
215215
let active = isItemActive(m)
216-
? j` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
216+
? ` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
217217
: ""
218218
<li
219219
key=m.href

jscomp/syntax/tests/idempotency/wildcards-world-ui/ThreeBoxUpdate.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ module TwitterVerification = {
393393
</React.Fragment>
394394
| PreparePostToTwitter => <p> {"Please login to 3box!"->React.string} </p>
395395
| PostToTwitter(did) =>
396-
let link = j`https://twitter.com/intent/tweet?text=This Tweet links my Twitter account to my 3Box profile!\\n%0D%0A%0D%0Ahttps://wildcards.world/%23user/$currentUser\\n%0D%0A%0D%0ASupport Animal conservation @wildcards_world\\n%0D%0A✅\\n%0D%0A$did\\n%0D%0A✅`
396+
let link = `https://twitter.com/intent/tweet?text=This Tweet links my Twitter account to my 3Box profile!\\n%0D%0A%0D%0Ahttps://wildcards.world/%23user/$currentUser\\n%0D%0A%0D%0ASupport Animal conservation @wildcards_world\\n%0D%0A✅\\n%0D%0A$did\\n%0D%0A✅`
397397

398398
<React.Fragment>
399399
<p> {"Post the following proof to twitter"->React.string} </p>

0 commit comments

Comments
 (0)