Skip to content

Commit 811eb6b

Browse files
authored
Merge pull request #736 from aspeddro/remove-unsafe-string-inter
Remove unsafe string interpolation `j`
2 parents bc82771 + bc207e0 commit 811eb6b

File tree

13 files changed

+51
-48
lines changed

13 files changed

+51
-48
lines changed

src/Blog.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module BlogCard = {
123123
| Some(category) =>
124124
<>
125125
{React.string(category)}
126-
{React.string(j` · `)}
126+
{React.string(` · `)}
127127
</>
128128
| None => React.null
129129
}}

src/DocsOverview.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ let default = (~showVersionSelect=true) => {
2727
}
2828

2929
let languageManual = [
30-
("Overview", j` /docs/manual/$version/introduction`),
31-
("Language Features", j`/docs/manual/$version/overview`),
32-
("JS Interop", j`/docs/manual/$version/embed-raw-javascript`),
33-
("Build System", j`/docs/manual/$version/build-overview`),
30+
("Overview", `/docs/manual/${version}/introduction`),
31+
("Language Features", `/docs/manual/${version}/overview`),
32+
("JS Interop", `/docs/manual/${version}/embed-raw-javascript`),
33+
("Build System", `/docs/manual/${version}/build-overview`),
3434
]
3535

3636
let ecosystem = [

src/Playground.res

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module ResultPane = {
125125
<div className={"p-2 " ++ highlightClass}>
126126
<span className=prefixColor> {React.string(prefixText)} </span>
127127
<span className="font-medium text-gray-40">
128-
{React.string(j` Line $row, column $column:`)}
128+
{React.string(` Line ${row->Belt.Int.toString}, column ${column->Belt.Int.toString}:`)}
129129
</span>
130130
<AnsiPre className="whitespace-pre-wrap "> shortMsg </AnsiPre>
131131
</div>
@@ -247,7 +247,7 @@ module ResultPane = {
247247
"Formatting completed with 0 errors"
248248
} else {
249249
let toStr = Api.Lang.toString(toLang)
250-
j`Switched to $toStr with 0 errors`
250+
`Switched to ${toStr} with 0 errors`
251251
}
252252
<PreWrap> {React.string(msg)} </PreWrap>
253253
| Conv(Fail({fromLang, toLang, details})) =>
@@ -268,11 +268,11 @@ module ResultPane = {
268268
// We keep both cases though in case we change things later
269269
let msg = if fromLang === toLang {
270270
let langStr = Api.Lang.toString(toLang)
271-
j`The code is not valid $langStr syntax.`
271+
`The code is not valid ${langStr} syntax.`
272272
} else {
273273
let fromStr = Api.Lang.toString(fromLang)
274274
let toStr = Api.Lang.toString(toLang)
275-
j`Could not convert from "$fromStr" to "$toStr" due to malformed syntax:`
275+
`Could not convert from "${fromStr}" to "${toStr}" due to malformed syntax:`
276276
}
277277
<div>
278278
<PreWrap className="text-16 mb-4"> {React.string(msg)} </PreWrap>
@@ -310,7 +310,9 @@ module ResultPane = {
310310
| Nothing =>
311311
let syntax = Api.Lang.toString(targetLang)
312312
<PreWrap>
313-
{React.string(j`This playground is now running on compiler version $compilerVersion with $syntax syntax`)}
313+
{React.string(
314+
`This playground is now running on compiler version ${compilerVersion} with ${syntax} syntax`,
315+
)}
314316
</PreWrap>
315317
}
316318

@@ -1053,7 +1055,7 @@ module ControlPanel = {
10531055
}
10541056

10551057
module ShareButton = {
1056-
let copyToClipboard: string => bool = %raw(j`
1058+
let copyToClipboard: string => bool = %raw(`
10571059
function(str) {
10581060
try {
10591061
const el = document.createElement('textarea');
@@ -1406,7 +1408,7 @@ module App = {
14061408
// Feel free to play around and compile some
14071409
// ReScript code!
14081410

1409-
let initialReContent = j`Js.log("Hello Reason 3.6!");`
1411+
let initialReContent = `Js.log("Hello Reason 3.6!");`
14101412

14111413
let default = (~props: Try.props) => {
14121414
let router = Next.Router.useRouter()

src/Try.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let default = (props: {"children": React.element}) => {
66
<>
77
<Meta title="ReScript Playground" description="Try ReScript in the browser" />
88
<Next.Head>
9-
<style> {React.string(j`body { background-color: #010427; } `)} </style>
9+
<style> {React.string(`body { background-color: #010427; }`)} </style>
1010
</Next.Head>
1111
<div className="text-16">
1212
<div className="text-gray-40 text-14">

src/bindings/RescriptCompilerApi.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Lang = {
2626
| "ml" => OCaml
2727
| "re" => Reason
2828
| "res" => Res
29-
| other => raise(DecodeError(j`Unknown language "$other"`))
29+
| other => raise(DecodeError(`Unknown language "${other}"`))
3030
}
3131
}
3232
}
@@ -110,7 +110,7 @@ module LocMsg = {
110110
| #E => "E"
111111
}
112112

113-
j`[1;31m[$prefix] Line $row, $column:[0m $shortMsg`
113+
`[1;31m[${prefix}] Line ${row->Belt.Int.toString}, ${column->Belt.Int.toString}:[0m ${shortMsg}`
114114
}
115115

116116
// Creates a somewhat unique id based on the rows / cols of the locMsg
@@ -160,11 +160,11 @@ module Warning = {
160160
| Warn({warnNumber, details})
161161
| WarnErr({warnNumber, details}) =>
162162
let {LocMsg.row: row, column, shortMsg} = details
163-
let msg = j`(Warning number $warnNumber) $shortMsg`
163+
let msg = `(Warning number ${warnNumber->Belt.Int.toString}) ${shortMsg}`
164164
(row, column, msg)
165165
}
166166

167-
j`[1;31m[$prefix] Line $row, $column:[0m $msg`
167+
`[1;31m[${prefix}] Line ${row->Belt.Int.toString}, ${column->Belt.Int.toString}:[0m ${msg}`
168168
}
169169
}
170170

@@ -295,7 +295,7 @@ module CompileFail = {
295295
| "warning_flag_error" =>
296296
let warningFlag = WarningFlag.decode(json)
297297
WarningFlagErr(warningFlag)
298-
| other => raise(DecodeError(j`Unknown type "$other" in CompileFail result`))
298+
| other => raise(DecodeError(`Unknown type "${other}" in CompileFail result`))
299299
}
300300
}
301301
}
@@ -336,7 +336,7 @@ module ConversionResult = {
336336
| "syntax_error" =>
337337
let locMsgs = field("errors", array(LocMsg.decode), json)
338338
Fail({fromLang, toLang, details: locMsgs})
339-
| other => Unknown(j`Unknown conversion result type "$other"`, json)
339+
| other => Unknown(`Unknown conversion result type "${other}"`, json)
340340
} catch {
341341
| DecodeError(errMsg) => Unknown(errMsg, json)
342342
}

src/common/Ansi.res

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module Sgr = {
5252
}
5353
}
5454

55-
let esc = j`\u001B`
55+
let esc = `\u001B`
5656

5757
let isAscii = (c: string) => Js.Re.test_(%re(`/[\x40-\x7F]/`), c)
5858

@@ -324,7 +324,7 @@ module SgrString = {
324324
}
325325
let params = Belt.Array.map(e.params, Sgr.paramToString)->Js.Array2.joinWith(", ")
326326

327-
j`SgrString params: $params | content: $content`
327+
`SgrString params: ${params} | content: ${content}`
328328
}
329329
}
330330

