Skip to content

Commit 433d4f1

Browse files
committed
Add delim to the representation of strings.
1 parent 83e2d92 commit 433d4f1

File tree

12 files changed

+53
-45
lines changed

12 files changed

+53
-45
lines changed

jscomp/core/j.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ and expression_desc =
147147
it will be true when it's a method
148148
The last pararemter [true] return unit
149149
*)
150-
| Str of {pure: bool; txt: string}
150+
| Str of {delim: string option; txt: string}
151151
(* A string is UTF-8 encoded, and may contain
152152
escape sequences.
153153
*)

jscomp/core/js_analyzer.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
9090
| String_index (a, b) | Array_index (a, b) ->
9191
no_side_effect a && no_side_effect b
9292
| Is_null_or_undefined b -> no_side_effect b
93-
| Str {pure} -> pure
93+
| Str _ -> true
9494
| Array (xs, _mutable_flag) | Caml_block (xs, _mutable_flag, _, _) ->
9595
(* create [immutable] block,
9696
does not really mean that this opreation itself is [pure].
@@ -181,8 +181,8 @@ let rec eq_expression ({ expression_desc = x0 } : J.expression)
181181
| Bin (op1, a1, b1) ->
182182
op0 = op1 && eq_expression a0 a1 && eq_expression b0 b1
183183
| _ -> false)
184-
| Str {pure=a0; txt=b0} -> (
185-
match y0 with Str {pure=a1; txt=b1} -> a0 = a1 && b0 = b1 | _ -> false)
184+
| Str {delim=a0; txt=b0} -> (
185+
match y0 with Str {delim=a1; txt=b1} -> a0 = a1 && b0 = b1 | _ -> false)
186186
| Static_index (e0, p0, off0) -> (
187187
match y0 with
188188
| Static_index (e1, p1, off1) ->

jscomp/core/js_dump.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,12 @@ and expression_desc cxt ~(level : int) f x : cxt =
591591
P.string f s;
592592
P.string f "\"";
593593
cxt
594-
| Str {txt} ->
594+
| Str {delim; txt} ->
595595
(*TODO --
596596
when utf8-> it will not escape '\\' which is definitely not we want
597597
*)
598-
Js_dump_string.pp_string f txt;
598+
if delim <> None then P.string f ("\"" ^ txt ^ "\"")
599+
else Js_dump_string.pp_string f txt;
599600
cxt
600601
| Raw_js_code { code = s; code_info = info } -> (
601602
match info with

jscomp/core/js_exp_make.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ let pure_runtime_call module_name fn_name args =
125125

126126
let runtime_ref module_name fn_name = runtime_var_dot module_name fn_name
127127

128-
let str ?(pure = true) ?comment s : t =
129-
{ expression_desc = Str {pure; txt=s}; comment }
128+
let str ?(delim = None) ?comment txt : t =
129+
{ expression_desc = Str {txt; delim}; comment }
130130

131131
let unicode ?comment s : t = { expression_desc = Unicode s; comment }
132132

jscomp/core/js_exp_make.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ val pure_runtime_call :
8282

8383
val runtime_ref : string -> string -> t
8484

85-
val str : ?pure:bool -> ?comment:string -> string -> t
85+
val str : ?delim: string option -> ?comment: string -> string -> t
8686

8787
val unicode : ?comment:string -> string -> t
8888

jscomp/core/js_fold.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,4 @@ class fold =
288288
let _self = _self#required_modules _x1 in
289289
_self
290290
end
291+

jscomp/core/js_record_fold.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,4 @@ let super : 'state iter =
305305
block;
306306
program;
307307
}
308+

jscomp/core/js_record_iter.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,4 @@ let super : iter =
226226
block;
227227
program;
228228
}
229+

