Skip to content

make j and js allowed names for tag functions #6817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#### :boom: Breaking Change

- Make `j` and `js` allowed names for tag functions. https://github.com/rescript-lang/rescript-compiler/pull/6817
- `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
- Remove handling of attributes with `bs.` prefix (`@bs.as` -> `@as` etc.). https://github.com/rescript-lang/rescript-compiler/pull/6643
- Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629
Expand Down
6 changes: 3 additions & 3 deletions jscomp/build_tests/super_errors/expected/jinterp.res.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

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

1 │
2 │ let a = 11
3 │ let b = j`number $(a)`
3 │ let b = j`number $(a)`

The unsafe j`$(a)$(b)` interpolation was removed, use string template `${a}${b}` instead.
The value j can't be found
10 changes: 3 additions & 7 deletions jscomp/frontend/ast_utf8_string_interp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,8 @@ module Delim = struct
type interpolation =
| Js (* string interpolation *)
| Unrecognized (* no interpolation: delimiter not recognized *)
let parse_unprocessed loc = function
let parse_unprocessed = function
| "js" -> Js
| "j" ->
Location.raise_errorf ~loc
"The unsafe j`$(a)$(b)` interpolation was removed, use string template \
`${a}${b}` instead."
| _ -> Unrecognized

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

let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
match Delim.parse_unprocessed e.pexp_loc delim with
match Delim.parse_unprocessed delim with
| Js ->
let js_str = Ast_utf8_string.transform e.pexp_loc s in
{e with pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped))}
| Unrecognized -> e

let transform_pat (p : Parsetree.pattern) s delim : Parsetree.pattern =
match Delim.parse_unprocessed p.ppat_loc delim with
match Delim.parse_unprocessed delim with
| Js ->
let js_str = Ast_utf8_string.transform p.ppat_loc s in
{p with ppat_desc = Ppat_constant (Pconst_string (js_str, Delim.escaped))}
Expand Down
12 changes: 5 additions & 7 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ and parse_primary_expr ~operand ?(no_call = false) p =
~end_pos:expr.pexp_loc.loc_end p
(Diagnostics.message
"Tagged template literals are currently restricted to names like: \
json`null`.");
myTagFunction`foo ${bar}`.");
parse_template_expr p)
| _ -> expr
in
Expand Down Expand Up @@ -2279,11 +2279,10 @@ and parse_binary_expr ?(context = OrdinaryExpr) ?a p prec =

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

Expand Down Expand Up @@ -2367,8 +2366,7 @@ and parse_template_expr ?prefix p =
in

match prefix with
| Some {txt = Longident.Lident ("js" | "j" | "json"); _} | None ->
gen_interpolated_string ()
| Some {txt = Longident.Lident "json"; _} | None -> gen_interpolated_string ()
| Some lident_loc -> gen_tagged_template_call lident_loc

(* Overparse: let f = a : int => a + 1, is it (a : int) => or (a): int =>
Expand Down
4 changes: 2 additions & 2 deletions jscomp/syntax/tests/conversion/reason/expected/string.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ let y = "\n"
(<> {"\n"->React.string} </>)

// The `//` should not result into an extra comment
let x = j`https://www.apple.com`
let x = `https://www.apple.com`
let x = `https://www.apple.com`
let x = `https://www.apple.com`
let x = `https://www.apple.com`
let x = sql`https://www.apple.com`

// /* */ should not result in an extra comments
let x = j`/* https://www.apple.com */`
let x = `/* https://www.apple.com */`
let x = `/* https://www.apple.com*/`
let x = `/*https://www.apple.com*/`
let x = `/*https://www.apple.com*/`
Expand Down
4 changes: 2 additions & 2 deletions jscomp/syntax/tests/conversion/reason/string.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ let y = "\n"
(<> {"\n"->React.string} </>)

// The `//` should not result into an extra comment
let x = j`https://www.apple.com`
let x = `https://www.apple.com`
let x = `https://www.apple.com`
let x = `https://www.apple.com`
let x = `https://www.apple.com`
let x = sql`https://www.apple.com`

// /* */ should not result in an extra comments
let x = j`/* https://www.apple.com */`
let x = `/* https://www.apple.com */`
let x = `/* https://www.apple.com*/`
let x = `/*https://www.apple.com*/`
let x = `/*https://www.apple.com*/`
Expand Down
2 changes: 1 addition & 1 deletion jscomp/syntax/tests/idempotency/bs-css/Css_AtomicTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ module Content = {
| #noOpenQuote => "no-open-quote"
| #noCloseQuote => "no-close-quote"
| #attr(name) => "attr(" ++ (name ++ ")")
| #text(string) => j`"$string"`
| #text(string) => `"$string"`
}
}

