Skip to content

Commit 3224ba8

Browse files
committed
support < > in for loop
1 parent 321b19d commit 3224ba8

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

jscomp/core/j.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ and exception_ident = ident
9494

9595
and for_ident = ident
9696

97-
and for_direction = Asttypes.direction_flag
97+
and for_direction = Js_op.direction_flag
9898

9999
and property_map =
100100
(property_name * expression) list

jscomp/core/js_dump.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ let pp_var_declare cxt f id =
265265

266266
let pp_direction f (direction : J.for_direction) =
267267
match direction with
268+
| Up
268269
| Upto -> P.string f L.plus_plus
270+
| Down
269271
| Downto -> P.string f L.minus_minus
270272

271273
let return_sp f =
@@ -1171,10 +1173,18 @@ and statement_desc top cxt f (s : J.statement_desc) : cxt =
11711173
let (_,_,right) = Js_op_util.op_prec Le in
11721174
P.string f L.le;
11731175
right
1176+
| Up ->
1177+
let (_,_,right) = Js_op_util.op_prec Lt in
1178+
P.string f L.lt;
1179+
right
11741180
| Downto ->
11751181
let (_,_,right) = Js_op_util.op_prec Ge in
11761182
P.string f L.ge ;
11771183
right
1184+
| Down ->
1185+
let (_,_,right) = Js_op_util.op_prec Gt in
1186+
P.string f L.gt ;
1187+
right
11781188
in
11791189
P.space f ;
11801190
let cxt =

jscomp/core/js_dump_lit.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ let string_cap = "String"
8181
let fromCharcode = "fromCharCode"
8282
let eq = "="
8383
let le = "<="
84+
let lt = "<"
8485
let ge = ">="
86+
let gt = ">"
8587
let plus_plus = "++"
8688
(* FIXME: use (i = i + 1 | 0) instead *)
8789
let minus_minus = "--"

jscomp/core/js_op.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ type mutable_flag =
184184
| Mutable
185185
| Immutable
186186
| NA
187-
187+
type direction_flag =
188+
| Upto
189+
| Downto
190+
| Up
191+
| Down
188192
(*
189193
{[
190194
let rec x = 1 :: y

jscomp/core/lam_compile.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,13 @@ and compile_while (predicate : Lam.t) (body : Lam.t) (lambda_cxt : Lam_compile_c
954954
*)
955955

956956
and compile_for
957-
id start finish direction body (lambda_cxt : Lam_compile_context.t) =
957+
(id : J.for_ident)
958+
(start : Lam.t)
959+
(finish : Lam.t)
960+
(direction : Js_op.direction_flag)
961+
(body : Lam.t)
962+
(lambda_cxt : Lam_compile_context.t)
963+
=
958964
let new_cxt = {lambda_cxt with continuation = NeedValue Not_tail} in
959965
let block =
960966
match compile_lambda new_cxt start,
@@ -1599,8 +1605,13 @@ and compile_lambda
15991605
compile_staticcatch cur_lam lambda_cxt
16001606
| Lwhile(p,body) ->
16011607
compile_while p body lambda_cxt
1602-
| Lfor (id,start,finish,direction,body) ->
1603-
compile_for id start finish direction body lambda_cxt
1608+
| Lfor (id,start,finish,direction,body) ->
1609+
begin match direction with
1610+
| Upto ->
1611+
compile_for id start finish Upto body lambda_cxt
1612+
| Downto ->
1613+
compile_for id start finish Downto body lambda_cxt
1614+
end
16041615
| Lassign(id,lambda) ->
16051616
compile_assign id lambda lambda_cxt
16061617
| Ltrywith(lam,id, catch) -> (* generate documentation *)

0 commit comments

Comments
 (0)