File tree 4 files changed +9
-4
lines changed
4 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,10 @@ let typeof ?comment (e : t) : t =
176
176
let instanceof ?comment (e0 : t ) (e1 : t ) : t =
177
177
{ expression_desc = Bin (InstanceOf , e0, e1); comment }
178
178
179
+ let is_array (e0 : t ) : t =
180
+ let f = str " Array.isArray" ~delim: DNoQuotes in
181
+ { expression_desc = Call (f, [e0], Js_call_info. ml_full_call); comment= None }
182
+
179
183
let new_ ?comment e0 args : t =
180
184
{ expression_desc = New (e0, Some args); comment }
181
185
Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ val is_type_object : t -> t
212
212
213
213
val typeof : ?comment : string -> t -> t
214
214
val instanceof : ?comment : string -> t -> t -> t
215
+ val is_array : t -> t
215
216
216
217
val to_int32 : ?comment : string -> t -> t
217
218
Original file line number Diff line number Diff line change @@ -749,7 +749,7 @@ and compile_untagged_cases cxt switch_exp table default =
749
749
| Block StringType
750
750
| Block FloatType
751
751
| Block Object -> E. string_equal (E. typeof y) x
752
- | Block Array -> E. instanceof y x
752
+ | Block Array -> E. is_array y
753
753
| Block Unknown ->
754
754
(* This should not happen because unknown must be the only non-literal case *)
755
755
assert false
@@ -767,7 +767,7 @@ and compile_untagged_cases cxt switch_exp table default =
767
767
match array_clauses with
768
768
| [(l, {J. switch_body})] when List. length clauses > 1 ->
769
769
let rest = Ext_list. filter clauses (fun c -> not (is_array c)) in
770
- S. if_ (E. instanceof e ( E. literal l) )
770
+ S. if_ (E. is_array e )
771
771
(switch_body)
772
772
~else_: ([S. string_switch ?default ?declaration (E. typeof e) rest])
773
773
| _ :: _ :: _ -> assert false (* at most 1 array case *)
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ var OnlyBlocks = {
154
154
} ;
155
155
156
156
function classify$5 ( x ) {
157
- if ( x instanceof Array ) {
157
+ if ( Array . isArray ( x ) ) {
158
158
return "array" ;
159
159
}
160
160
switch ( typeof x ) {
@@ -184,7 +184,7 @@ function classify$6(x) {
184
184
185
185
}
186
186
} else {
187
- if ( x instanceof Array ) {
187
+ if ( Array . isArray ( x ) ) {
188
188
return {
189
189
TAG : "JSONArray" ,
190
190
_0 : x
You can’t perform that action at this time.
0 commit comments