Skip to content

Commit 32ccf6b

Browse files
committed
Fix Array.isArray.
1 parent 4a1aaee commit 32ccf6b

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

compiler/core/js_exp_make.ml

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,10 @@ let rec push_negation (e : t) : t option =
711711
712712
Type check optimizations:
713713
- [(typeof x === "boolean") && (x === true/false)] -> [x === true/false]
714-
- [(typeof x === "string" || Array.isArray(x)) && (x === boolean/null/undefined)] -> [false]
714+
- [(typeof x === "string") && (x === boolean/null/undefined)] -> [false]
715+
- [(Array.isArray(x)) && (x === boolean/null/undefined)] -> [false]
716+
717+
- TODO: [(typeof x === "boolean") && (x !== null)] -> [typeof x === "boolean"]
715718
716719
Note: The function preserves the semantics of the original expression while
717720
attempting to reduce it to a simpler form. If no simplification is possible,
@@ -790,14 +793,7 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
790793
Some {expression_desc = b; comment = None}
791794
| ( Bin
792795
( EqEqEq,
793-
{
794-
expression_desc =
795-
( Typeof {expression_desc = Var ia}
796-
| Call
797-
( {expression_desc = Str {txt = "Array.isArray"}},
798-
[{expression_desc = Var ia}],
799-
_ ) );
800-
},
796+
{expression_desc = Typeof {expression_desc = Var ia}},
801797
{expression_desc = Str {txt = "boolean" | "string"}} ),
802798
Bin
803799
( EqEqEq,
@@ -809,18 +805,29 @@ let rec simplify_and (e1 : t) (e2 : t) : t option =
809805
{expression_desc = Bool _ | Null | Undefined _} ),
810806
Bin
811807
( EqEqEq,
812-
{
813-
expression_desc =
814-
( Typeof {expression_desc = Var ia}
815-
| Call
816-
( {expression_desc = Str {txt = "Array.isArray"}},
817-
[{expression_desc = Var ia}],
818-
_ ) );
819-
},
808+
{expression_desc = Typeof {expression_desc = Var ia}},
820809
{expression_desc = Str {txt = "boolean" | "string"}} ) )
821810
when Js_op_util.same_vident ia ib ->
822811
(* Note: case boolean / Bool _ is handled above *)
823812
Some false_
813+
| ( Call
814+
( {expression_desc = Str {txt = "Array.isArray"}},
815+
[{expression_desc = Var ia}],
816+
_ ),
817+
Bin
818+
( EqEqEq,
819+
{expression_desc = Var ib},
820+
{expression_desc = Bool _ | Null | Undefined _} ) )
821+
| ( Bin
822+
( EqEqEq,
823+
{expression_desc = Var ib},
824+
{expression_desc = Bool _ | Null | Undefined _} ),
825+
Call
826+
( {expression_desc = Str {txt = "Array.isArray"}},
827+
[{expression_desc = Var ia}],
828+
_ ) )
829+
when Js_op_util.same_vident ia ib ->
830+
Some false_
824831
| _ -> None
825832

826833
(**

0 commit comments

Comments
 (0)