Skip to content

Commit aee06c0

Browse files
authored
Remove redundant space after continue in generated file (rescript-lang#6743)
* Remove continue label * Recompile tests * Update changelog
1 parent cfed01f commit aee06c0

File tree

218 files changed

+1917
-1969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+1917
-1969
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Make the `--help` arg be prioritized in the CLI, so correctly prints help message and skip other commands. https://github.com/rescript-lang/rescript-compiler/pull/6667
2929
- Remove redundant space for empty return in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6745
3030
- Remove redundant space for export in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6560
31+
- Remove redundant space after continue in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6743
3132
- Remove empty export blocks in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6744
3233
- Fix indent for returned/thrown/wrapped in parentheses objects in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6746
3334
- Fix indent in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6747

jscomp/core/j.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ type exports = Js_op.exports
4242
type tag_info = Js_op.tag_info
4343
type property_name = Js_op.property_name
4444

45-
type label = string
4645
and ident = Ident.t
4746
(* we override `method ident` *)
4847

@@ -254,15 +253,15 @@ and statement_desc =
254253
(* Function declaration and Variable declaration *)
255254
| Exp of expression
256255
| If of expression * block * block
257-
| While of label option * expression * block
256+
| While of expression * block
258257
(* check if it contains loop mutable values, happens in nested loop *)
259258
| ForRange of
260259
for_ident_expression option
261260
* finish_ident_expression
262261
* for_ident
263262
* for_direction
264263
* block
265-
| Continue of label
264+
| Continue
266265
| Break (* only used when inline a fucntion *)
267266
| Return of expression
268267
(* Here we need track back a bit ?, move Return to Function ...

jscomp/core/js_analyzer.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ let no_side_effect_obj =
123123
statement =
124124
(fun self s ->
125125
match s.statement_desc with
126-
| Throw _ | Debugger | Break | Variable _ | Continue _ ->
126+
| Throw _ | Debugger | Break | Variable _ | Continue ->
127127
raise_notrace Not_found
128128
| Exp e -> self.expression self e
129129
| Int_switch _ | String_switch _ | ForRange _ | If _ | While _ | Block _
@@ -226,7 +226,7 @@ and eq_statement ({ statement_desc = x0 } : J.statement)
226226
| Debugger -> y0 = Debugger
227227
| Break -> y0 = Break
228228
| Block xs0 -> ( match y0 with Block ys0 -> eq_block xs0 ys0 | _ -> false)
229-
| Variable _ | If _ | While _ | ForRange _ | Continue _ | Int_switch _
229+
| Variable _ | If _ | While _ | ForRange _ | Continue | Int_switch _
230230
| String_switch _ | Throw _ | Try _ ->
231231
false
232232

jscomp/core/js_dump.ml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,8 @@ let break_nl f =
232232
semi f;
233233
P.newline f
234234

235-
let continue f s =
235+
let continue f =
236236
P.string f L.continue;
237-
P.space f;
238-
P.string f s;
239237
semi f
240238

241239
let formal_parameter_list cxt f l = iter_lst cxt f l Ext_pp_scope.ident comma_sp
@@ -1020,14 +1018,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
10201018
P.string f L.else_;
10211019
P.space f;
10221020
brace_block cxt f s2)
1023-
| While (label, e, s) ->
1021+
| While (e, s) ->
10241022
(* FIXME: print scope as well *)
1025-
(match label with
1026-
| Some i ->
1027-
P.string f i;
1028-
P.string f L.colon;
1029-
P.newline f
1030-
| None -> ());
10311023
let cxt =
10321024
match e.expression_desc with
10331025
| Number (Int { i = 1l }) ->
@@ -1120,8 +1112,8 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
11201112
brace_block cxt f s)
11211113
in
11221114
action cxt
1123-
| Continue s ->
1124-
continue f s;
1115+
| Continue ->
1116+
continue f;
11251117
cxt
11261118
(* P.newline f; #2642 *)
11271119
| Debugger ->

jscomp/core/js_fold.ml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class fold =
4747
let _self = _self#list _f_a _x_i1 in
4848
_self
4949

50-
method label : label -> 'self_type = unknown _self
51-
5250
method ident : ident -> 'self_type = unknown _self
5351

5452
method module_id : module_id -> 'self_type =
@@ -217,10 +215,9 @@ class fold =
217215
let _self = _self#block _x1 in
218216
let _self = _self#block _x2 in
219217
_self
220-
| While (_x0, _x1, _x2) ->
221-
let _self = option (fun _self -> _self#label) _self _x0 in
222-
let _self = _self#expression _x1 in
223-
let _self = _self#block _x2 in
218+
| While (_x0, _x1) ->
219+
let _self = _self#expression _x0 in
220+
let _self = _self#block _x1 in
224221
_self
225222
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
226223
let _self =
@@ -231,9 +228,7 @@ class fold =
231228
let _self = _self#for_direction _x3 in
232229
let _self = _self#block _x4 in
233230
_self
234-
| Continue _x0 ->
235-
let _self = _self#label _x0 in
236-
_self
231+
| Continue -> _self
237232
| Break -> _self
238233
| Return _x0 ->
239234
let _self = _self#expression _x0 in

jscomp/core/js_pass_scope.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ let record_scope_pass =
287287
closured_idents =
288288
Set_ident.union state.closured_idents lexical_scope;
289289
}
290-
| While (_label, pred, body) ->
290+
| While (pred, body) ->
291291
with_in_loop
292292
(self.block self
293293
(with_in_loop (self.expression self state pred) true)

jscomp/core/js_record_fold.ml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ type 'state iter = {
5151

5252
and ('state, 'a) fn = 'state iter -> 'state -> 'a -> 'state
5353

54-
let label : 'a. ('a, label) fn = unknown
55-
5654
let ident : 'a. ('a, ident) fn = unknown
5755

5856
let module_id : 'a. ('a, module_id) fn =
@@ -223,10 +221,9 @@ let statement_desc : 'a. ('a, statement_desc) fn =
223221
let st = _self.block _self st _x1 in
224222
let st = _self.block _self st _x2 in
225223
st
226-
| While (_x0, _x1, _x2) ->
227-
let st = option label _self st _x0 in
228-
let st = _self.expression _self st _x1 in
229-
let st = _self.block _self st _x2 in
224+
| While (_x0, _x1) ->
225+
let st = _self.expression _self st _x0 in
226+
let st = _self.block _self st _x1 in
230227
st
231228
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
232229
let st = option for_ident_expression _self st _x0 in
@@ -235,9 +232,7 @@ let statement_desc : 'a. ('a, statement_desc) fn =
235232
let st = for_direction _self st _x3 in
236233
let st = _self.block _self st _x4 in
237234
st
238-
| Continue _x0 ->
239-
let st = label _self st _x0 in
240-
st
235+
| Continue -> st
241236
| Break -> st
242237
| Return _x0 ->
243238
let st = _self.expression _self st _x0 in