Expand Down
6 changes: 3 additions & 3 deletions jscomp/syntax/tests/idempotency/bs-css/Css_Js_Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -1690,8 +1690,8 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
src
->Belt.Array.map(x =>
switch x {
| #localUrl(value) => j`local("$(value)")`
| #url(value) => j`url("$(value)")`
| #localUrl(value) => `local("$(value)")`
| #url(value) => `url("$(value)")`
}
)
->join(", ")
Expand All @@ -1710,7 +1710,7 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
"font-display: " ++ (FontDisplay.toString(f) ++ ";")
)

j`@font-face {
`@font-face {
font-family: $fontFamily;
src: $src;
$(fontStyle)
Expand Down
6 changes: 3 additions & 3 deletions jscomp/syntax/tests/idempotency/bs-css/Css_Legacy_Core.res
Original file line number Diff line number Diff line change
Expand Up @@ -1701,8 +1701,8 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
src
|> List.map(x =>
switch x {
| #localUrl(value) => j`local("$(value)")`
| #url(value) => j`url("$(value)")`
| #localUrl(value) => `local("$(value)")`
| #url(value) => `url("$(value)")`
}
)
|> String.concat(", ")
Expand All @@ -1721,7 +1721,7 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
"font-display: " ++ (FontDisplay.toString(f) ++ ";")
)