jscomp/core/js_record_map.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,4 @@ let super : iter =
302302
block;
303303
program;
304304
}
305+

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65323,7 +65323,7 @@ and expression_desc =
6532365323
it will be true when it's a method
6532465324
The last pararemter [true] return unit
6532565325
*)
65326-
| Str of {pure: bool; txt: string}
65326+
| Str of {delim: string option; txt: string}
6532765327
(* A string is UTF-8 encoded, and may contain
6532865328
escape sequences.
6532965329
*)
@@ -66384,7 +66384,7 @@ let super : iter =
6638466384
block;
6638566385
program;
6638666386
}
66387-
66387+
6638866388
end
6638966389
module Js_analyzer : sig
6639066390
#1 "js_analyzer.mli"
@@ -66556,7 +66556,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) =
6655666556
| String_index (a, b) | Array_index (a, b) ->
6655766557
no_side_effect a && no_side_effect b
6655866558
| Is_null_or_undefined b -> no_side_effect b
66559-
| Str {pure} -> pure
66559+
| Str _ -> true
6656066560
| Array (xs, _mutable_flag) | Caml_block (xs, _mutable_flag, _, _) ->
6656166561
(* create [immutable] block,
6656266562
does not really mean that this opreation itself is [pure].
@@ -66647,8 +66647,8 @@ let rec eq_expression ({ expression_desc = x0 } : J.expression)
6664766647
| Bin (op1, a1, b1) ->
6664866648
op0 = op1 && eq_expression a0 a1 && eq_expression b0 b1
6664966649
| _ -> false)
66650-
| Str {pure=a0; txt=b0} -> (
66651-
match y0 with Str {pure=a1; txt=b1} -> a0 = a1 && b0 = b1 | _ -> false)
66650+
| Str {delim=a0; txt=b0} -> (
66651+
match y0 with Str {delim=a1; txt=b1} -> a0 = a1 && b0 = b1 | _ -> false)
6665266652
| Static_index (e0, p0, off0) -> (
6665366653
match y0 with
6665466654
| Static_index (e1, p1, off1) ->
@@ -66982,7 +66982,7 @@ val pure_runtime_call :
6698266982

6698366983
val runtime_ref : string -> string -> t
6698466984

66985-
val str : ?pure:bool -> ?comment:string -> string -> t
66985+
val str : ?delim: string option -> ?comment: string -> string -> t
6698666986

6698766987
val unicode : ?comment:string -> string -> t
6698866988

@@ -67370,8 +67370,8 @@ let pure_runtime_call module_name fn_name args =
6737067370

6737167371
let runtime_ref module_name fn_name = runtime_var_dot module_name fn_name
6737267372

67373-
let str ?(pure = true) ?comment s : t =
67374-
{ expression_desc = Str {pure; txt=s}; comment }
67373+
let str ?(delim = None) ?comment txt : t =
67374+
{ expression_desc = Str {txt; delim}; comment }
6737567375

6737667376
let unicode ?comment s : t = { expression_desc = Unicode s; comment }
6737767377

@@ -69756,11 +69756,12 @@ and expression_desc cxt ~(level : int) f x : cxt =
6975669756
P.string f s;
6975769757
P.string f "\"";
6975869758
cxt
69759-
| Str {txt} ->
69759+
| Str {delim; txt} ->
6976069760
(*TODO --
6976169761
when utf8-> it will not escape '\\' which is definitely not we want
6976269762
*)
69763-
Js_dump_string.pp_string f txt;
69763+
if delim <> None then P.string f ("\"" ^ txt ^ "\"")
69764+
else Js_dump_string.pp_string f txt;
6976469765
cxt
6976569766
| Raw_js_code { code = s; code_info = info } -> (
6976669767
match info with
@@ -79577,7 +79578,7 @@ let super : iter =
7957779578
block;
7957879579
program;
7957979580
}
79580-
79581+
7958179582
end
7958279583
module Js_pass_flatten : sig
7958379584
#1 "js_pass_flatten.mli"
@@ -80361,7 +80362,7 @@ let super : 'state iter =
8036180362
block;
8036280363
program;
8036380364
}
80364-
80365+
8036580366
end
8036680367
module Js_pass_scope : sig
8036780368
#1 "js_pass_scope.mli"

0 commit comments

Comments
 (0)