jscomp/core/js_record_iter.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ type iter = {
5151

5252
and 'a fn = iter -> 'a -> unit
5353

54-
let label : label fn = unknown
55-
5654
let ident : ident fn = unknown
5755

5856
let module_id : module_id fn =
@@ -163,17 +161,16 @@ let statement_desc : statement_desc fn =
163161
_self.expression _self _x0;
164162
_self.block _self _x1;
165163
_self.block _self _x2
166-
| While (_x0, _x1, _x2) ->
167-
option label _self _x0;
168-
_self.expression _self _x1;
169-
_self.block _self _x2
164+
| While (_x0, _x1) ->
165+
_self.expression _self _x0;
166+
_self.block _self _x1
170167
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
171168
option for_ident_expression _self _x0;
172169
finish_ident_expression _self _x1;
173170
_self.for_ident _self _x2;
174171
for_direction _self _x3;
175172
_self.block _self _x4
176-
| Continue _x0 -> label _self _x0
173+
| Continue -> ()
177174
| Break -> ()
178175
| Return _x0 -> _self.expression _self _x0
179176
| Int_switch (_x0, _x1, _x2) ->

jscomp/core/js_record_map.ml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ type iter = {
5151

5252
and 'a fn = iter -> 'a -> 'a
5353

54-
let label : label fn = unknown
55-
5654
let ident : ident fn = unknown
5755

5856
let module_id : module_id fn =
@@ -221,21 +219,18 @@ let statement_desc : statement_desc fn =
221219
let _x1 = _self.block _self _x1 in
222220
let _x2 = _self.block _self _x2 in
223221
If (_x0, _x1, _x2)
224-
| While (_x0, _x1, _x2) ->
225-
let _x0 = option label _self _x0 in
226-
let _x1 = _self.expression _self _x1 in
227-
let _x2 = _self.block _self _x2 in
228-
While (_x0, _x1, _x2)
222+
| While (_x0, _x1) ->
223+
let _x0 = _self.expression _self _x0 in
224+
let _x1 = _self.block _self _x1 in
225+
While (_x0, _x1)
229226
| ForRange (_x0, _x1, _x2, _x3, _x4) ->
230227
let _x0 = option for_ident_expression _self _x0 in
231228
let _x1 = finish_ident_expression _self _x1 in
232229
let _x2 = _self.for_ident _self _x2 in
233230
let _x3 = for_direction _self _x3 in
234231
let _x4 = _self.block _self _x4 in
235232
ForRange (_x0, _x1, _x2, _x3, _x4)
236-
| Continue _x0 ->
237-
let _x0 = label _self _x0 in
238-
Continue _x0
233+
| Continue as v -> v
239234
| Break as v -> v
240235
| Return _x0 ->
241236
let _x0 = _self.expression _self _x0 in

jscomp/core/js_stmt_make.ml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ let rec block_last_is_return_throw_or_continue (x : J.block) =
179179
| [] -> false
180180
| [ x ] -> (
181181
match x.statement_desc with
182-
| Return _ | Throw _ | Continue _ -> true
182+
| Return _ | Throw _ | Continue -> true
183183
| _ -> false)
184184
| _ :: rest -> block_last_is_return_throw_or_continue rest
185185

@@ -318,8 +318,8 @@ let if_ ?comment ?declaration ?else_ (e : J.expression) (then_ : J.block) : t =
318318
let assign ?comment id e : t =
319319
{ statement_desc = J.Exp (E.assign (E.var id) e); comment }
320320

321-
let while_ ?comment ?label (e : E.t) (st : J.block) : t =
322-
{ statement_desc = While (label, e, st); comment }
321+
let while_ ?comment (e : E.t) (st : J.block) : t =
322+
{ statement_desc = While (e, st); comment }
323323

324324
let for_ ?comment for_ident_expression finish_ident_expression id direction
325325
(b : J.block) : t =
@@ -333,15 +333,6 @@ let for_ ?comment for_ident_expression finish_ident_expression id direction
333333
let try_ ?comment ?with_ ?finally body : t =
334334
{ statement_desc = Try (body, with_, finally); comment }
335335

336-
(* TODO:
337-
actually, only loops can be labelled
338-
*)
339-
(* let continue_stmt ?comment ?(label="") () : t =
340-
{
341-
statement_desc = J.Continue label;
342-
comment;
343-
} *)
344-
345-
let continue_ : t = { statement_desc = Continue ""; comment = None }
336+
let continue_ : t = { statement_desc = Continue; comment = None }
346337

347338
let debugger_block : t list = [ { statement_desc = Debugger; comment = None } ]

jscomp/core/js_stmt_make.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ val assign : ?comment:string -> J.ident -> J.expression -> t
132132

133133
val while_ :
134134
?comment:string ->
135-
?label:J.label ->
136135
J.expression ->
137136
J.block ->
138137
t

jscomp/core/lam_compile.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
320320
(id : Ident.t) (arg : Lam.t) : Js_output.t * initialization =
321321
match arg with
322322
| Lfunction { params; body; attr = { return_unit; async; oneUnitArg } } ->
323-
let continue_label = Lam_util.generate_label ~name:id.name () in
324323
(* TODO: Think about recursive value
325324
{[
326325
let rec v = ref (fun _ ...
@@ -331,7 +330,6 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
331330
let ret : Lam_compile_context.return_label =
332331
{
333332
id;
334-
label = continue_label;
335333
params;
336334
immutable_mask = Array.make (List.length params) true;
337335
new_params = Map_ident.empty;
@@ -363,7 +361,7 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
363361
(Ext_list.map params (fun x ->
364362
Map_ident.find_default ret.new_params x x))
365363
[
366-
S.while_ (* ~label:continue_label *) E.true_
364+
S.while_ E.true_
367365
(Map_ident.fold ret.new_params body_block
368366
(fun old new_param acc ->
369367
S.define_variable ~kind:Alias old (E.var new_param) :: acc));

jscomp/core/lam_compile_context.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type value = { exit_id : Ident.t; bindings : Ident.t list; order_id : int }
3333
*)
3434
type return_label = {
3535
id : Ident.t;
36-
label : J.label;
3736
params : Ident.t list;
3837
immutable_mask : bool array;
3938
mutable new_params : Ident.t Map_ident.t;

jscomp/core/lam_compile_context.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ type jbl_label = int
3333

3434
type return_label = {
3535
id : Ident.t;
36-
label : J.label;
3736
params : Ident.t list;
3837
immutable_mask : bool array;
3938
mutable new_params : Ident.t Map_ident.t;

jscomp/core/lam_util.ml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,6 @@ let field_flatten_get
212212
| Some _
213213
| None -> lam ()
214214

215-
216-
(* TODO: check that if label belongs to a different
217-
namesape
218-
*)
219-
let count = ref 0
220-
221-
let generate_label ?(name="") () =
222-
incr count;
223-
Printf.sprintf "%s_tailcall_%04d" name !count
224-
225215
#if (defined BROWSER || defined RELEASE)
226216
let dump ext lam =
227217
()

jscomp/core/lam_util.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ val alias_ident_or_global :
5454

5555
val refine_let : kind:Lam_compat.let_kind -> Ident.t -> Lam.t -> Lam.t -> Lam.t
5656

57-
val generate_label : ?name:string -> unit -> J.label
58-
5957
val dump : string -> Lam.t -> unit
6058
(** [dump] when {!Js_config.is_same_file}*)
6159

jscomp/test/a_scope_bug.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/and_or_tailcall_test.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/arith_lexer.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)