Skip to content
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

Deprecate unsafe "j" string interpolation #6067

Merged
merged 1 commit into from
Mar 12, 2023
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 @@ -25,6 +25,7 @@

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

# 10.1.3

Expand Down
9 changes: 9 additions & 0 deletions jscomp/build_tests/super_errors/expected/jinterp.res.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

Warning number 3
/.../fixtures/jinterp.res:3:10-21

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

deprecated: The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.
3 changes: 3 additions & 0 deletions jscomp/build_tests/super_errors/fixtures/jinterp.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

let a = 11
let b = j`number $(a)`
6 changes: 5 additions & 1 deletion jscomp/frontend/ast_utf8_string_interp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
e with
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
}
| J -> transform_interp e.pexp_loc s
| J ->
Location.prerr_warning e.pexp_loc
(Warnings.Deprecated
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
transform_interp e.pexp_loc s
| Unrecognized -> e


Expand Down
4 changes: 2 additions & 2 deletions jscomp/stdlib-406/arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ let print_spec buf (key, spec, doc) =
match spec with
| Symbol (l, _) ->
let sym = make_symlist "{" "|" "}" l in
Buffer.add_string buf {j| $(key) $(sym)$(doc)\n|j}
Buffer.add_string buf (((((" " ^ key) ^ " ") ^ sym) ^ doc) ^ "\n")
| _ ->
Buffer.add_string buf {j| $(key) $(doc)\n|j}
Buffer.add_string buf ((((" " ^ key) ^ " ") ^ doc) ^ "\n")



Expand Down
60 changes: 28 additions & 32 deletions jscomp/stdlib-406/printexc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
[@@@bs.config { flags = [|"-bs-no-cross-module-opt" |]}]

[@@@bs.config { flags = [| "-bs-no-cross-module-opt" |] }]

let printers = ref []

let locfmt s (linum : int) (start : int) (finish : int) msg =
{j|File "$(s)", line $(linum), characters $(start)-$(finish): $(msg)|j}

let locfmt s (linum : int) (start : int) (finish : int) msg =
(((((((("File \"" ^ s) ^ "\", line ") ^ __unsafe_cast linum) ^ ", characters ")
^ __unsafe_cast start)
^ "-")
^ __unsafe_cast finish)
^ ": ")
^ msg

let fields : exn -> string = [%raw{|function(x){
let fields : exn -> string =
[%raw
{|function(x){
var s = ""
var index = 1
while ("_"+index in x){
Expand All @@ -33,47 +38,38 @@ let fields : exn -> string = [%raw{|function(x){
}
return "(" + s + ")"
}
|}]




|}]

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

let to_string x =
let to_string x =
let rec conv = function
| hd :: tl ->
(match try hd x with _ -> None with
| Some s -> s
| None -> conv tl)
| [] ->
| hd :: tl -> (
match try hd x with _ -> None with Some s -> s | None -> conv tl)
| [] -> (
match x with
| Match_failure(file, line, char) ->
locfmt file line char (char+5) "Pattern matching failed"
| Assert_failure(file, line, char) ->
locfmt file line char (char+6) "Assertion failed"
| Undefined_recursive_module(file, line, char) ->
locfmt file line char (char+6) "Undefined recursive module"
| Match_failure (file, line, char) ->
locfmt file line char (char + 5) "Pattern matching failed"
| Assert_failure (file, line, char) ->
locfmt file line char (char + 6) "Assertion failed"
| Undefined_recursive_module (file, line, char) ->
locfmt file line char (char + 6) "Undefined recursive module"
| _ ->
let constructor =
exn_slot_name x in
constructor ^ fields x in
let constructor = exn_slot_name x in
constructor ^ fields x)
in
conv !printers

let print fct arg =
try
fct arg
try fct arg
with x ->
Js.log ("Uncaught exception: " ^ to_string x);
raise x

let catch fct arg =
try
fct arg
try fct arg
with x ->
Js.log ("Uncaught exception: " ^ to_string x);
exit 2

let register_printer fn =
printers := fn :: !printers
let register_printer fn = printers := fn :: !printers
6 changes: 5 additions & 1 deletion lib/4.06.1/unstable/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52179,7 +52179,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
e with
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
}
| J -> transform_interp e.pexp_loc s
| J ->
Location.prerr_warning e.pexp_loc
(Warnings.Deprecated
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
transform_interp e.pexp_loc s
| Unrecognized -> e


Expand Down
6 changes: 5 additions & 1 deletion lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85152,7 +85152,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
e with
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
}
| J -> transform_interp e.pexp_loc s
| J ->
Location.prerr_warning e.pexp_loc
(Warnings.Deprecated
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
transform_interp e.pexp_loc s
| Unrecognized -> e


Expand Down
6 changes: 5 additions & 1 deletion lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85152,7 +85152,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
e with
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
}
| J -> transform_interp e.pexp_loc s
| J ->
Location.prerr_warning e.pexp_loc
(Warnings.Deprecated
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
transform_interp e.pexp_loc s
| Unrecognized -> e


Expand Down
6 changes: 5 additions & 1 deletion lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179572,7 +179572,11 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression =
e with
pexp_desc = Pexp_constant (Pconst_string (js_str, Delim.escaped));
}
| J -> transform_interp e.pexp_loc s
| J ->
Location.prerr_warning e.pexp_loc
(Warnings.Deprecated
("The unsafe j`$(a)$(b)` interpolation is deprecated, use string template `${a}${b}` instead.", e.pexp_loc, e.pexp_loc));
transform_interp e.pexp_loc s
| Unrecognized -> e


Expand Down