j`@font-face {
`@font-face {
font-family: $fontFamily;
src: $src;
$(fontStyle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let hook = (makeInitial, ~queryFragment, ~coder) => {

{
open Window
window.history.replaceState(. state, "", j`$protocol//$host$pathname$search`)
window.history.replaceState(. state, "", `$protocol//$host$pathname$search`)
}

None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ module Followee = {
})}
/>
</Link>
: <div> {React.string(followee.username ++ (" has no items! " ++ j`😞`))} </div>}
: <div> {React.string(followee.username ++ (" has no items! " ++ `😞`))} </div>}
</div>
: React.null}
</div>
Expand Down
12 changes: 6 additions & 6 deletions jscomp/syntax/tests/idempotency/nook-exchange/ImportPage.res
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ type itemDestination = [

let itemDestinationToEmoji = destination =>
switch destination {
| #ForTrade => j`🤝`
| #CanCraft => j`🔨`
| #CatalogOnly => j`📖`
| #Wishlist => j`🙏`
| #Ignore => j`🤝`
| #ForTrade => `🤝`
| #CanCraft => `🔨`
| #CatalogOnly => `📖`
| #Wishlist => `🙏`
| #Ignore => `🤝`
}

module VariantRow = {
Expand Down Expand Up @@ -729,7 +729,7 @@ let make = (~showLogin, ~url: ReasonReactRouter.url) => {
setIsFetchingFromCatalogScanner(_ => true)
%Repromise.Js({
let response = Fetch.fetchWithInit(
j`https://ehsan.lol/$catalogScannerId/raw`,
`https://ehsan.lol/$catalogScannerId/raw`,
Fetch.RequestInit.make(~method_=Get, ~mode=CORS, ()),
)
setIsFetchingFromCatalogScanner(_ => false)
Expand Down
6 changes: 3 additions & 3 deletions jscomp/syntax/tests/idempotency/nook-exchange/ItemCard.res
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ let make = (~item: Item.t, ~isLoggedIn, ~showLogin) => {
</span>
{React.string(
switch userItem.status {
| Wishlist => j`In your Wishlist`
| ForTrade => j`In your For Trade list`
| CanCraft => j`In your Can Craft list`
| Wishlist => `In your Wishlist`
| ForTrade => `In your For Trade list`
| CanCraft => `In your Can Craft list`
| _ => raise(Constants.Uhoh)
},
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ module MyStatusSection = {
</span>
{React.string(
switch userItem.status {
| Wishlist => j`In your Wishlist`
| ForTrade => j`In your For Trade list`
| CanCraft => j`In your Can Craft list`
| Wishlist => `In your Wishlist`
| ForTrade => `In your For Trade list`
| CanCraft => `In your Can Craft list`
| _ => raise(Constants.Uhoh)
},
)}
Expand Down
28 changes: 14 additions & 14 deletions jscomp/syntax/tests/idempotency/nook-exchange/SettingsStore.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ let languages: array<language> = [

let languageToString = (language: language) =>
switch language {
| #German => j`Deutsch`
| #SpanishEurope => j`Español (Europe)`
| #SpanishAmerica => j`Español (America)`
| #FrenchEurope => j`Français (Europe)`
| #FrenchAmerica => j`Français (America)`
| #Italian => j`Italiano`
| #Japanese => j`日本語`
| #Korean => j`한국어`
| #Dutch => j`Nederlands`
| #Russian => j`Русский`
| #ChineseSimplified => j`中文`
| #ChineseTraditional => j`繁體中文`
| #English => j`English`
| #EnglishEurope => j`English (UK)`
| #German => `Deutsch`
| #SpanishEurope => `Español (Europe)`
| #SpanishAmerica => `Español (America)`
| #FrenchEurope => `Français (Europe)`
| #FrenchAmerica => `Français (America)`
| #Italian => `Italiano`
| #Japanese => `日本語`
| #Korean => `한국어`
| #Dutch => `Nederlands`
| #Russian => `Русский`
| #ChineseSimplified => `中文`
| #ChineseTraditional => `繁體中文`
| #English => `English`
| #EnglishEurope => `English (UK)`
}

@val @scope("navigator")
Expand Down
8 changes: 4 additions & 4 deletions jscomp/syntax/tests/idempotency/nook-exchange/User.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ type itemStatus =

let itemStatusToEmoji = itemStatus =>
switch itemStatus {
| Wishlist => j`🙏`
| ForTrade => j`🤝`
| CanCraft => j`🔨`
| CatalogOnly => j`📖`
| Wishlist => `🙏`
| ForTrade => `🤝`
| CanCraft => `🔨`
| CatalogOnly => `📖`
}
let itemStatusToString = itemStatus =>
switch itemStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let make = (
onBlur
className=Styles.catalogStatusButton
ref={ReactDOMRe.Ref.domRef(ref)}>
{React.string(userItemStatus == Some(ForTrade) ? j`🤝` : j`🔨`)}
{React.string(userItemStatus == Some(ForTrade) ? `🤝` : `🔨`)}
</div>}
</ReactAtmosphere.Tooltip>
| _ => React.null
Expand Down
8 changes: 4 additions & 4 deletions jscomp/syntax/tests/idempotency/nook-exchange/ViewingList.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ let urlToViewingList = url =>
}
let viewingListToEmoji = viewingList =>
switch viewingList {
| Wishlist => j`🙏`
| ForTrade => j`🤝`
| CanCraft => j`🔨`
| Catalog => j`📖`
| Wishlist => `🙏`
| ForTrade => `🤝`
| CanCraft => `🔨`
| Catalog => `📖`
}
let viewingListToString = viewingList =>
switch viewingList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ open Belt

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

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

let storyUrl = id => j`$apiBaseUrl/stories/$id.json`
let storyUrl = id => `$apiBaseUrl/stories/$id.json`

type story = {
by: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module CollapsibleLink = {

let useOutsideClick: (ReactDOMRe.Ref.t, unit => unit) => unit = %raw(
(outerRef, trigger) =>
j`{
`{
function handleClickOutside(event) {
if (outerRef.current && !outerRef.current.contains(event.target)) {
trigger();
Expand All @@ -107,7 +107,7 @@ let useOutsideClick: (ReactDOMRe.Ref.t, unit => unit) => unit = %raw(

let useWindowWidth: unit => option<int> = %raw(
() =>
j`{
`{
const isClient = typeof window === 'object';

function getSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module Sidebar = {
{Belt.Array.map(items, m => {
let hidden = isHidden ? "hidden" : "block"
let active = isItemActive(m)
? j` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
? ` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
: ""

let activeToc = switch getActiveToc {
Expand Down Expand Up @@ -144,7 +144,7 @@ module Sidebar = {
<ul className="mt-3 text-night">
{Belt.Array.map(items, m => {
let active = isItemActive(m)
? j` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
? ` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
: ""
<li key=m.name className="leading-5 w-4/5">
<Link href=m.href>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ module Sidebar = {
{Belt.Array.map(items, m => {
let hidden = isHidden ? "hidden" : "block"
let active = isItemActive(m)
? j` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
? ` bg-primary-15 text-primary-dark rounded -mx-2 px-2 font-bold block `
: ""
<li
key=m.name
Expand Down Expand Up @@ -213,7 +213,7 @@ module Sidebar = {
<ul className="mt-3 text-night">
{Belt.Array.mapWithIndex(items, (idx, m) => {
let active = isItemActive(m)
? j` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
? ` bg-primary-15 text-primary-dark -ml-1 px-2 font-bold block `
: ""
<li
key=m.href
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ module TwitterVerification = {
</React.Fragment>
| PreparePostToTwitter => <p> {"Please login to 3box!"->React.string} </p>
| PostToTwitter(did) =>
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✅`
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✅`

<React.Fragment>
<p> {"Post the following proof to twitter"->React.string} </p>
Expand Down
Loading