File tree Expand file tree Collapse file tree 4 files changed +9
-4
lines changed Expand file tree Collapse file tree 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 =
176176let instanceof ?comment (e0 : t ) (e1 : t ) : t =
177177 { expression_desc = Bin (InstanceOf , e0, e1); comment }
178178
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+
179183let new_ ?comment e0 args : t =
180184 { expression_desc = New (e0, Some args); comment }
181185
Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ val is_type_object : t -> t
212212
213213val typeof : ?comment : string -> t -> t
214214val instanceof : ?comment : string -> t -> t -> t
215+ val is_array : t -> t
215216
216217val to_int32 : ?comment : string -> t -> t
217218
Original file line number Diff line number Diff line change @@ -749,7 +749,7 @@ and compile_untagged_cases cxt switch_exp table default =
749749 | Block StringType
750750 | Block FloatType
751751 | Block Object -> E. string_equal (E. typeof y) x
752- | Block Array -> E. instanceof y x
752+ | Block Array -> E. is_array y
753753 | Block Unknown ->
754754 (* This should not happen because unknown must be the only non-literal case *)
755755 assert false
@@ -767,7 +767,7 @@ and compile_untagged_cases cxt switch_exp table default =
767767 match array_clauses with
768768 | [(l, {J. switch_body})] when List. length clauses > 1 ->
769769 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 )
771771 (switch_body)
772772 ~else_: ([S. string_switch ?default ?declaration (E. typeof e) rest])
773773 | _ :: _ :: _ -> assert false (* at most 1 array case *)
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ var OnlyBlocks = {
154154} ;
155155
156156function classify$5 ( x ) {
157- if ( x instanceof Array ) {
157+ if ( Array . isArray ( x ) ) {
158158 return "array" ;
159159 }
160160 switch ( typeof x ) {
@@ -184,7 +184,7 @@ function classify$6(x) {
184184
185185 }
186186 } else {
187- if ( x instanceof Array ) {
187+ if ( Array . isArray ( x ) ) {
188188 return {
189189 TAG : "JSONArray" ,
190190 _0 : x
You can’t perform that action at this time.
0 commit comments