Skip to content

Commit 1372166

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

File tree

27 files changed

+224
-87
lines changed

27 files changed

+224
-87
lines changed
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

+3-5
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
@@ -2282,8 +2282,7 @@ and parse_template_expr ?prefix p =
22822282
(* we could stop treating js and j prefix as something special
22832283
for json, 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/temp/files.txt

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
tests/parsing/grammar/interface/interface.resi
2+
tests/parsing/grammar/signature/recModule.res
3+
tests/parsing/grammar/signature/modDecl.res
4+
tests/parsing/grammar/signature/include.res
5+
tests/parsing/grammar/signature/typLvlModAlias.res
6+
tests/parsing/grammar/signature/external.res
7+
tests/parsing/grammar/signature/typext.res
8+
tests/parsing/grammar/signature/standAloneAttribute.res
9+
tests/parsing/grammar/signature/exception.res
10+
tests/parsing/grammar/signature/open.res
11+
tests/parsing/grammar/signature/typeDefinition.res
12+
tests/parsing/grammar/signature/modtype.res
13+
tests/parsing/grammar/signature/let.res
14+
tests/parsing/grammar/signature/itemExtension.res
15+
tests/parsing/grammar/typexpr/tuple.res
16+
tests/parsing/grammar/typexpr/unit.res
17+
tests/parsing/grammar/typexpr/typeconstr.res
18+
tests/parsing/grammar/typexpr/var.res
19+
tests/parsing/grammar/typexpr/polyVariant.res
20+
tests/parsing/grammar/typexpr/parenthesized.res
21+
tests/parsing/grammar/typexpr/es6Arrow.res
22+
tests/parsing/grammar/typexpr/objectTypeSpreading.res
23+
tests/parsing/grammar/typexpr/uncurried.res
24+
tests/parsing/grammar/typexpr/alias.res
25+
tests/parsing/grammar/typexpr/extension.res
26+
tests/parsing/grammar/typexpr/firstClassModules.res
27+
tests/parsing/grammar/typexpr/poly.res
28+
tests/parsing/grammar/typexpr/any.res
29+
tests/parsing/grammar/typexpr/bsObject.res
30+
tests/parsing/grammar/modtype/with.res
31+
tests/parsing/grammar/modtype/parenthesized.res
32+
tests/parsing/grammar/modtype/functor.res
33+
tests/parsing/grammar/modtype/signature.res
34+
tests/parsing/grammar/modtype/typeof.res
35+
tests/parsing/grammar/modtype/extension.res
36+
tests/parsing/grammar/modtype/ident.res
37+
tests/parsing/grammar/ffi/export.res
38+
tests/parsing/grammar/expressions/arrow.res
39+
tests/parsing/grammar/expressions/UncurriedAlways.res
40+
tests/parsing/grammar/expressions/list.res
41+
tests/parsing/grammar/expressions/tuple.res
42+
tests/parsing/grammar/expressions/sideEffects.res
43+
tests/parsing/grammar/expressions/float.res
44+
tests/parsing/grammar/expressions/async.res
45+
tests/parsing/grammar/expressions/apply.res
46+
tests/parsing/grammar/expressions/coerce.res
47+
tests/parsing/grammar/expressions/array.res
48+
tests/parsing/grammar/expressions/UncurriedByDefault.res
49+
tests/parsing/grammar/expressions/polyvariant.res
50+
tests/parsing/grammar/expressions/infix.res
51+
tests/parsing/grammar/expressions/parenthesized.res
52+
tests/parsing/grammar/expressions/es6template.res
53+
tests/parsing/grammar/expressions/record.res
54+
tests/parsing/grammar/expressions/for.res
55+
tests/parsing/grammar/expressions/argument.res
56+
tests/parsing/grammar/expressions/await.res
57+
tests/parsing/grammar/expressions/bracedOrRecord.res
58+
tests/parsing/grammar/expressions/underscoreApply.res
59+
tests/parsing/grammar/expressions/uncurried.res
60+
tests/parsing/grammar/expressions/locallyAbstractTypes.res
61+
tests/parsing/grammar/expressions/while.res
62+
tests/parsing/grammar/expressions/try.res
63+
tests/parsing/grammar/expressions/bigint.res
64+
tests/parsing/grammar/expressions/tupleVsDivision.res
65+
tests/parsing/grammar/expressions/extension.res
66+
tests/parsing/grammar/expressions/switch.res
67+
tests/parsing/grammar/expressions/binaryNoEs6Arrow.res
68+
tests/parsing/grammar/expressions/ident.res
69+
tests/parsing/grammar/expressions/binary.res
70+
tests/parsing/grammar/expressions/primary.res
71+
tests/parsing/grammar/expressions/firstClassModule.res
72+
tests/parsing/grammar/expressions/constructor.res
73+
tests/parsing/grammar/expressions/block.res
74+
tests/parsing/grammar/expressions/unaryOrBinary.res
75+
tests/parsing/grammar/expressions/if.res
76+
tests/parsing/grammar/expressions/constants.res
77+
tests/parsing/grammar/expressions/unary.res
78+
tests/parsing/grammar/expressions/jsx.res
79+
tests/parsing/grammar/expressions/bsObject.res
80+
tests/parsing/grammar/modexpr/apply.res
81+
tests/parsing/grammar/modexpr/parenthesized.res
82+
tests/parsing/grammar/modexpr/functor.res
83+
tests/parsing/grammar/modexpr/constrained.res
84+
tests/parsing/grammar/modexpr/firstClassModules.res
85+
tests/parsing/grammar/modexpr/ident.res
86+
tests/parsing/grammar/modexpr/structure.res
87+
tests/parsing/grammar/pattern/list.res
88+
tests/parsing/grammar/pattern/tuple.res
89+
tests/parsing/grammar/pattern/unit.res
90+
tests/parsing/grammar/pattern/var.res
91+
tests/parsing/grammar/pattern/array.res
92+
tests/parsing/grammar/pattern/record.res
93+
tests/parsing/grammar/pattern/constant.res
94+
tests/parsing/grammar/pattern/polyvariants.res
95+
tests/parsing/grammar/pattern/exception.res
96+
tests/parsing/grammar/pattern/variants.res
97+
tests/parsing/grammar/pattern/or.res
98+
tests/parsing/grammar/pattern/extension.res
99+
tests/parsing/grammar/pattern/firstClassModules.res
100+
tests/parsing/grammar/pattern/constructor.res
101+
tests/parsing/grammar/pattern/constraint.res
102+
tests/parsing/grammar/pattern/any.res
103+
tests/parsing/grammar/structure/modExprExtension.res
104+
tests/parsing/grammar/structure/exceptionDefinition.res
105+
tests/parsing/grammar/structure/recursiveModules.res
106+
tests/parsing/grammar/structure/letBinding.res
107+
tests/parsing/grammar/structure/includeStatement.res
108+
tests/parsing/grammar/structure/standaloneAttribute.res
109+
tests/parsing/grammar/structure/externalDefinition.res
110+
tests/parsing/grammar/structure/typeDefinition.res
111+
tests/parsing/grammar/structure/openDescription.res
112+
tests/parsing/grammar/structure/modType.res
113+
tests/parsing/grammar/structure/moduleTypeExtension.res
114+
tests/parsing/grammar/structure/itemExtension.res
115+
tests/parsing/grammar/structure/module.res
116+
tests/parsing/grammar/typedefinition/typeparams.res
117+
tests/parsing/grammar/typedefinition/polyvariant.res
118+
tests/parsing/grammar/typedefinition/typeConstraint.res
119+
tests/parsing/grammar/typedefinition/typext.res
120+
tests/parsing/grammar/typedefinition/typedef.res
121+
tests/parsing/grammar/typedefinition/typeDefinition.res
122+
tests/parsing/grammar/typedefinition/typeNonrec.res
123+
tests/parsing/grammar/typedefinition/typeInformation.res
124+
tests/parsing/grammar/typedefinition/typeRepresentation.res
125+
tests/parsing/grammar/typedefinition/constructorDeclaration.res
126+
tests/parsing/grammar/typedefinition/diamond.res
127+
tests/parsing/grammar/typedefinition/recordDeclaration.res
128+
tests/parsing/grammar/typedefinition/privateTypeEquation.res
129+
tests/parsing/grammar/typedefinition/bsObject.res
130+
tests/parsing/other/list.res
131+
tests/parsing/other/comments.res
132+
tests/parsing/other/onlySinglinelineComment.resi
133+
tests/parsing/other/onlyMultilineComment.res
134+
tests/parsing/other/emptyInterface.resi
135+
tests/parsing/other/stringLiterals.res
136+
tests/parsing/other/attributes.res
137+
tests/parsing/other/singleLineCommentWithoutNewline.res
138+
tests/parsing/other/docComments.res
139+
tests/parsing/other/semi.res
140+
tests/parsing/other/gentype.res
141+
tests/parsing/other/onlySinglelineComment.res
142+
tests/parsing/other/onlyMultilineComment.resi
143+
tests/parsing/other/emptyFile.res

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
)}

0 commit comments

Comments
 (0)