Skip to content

Commit f83fb38

Browse files
committed
refactor
1 parent c1acd47 commit f83fb38

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

jscomp/core/lam_compile.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ and compile_untagged_cases ~cxt ~switch_exp ~default ~block_cases cases =
766766
| Ast_untagged_variants.Untagged (InstanceType _) -> true
767767
| _ -> false in
768768
let switch ?default ?declaration e clauses =
769-
let not_typeof_clauses = Ext_list.filter clauses is_not_typeof in
770-
let typeof_clauses = Ext_list.filter clauses (fun c -> not (is_not_typeof c)) in
769+
let (not_typeof_clauses, typeof_clauses) = List.partition is_not_typeof clauses in
771770
let rec build_if_chain remaining_clauses = (match remaining_clauses with
772771
| (Ast_untagged_variants.Untagged (InstanceType Array), {J.switch_body}) :: rest ->
773772
S.if_ (E.is_array e)

jscomp/ml/ast_untagged_variants.ml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
module Instance = struct
22
type t =
3-
| Array
4-
| Promise
5-
| Date
6-
| RegExp
7-
| File
3+
| Array
84
| Blob
9-
let to_string = function
5+
| Date
6+
| File
7+
| Promise
8+
| RegExp
9+
let to_string = function
1010
Array -> "Array"
11+
| Blob -> "Blob"
12+
| Date -> "Date"
13+
| File -> "File"
1114
| Promise -> "Promise"
12-
| Date -> "Date"
1315
| RegExp -> "RegExp"
14-
| File -> "File"
15-
| Blob -> "Blob"
1616
end
1717

1818
type untaggedError =
@@ -143,9 +143,13 @@ let type_is_builtin_object (t : Types.type_expr) =
143143

144144
let type_to_instanceof_backed_obj (t : Types.type_expr) =
145145
match t.desc with
146+
| Tconstr (path, _, _) when Path.same path Predef.path_promise ->
147+
Some Instance.Promise
148+
| Tconstr (path, _, _) when Path.same path Predef.path_array ->
149+
Some Array
146150
| Tconstr (path, _, _) -> (
147151
match Path.name path with
148-
| "Js.Date.t" | "Js_date.t" -> Some(Instance.Date)
152+
| "Js.Date.t" | "Js_date.t" -> Some(Date)
149153
| "Js.Re.t" | "Js_re.t" | "RescriptCore.Re.t" ->
150154
(* TODO: Get rid of explicit Core by digging through aliases *)
151155
Some(RegExp)
@@ -167,12 +171,6 @@ let get_block_type ~env (cstr : Types.constructor_declaration) :
167171
| true, Cstr_tuple [{desc = Tconstr (path, _, _)}]
168172
when Path.same path Predef.path_float ->
169173
Some FloatType
170-
| true, Cstr_tuple [{desc = Tconstr (path, _, _)}]
171-
when Path.same path Predef.path_array ->
172-
Some (InstanceType Array)
173-
| true, Cstr_tuple [{desc = Tconstr (path, _, _)}]
174-
when Path.same path Predef.path_promise ->
175-
Some (InstanceType Promise)
176174
| true, Cstr_tuple [({desc = Tconstr _} as t)]
177175
when Ast_uncurried_utils.typeIsUncurriedFun t ->
178176
Some FunctionType

0 commit comments

Comments
 (0)