@@ -338,14 +338,14 @@ module Printer = {
338338
open Js.String2
339339
replaceByRe(content, %re("/\n/g"), "\\n")->replace(esc, "")
340340
}
341-
j`Text "$content" ($startPos to $endPos)`
341+
`Text "${content}" (${startPos->Belt.Int.toString} to ${endPos->Belt.Int.toString})`
342342
| Sgr({params, raw, loc: {startPos, endPos}}) =>
343343
let raw = Js.String2.replace(raw, esc, "")
344344
let params = Belt.Array.map(params, Sgr.paramToString)->Js.Array2.joinWith(", ")
345-
j`Sgr "$raw" -> $params ($startPos to $endPos)`
345+
`Sgr "${raw}" -> ${params} (${startPos->Belt.Int.toString} to ${endPos->Belt.Int.toString})`
346346
| ClearSgr({loc: {startPos, endPos}, raw}) =>
347347
let raw = Js.String2.replace(raw, esc, "")
348-
j`Clear Sgr "$raw" ($startPos to $endPos)`
348+
`Clear Sgr "${raw}" (${startPos->Belt.Int.toString} to ${endPos->Belt.Int.toString})`
349349
}
350350

351351
let plainString = (tokens: array<token>): string =>

src/common/BlogApi.res

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module RssFeed = {
134134
Belt.Array.get(items, 0)
135135
->Belt.Option.map(item => {
136136
let latestPubDateStr = item.pubDate->dateToUTCString
137-
j`<lastBuildDate>$latestPubDateStr</lastBuildDate>`
137+
`<lastBuildDate>${latestPubDateStr}</lastBuildDate>`
138138
})
139139
->Belt.Option.getWithDefault("")
140140

@@ -143,33 +143,34 @@ module RssFeed = {
143143
->Js.Array2.map(({title, pubDate, description, href}) => {
144144
let descriptionElement = switch description {
145145
| "" => ""
146-
| desc => j`<description>
147-
<![CDATA[$desc]]>
146+
| desc =>
147+
`<description>
148+
<![CDATA[${desc}]]>
148149
</description>`
149150
}
150151

151152
// TODO: convert pubdate to string
152153
let dateStr = pubDate->dateToUTCString
153-
j`
154+
`
154155
<item>
155-
<title> <![CDATA[$title]]></title>
156-
<link> $href </link>
157-
<guid> $href </guid>
158-
$descriptionElement
159-
<pubDate>$dateStr</pubDate>
156+
<title> <![CDATA[${title}]]></title>
157+
<link> ${href} </link>
158+
<guid> ${href} </guid>
159+
${descriptionElement}
160+
<pubDate>${dateStr}</pubDate>
160161
</item>`
161162
})
162163
->Js.Array2.joinWith("\n")
163164

164-
let ret = j`<?xml version="1.0" encoding="utf-8" ?>
165+
let ret = `<?xml version="1.0" encoding="utf-8" ?>
165166
<rss version="2.0">
166167
<channel>
167-
<title>$siteTitle</title>
168+
<title>${siteTitle}</title>
168169
<link>https://rescript-lang.org</link>
169-
<description>$siteDescription</description>
170+
<description>${siteDescription}</description>
170171
<language>en</language>
171-
$latestPubDateElement
172-
$itemsStr
172+
${latestPubDateElement}
173+
${itemsStr}
173174
</channel>
174175
</rss>` //rescript-lang.org</link>
175176

src/common/BlogFrontmatter.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ let decodeBadge = (str: string): Badge.t =>
9898
| "testing" => Testing
9999
| "preview" => Preview
100100
| "roadmap" => Roadmap
101-
| str => raise(Json.Decode.DecodeError(j`Unknown category "$str"`))
101+
| str => raise(Json.Decode.DecodeError(`Unknown category "${str}"`))
102102
}
103103

104104
exception AuthorNotFound(string)
105105

106106
let decodeAuthor = (~fieldName: string, ~authors, username) =>
107107
switch Js.Array2.find(authors, a => a.username === username) {
108108
| Some(author) => author
109-
| None => raise(AuthorNotFound(j`Couldn't find author "$username" in field $fieldName`))
109+
| None => raise(AuthorNotFound(`Couldn't find author "${username}" in field ${fieldName}`))
110110
}
111111

112112
let authorDecoder = (~fieldName: string, ~authors, json) => {

src/common/CompilerManagerHook.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module LoadScript = {
2828
loadScript(
2929
~src=url,
3030
~onSuccess=() => resolve(. Ok()),
31-
~onError=_err => resolve(. Error(j`Could not load script: $url`)),
31+
~onError=_err => resolve(. Error(`Could not load script: ${url}`)),
3232
)->ignore
3333
})
3434
}

src/common/Hooks.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Contains some generic hooks */
22
%%raw("import React from 'react'")
33

4-
let useOutsideClick: (ReactDOM.Ref.t, unit => unit) => unit = %raw(j`(outerRef, trigger) => {
4+
let useOutsideClick: (ReactDOM.Ref.t, unit => unit) => unit = %raw(`(outerRef, trigger) => {
55
function handleClickOutside(event) {
66
if (outerRef.current && !outerRef.current.contains(event.target)) {
77
trigger();
@@ -16,7 +16,7 @@ let useOutsideClick: (ReactDOM.Ref.t, unit => unit) => unit = %raw(j`(outerRef,
1616
});
1717
}`)
1818

19-
let useWindowWidth: unit => option<int> = %raw(j` () => {
19+
let useWindowWidth: unit => option<int> = %raw(` () => {
2020
const isClient = typeof window === 'object';
2121
2222
function getSize() {

src/components/CodeExample.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module DomUtil = {
2929
}
3030

3131
module CopyButton = {
32-
let copyToClipboard: string => bool = %raw(j`
32+
let copyToClipboard: string => bool = %raw(`
3333
function(str) {
3434
try {
3535
const el = document.createElement('textarea');

src/components/CodeMirror.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
This file is providing the core functionality and logic of our CodeMirror instances.
99
*/
1010

11-
let useWindowWidth: unit => int = %raw(j` () => {
11+
let useWindowWidth: unit => int = %raw(` () => {
1212
const isClient = typeof window === 'object';
1313
1414
function getSize() {
@@ -460,7 +460,7 @@ module GutterMarker = {
460460
}
461461

462462
let (row, col) = rowCol
463-
marker->setId(j`gutter-marker_$row-$col`)
463+
marker->setId(`gutter-marker_${row->Belt.Int.toString}-${col->Belt.Int.toString}`)
464464
marker->setClassName(
465465
"flex items-center justify-center text-14 text-center ml-1 h-6 font-bold hover:cursor-pointer " ++
466466
colorClass,
@@ -702,7 +702,7 @@ let make = // props relevant for the react wrapper
702702
*/
703703
let errorsFingerprint = Belt.Array.map(errors, e => {
704704
let {Error.row: row, column} = e
705-
j`$row-$column`
705+
`${row->Belt.Int.toString}-${column->Belt.Int.toString}`
706706
})->Js.Array2.joinWith(";")
707707

708708
React.useEffect1(() => {

src/layouts/LandingPageLayout.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ exports.Button = Button;`,
131131

132132
module QuickInstall = {
133133
module CopyButton = {
134-
let copyToClipboard: string => bool = %raw(j`
134+
let copyToClipboard: string => bool = %raw(`
135135
function(str) {
136136
try {
137137
const el = document.createElement('textarea');

0 commit comments

Comments
 (0)