diff --git a/CHANGELOG.md b/CHANGELOG.md index 33651b6311..464773082b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/build_tests/super_errors/expected/jinterp.res.expected b/jscomp/build_tests/super_errors/expected/jinterp.res.expected index 7eb7ad35cb..82d06d2f91 100644 --- a/jscomp/build_tests/super_errors/expected/jinterp.res.expected +++ b/jscomp/build_tests/super_errors/expected/jinterp.res.expected @@ -1,9 +1,9 @@ [1;31mWe've found a bug for you![0m - [36m/.../fixtures/jinterp.res[0m:[2m3:10-21[0m + [36m/.../fixtures/jinterp.res[0m:[2m3:9[0m 1 [2m│[0m 2 [2m│[0m let a = 11 - [1;31m3[0m [2m│[0m let b = j[1;31m`number $(a)[0m` + [1;31m3[0m [2m│[0m let b = [1;31mj[0m`number $(a)` - The unsafe j`$(a)$(b)` interpolation was removed, use string template `${a}${b}` instead. \ No newline at end of file + The value j can't be found \ No newline at end of file diff --git a/jscomp/frontend/ast_utf8_string_interp.ml b/jscomp/frontend/ast_utf8_string_interp.ml index a66d7ee1f7..ee4ae0f7e1 100644 --- a/jscomp/frontend/ast_utf8_string_interp.ml +++ b/jscomp/frontend/ast_utf8_string_interp.ml @@ -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 *) @@ -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))} diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index c77084669b..f2f2f9393e 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -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 @@ -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 @@ -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 => diff --git a/jscomp/syntax/tests/conversion/reason/expected/string.res.txt b/jscomp/syntax/tests/conversion/reason/expected/string.res.txt index a85d0bbc5b..dde635285c 100644 --- a/jscomp/syntax/tests/conversion/reason/expected/string.res.txt +++ b/jscomp/syntax/tests/conversion/reason/expected/string.res.txt @@ -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*/` diff --git a/jscomp/syntax/tests/conversion/reason/string.res b/jscomp/syntax/tests/conversion/reason/string.res index a85d0bbc5b..dde635285c 100644 --- a/jscomp/syntax/tests/conversion/reason/string.res +++ b/jscomp/syntax/tests/conversion/reason/string.res @@ -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*/` diff --git a/jscomp/syntax/tests/idempotency/bs-css/Css_AtomicTypes.res b/jscomp/syntax/tests/idempotency/bs-css/Css_AtomicTypes.res index 18d29352bf..bbf835c94a 100644 --- a/jscomp/syntax/tests/idempotency/bs-css/Css_AtomicTypes.res +++ b/jscomp/syntax/tests/idempotency/bs-css/Css_AtomicTypes.res @@ -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"` } } diff --git a/jscomp/syntax/tests/idempotency/bs-css/Css_Js_Core.res b/jscomp/syntax/tests/idempotency/bs-css/Css_Js_Core.res index eacb481386..104a398967 100644 --- a/jscomp/syntax/tests/idempotency/bs-css/Css_Js_Core.res +++ b/jscomp/syntax/tests/idempotency/bs-css/Css_Js_Core.res @@ -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(", ") @@ -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) diff --git a/jscomp/syntax/tests/idempotency/bs-css/Css_Legacy_Core.res b/jscomp/syntax/tests/idempotency/bs-css/Css_Legacy_Core.res index 1470459138..ed928be91e 100644 --- a/jscomp/syntax/tests/idempotency/bs-css/Css_Legacy_Core.res +++ b/jscomp/syntax/tests/idempotency/bs-css/Css_Legacy_Core.res @@ -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(", ") @@ -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) diff --git a/jscomp/syntax/tests/idempotency/covid-19charts.com/src/UseQueryParam.res b/jscomp/syntax/tests/idempotency/covid-19charts.com/src/UseQueryParam.res index dadfa1e61d..a79a98b100 100644 --- a/jscomp/syntax/tests/idempotency/covid-19charts.com/src/UseQueryParam.res +++ b/jscomp/syntax/tests/idempotency/covid-19charts.com/src/UseQueryParam.res @@ -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 diff --git a/jscomp/syntax/tests/idempotency/nook-exchange/FriendsPage.res b/jscomp/syntax/tests/idempotency/nook-exchange/FriendsPage.res index e82639b1a5..b3402424ec 100644 --- a/jscomp/syntax/tests/idempotency/nook-exchange/FriendsPage.res +++ b/jscomp/syntax/tests/idempotency/nook-exchange/FriendsPage.res @@ -243,7 +243,7 @@ module Followee = { })} /> - :
{"Please login to 3box!"->React.string}
| 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✅`{"Post the following proof to twitter"->React.string}
diff --git a/jscomp/syntax/tests/idempotency/wildcards-world-ui/Web3Connect.res b/jscomp/syntax/tests/idempotency/wildcards-world-ui/Web3Connect.res index 2e0364dc3d..e982c1faab 100644 --- a/jscomp/syntax/tests/idempotency/wildcards-world-ui/Web3Connect.res +++ b/jscomp/syntax/tests/idempotency/wildcards-world-ui/Web3Connect.res @@ -13,12 +13,12 @@ let make = (~clickAction=() => ()) => { let connectedNetworkName = networkId => switch networkId { - | 1 => j`MAINNET\\xa0`->React.string - | 3 => j`ROPSTEN\\xa0`->React.string - | 4 => j`RINKEBY\\xa0`->React.string - | 5 => j`GOERLI\\xa0`->React.string - | 42 => j`KOVAN\\xa0`->React.string - | _ => j`Unknown\\xa0`->React.string + | 1 => `MAINNET\\xa0`->React.string + | 3 => `ROPSTEN\\xa0`->React.string + | 4 => `RINKEBY\\xa0`->React.string + | 5 => `GOERLI\\xa0`->React.string + | 42 => `KOVAN\\xa0`->React.string + | _ => `Unknown\\xa0`->React.string } let web3Button = switch networkIdOpt { diff --git a/jscomp/syntax/tests/parsing/errors/expressions/expected/taggedTemplateLiterals.res.txt b/jscomp/syntax/tests/parsing/errors/expressions/expected/taggedTemplateLiterals.res.txt index 3711a2c321..211e8a37b9 100644 --- a/jscomp/syntax/tests/parsing/errors/expressions/expected/taggedTemplateLiterals.res.txt +++ b/jscomp/syntax/tests/parsing/errors/expressions/expected/taggedTemplateLiterals.res.txt @@ -5,6 +5,6 @@ 1 │ foo()`null` 2 │ - Tagged template literals are currently restricted to names like: json`null`. + Tagged template literals are currently restricted to names like: myTagFunction`foo ${bar}`. ;;(({js|null|js})[@res.template ]) \ No newline at end of file diff --git a/jscomp/syntax/tests/printer/other/expected/reasonString.res.txt b/jscomp/syntax/tests/printer/other/expected/reasonString.res.txt index e68fb5323e..94d760ca90 100644 --- a/jscomp/syntax/tests/printer/other/expected/reasonString.res.txt +++ b/jscomp/syntax/tests/printer/other/expected/reasonString.res.txt @@ -1,4 +1,4 @@ -let x = j`foo \${bar` -let x = j`foo \`bar` -let x = j`foo \\bar` -let x = j`foo \\\${bar` +let x = `foo \${bar` +let x = `foo \`bar` +let x = `foo \\bar` +let x = `foo \\\${bar` diff --git a/jscomp/syntax/tests/printer/other/reasonString.res b/jscomp/syntax/tests/printer/other/reasonString.res index e68fb5323e..94d760ca90 100644 --- a/jscomp/syntax/tests/printer/other/reasonString.res +++ b/jscomp/syntax/tests/printer/other/reasonString.res @@ -1,4 +1,4 @@ -let x = j`foo \${bar` -let x = j`foo \`bar` -let x = j`foo \\bar` -let x = j`foo \\\${bar` +let x = `foo \${bar` +let x = `foo \`bar` +let x = `foo \\bar` +let x = `foo \\\${bar` diff --git a/jscomp/test/tagged_template_test.js b/jscomp/test/tagged_template_test.js index afd462a124..5b5507f1fb 100644 --- a/jscomp/test/tagged_template_test.js +++ b/jscomp/test/tagged_template_test.js @@ -96,7 +96,19 @@ Mt.from_pair_suites("tagged templates", { }; }) ], - tl: /* [] */0 + tl: { + hd: [ + "a regular string interpolation should continue working", + (function (param) { + return { + TAG: "Eq", + _0: "some random string interpolation", + _1: "some random string interpolation" + }; + }) + ], + tl: /* [] */0 + } } } } diff --git a/jscomp/test/tagged_template_test.res b/jscomp/test/tagged_template_test.res index bb302d73bc..27c25658e7 100644 --- a/jscomp/test/tagged_template_test.res +++ b/jscomp/test/tagged_template_test.res @@ -51,5 +51,9 @@ Mt.from_pair_suites( "a template literal tagged with json should generate a regular string interpolation for now", () => Eq(json`some random ${"string"}`, "some random string"), ), + ( + "a regular string interpolation should continue working", + () => Eq(`some random ${"string"} interpolation`, "some random string interpolation"), + ), }, ) \ No newline at end of file