Skip to content

Commit 861e02b

Browse files
committed
Deprecate unsafe `` j$(a)$(b) `` interpolation
1 parent 6178dce commit 861e02b

File tree

10 files changed

+68
-39
lines changed

10 files changed

+68
-39
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
- Better error message for extension point https://github.com/rescript-lang/rescript-compiler/pull/6057
2727
- Improve format check help https://github.com/rescript-lang/rescript-compiler/pull/6056
28+
- Deprecate unsafe ``` j`$(a)$(b)` ``` interpolation: use string templates ``` `${a}${b}` ``` instead
2829

2930
# 10.1.3
3031

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
Warning number 3
3+
/.../fixtures/jinterp.res:3:10-21
4+
5+
1 │
6+
2 │ let a = 11
7+
3 │ let b = j`number $(a)`
8+
9+
deprecated: The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
let a = 11
3+
let b = j`number $(a)`

jscomp/frontend/ast_utf8_string_interp.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
409409
e with
410410
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
411411
}
412-
| J -> transform_interp e.pexp_loc s
412+
| J ->
413+
Location.prerr_warning e.pexp_loc
414+
(Warnings.Deprecated
415+
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
416+
transform_interp e.pexp_loc s
413417
| Unrecognized -> e
414418

415419

jscomp/stdlib-406/arg.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ let print_spec buf (key, spec, doc) =
8181
match spec with
8282
| Symbol (l, _) ->
8383
let sym = make_symlist "{" "|" "}" l in
84-
Buffer.add_string buf {j| $(key) $(sym)$(doc)\n|j}
84+
Buffer.add_string buf (((((" " ^ key) ^ " ") ^ sym) ^ doc) ^ "\n")
8585
| _ ->
86-
Buffer.add_string buf {j| $(key) $(doc)\n|j}
86+
Buffer.add_string buf ((((" " ^ key) ^ " ") ^ doc) ^ "\n")
8787

8888

8989

jscomp/stdlib-406/printexc.ml

+28-32
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@
1212
(* special exception on linking described in the file LICENSE. *)
1313
(* *)
1414
(**************************************************************************)
15-
[@@@bs.config { flags = [|"-bs-no-cross-module-opt" |]}]
16-
15+
[@@@bs.config { flags = [| "-bs-no-cross-module-opt" |] }]
1716

1817
let printers = ref []
1918

20-
let locfmt s (linum : int) (start : int) (finish : int) msg =
21-
{j|File "$(s)", line $(linum), characters $(start)-$(finish): $(msg)|j}
22-
19+
let locfmt s (linum : int) (start : int) (finish : int) msg =
20+
(((((((("File \"" ^ s) ^ "\", line ") ^ __unsafe_cast linum) ^ ", characters ")
21+
^ __unsafe_cast start)
22+
^ "-")
23+
^ __unsafe_cast finish)
24+
^ ": ")
25+
^ msg
2326

24-
let fields : exn -> string = [%raw{|function(x){
27+
let fields : exn -> string =
28+
[%raw
29+
{|function(x){
2530
var s = ""
2631
var index = 1
2732
while ("_"+index in x){
@@ -33,47 +38,38 @@ let fields : exn -> string = [%raw{|function(x){
3338
}
3439
return "(" + s + ")"
3540
}
36-
|}]
37-
38-
39-
40-
41+
|}]
4142

4243
external exn_slot_name : exn -> string = "?exn_slot_name"
4344

44-
let to_string x =
45+
let to_string x =
4546
let rec conv = function
46-
| hd :: tl ->
47-
(match try hd x with _ -> None with
48-
| Some s -> s
49-
| None -> conv tl)
50-
| [] ->
47+
| hd :: tl -> (
48+
match try hd x with _ -> None with Some s -> s | None -> conv tl)
49+
| [] -> (
5150
match x with
52-
| Match_failure(file, line, char) ->
53-
locfmt file line char (char+5) "Pattern matching failed"
54-
| Assert_failure(file, line, char) ->
55-
locfmt file line char (char+6) "Assertion failed"
56-
| Undefined_recursive_module(file, line, char) ->
57-
locfmt file line char (char+6) "Undefined recursive module"
51+
| Match_failure (file, line, char) ->
52+
locfmt file line char (char + 5) "Pattern matching failed"
53+
| Assert_failure (file, line, char) ->
54+
locfmt file line char (char + 6) "Assertion failed"
55+
| Undefined_recursive_module (file, line, char) ->
56+
locfmt file line char (char + 6) "Undefined recursive module"
5857
| _ ->
59-
let constructor =
60-
exn_slot_name x in
61-
constructor ^ fields x in
58+
let constructor = exn_slot_name x in
59+
constructor ^ fields x)
60+
in
6261
conv !printers
6362

6463
let print fct arg =
65-
try
66-
fct arg
64+
try fct arg
6765
with x ->
6866
Js.log ("Uncaught exception: " ^ to_string x);
6967
raise x
7068

7169
let catch fct arg =
72-
try
73-
fct arg
70+
try fct arg
7471
with x ->
7572
Js.log ("Uncaught exception: " ^ to_string x);
7673
exit 2
7774

78-
let register_printer fn =
79-
printers := fn :: !printers
75+
let register_printer fn = printers := fn :: !printers

lib/4.06.1/unstable/all_ounit_tests.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -52179,7 +52179,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
5217952179
e with
5218052180
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
5218152181
}
52182-
| J -> transform_interp e.pexp_loc s
52182+
| J ->
52183+
Location.prerr_warning e.pexp_loc
52184+
(Warnings.Deprecated
52185+
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
52186+
transform_interp e.pexp_loc s
5218352187
| Unrecognized -> e
5218452188

5218552189

lib/4.06.1/unstable/js_compiler.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -85152,7 +85152,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
8515285152
e with
8515385153
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
8515485154
}
85155-
| J -> transform_interp e.pexp_loc s
85155+
| J ->
85156+
Location.prerr_warning e.pexp_loc
85157+
(Warnings.Deprecated
85158+
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
85159+
transform_interp e.pexp_loc s
8515685160
| Unrecognized -> e
8515785161

8515885162

lib/4.06.1/unstable/js_playground_compiler.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -85152,7 +85152,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
8515285152
e with
8515385153
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
8515485154
}
85155-
| J -> transform_interp e.pexp_loc s
85155+
| J ->
85156+
Location.prerr_warning e.pexp_loc
85157+
(Warnings.Deprecated
85158+
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
85159+
transform_interp e.pexp_loc s
8515685160
| Unrecognized -> e
8515785161

8515885162

lib/4.06.1/whole_compiler.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -179572,7 +179572,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
179572179572
e with
179573179573
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
179574179574
}
179575-
| J -> transform_interp e.pexp_loc s
179575+
| J ->
179576+
Location.prerr_warning e.pexp_loc
179577+
(Warnings.Deprecated
179578+
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
179579+
transform_interp e.pexp_loc s
179576179580
| Unrecognized -> e
179577179581

179578179582

0 commit comments

Comments
 (0)