You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Skeleton adapt untagged variants to several instanceof cases.
* handle instanceof for untagged variants in code generator
* extend examples
* add more instanceof backed type
* add blob and file to untagged variants instanceof support
* refactor
* centralize emission logic for instanceof checks
* changelog
---------
Co-authored-by: Gabriel Nordeborn <gabbe.nord@gmail.com>
Copy file name to clipboardExpand all lines: jscomp/ml/ast_untagged_variants.ml
+62-18Lines changed: 62 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,24 @@
1
+
moduleInstance=struct
2
+
typet =
3
+
| Array
4
+
| Blob
5
+
| Date
6
+
| File
7
+
| Promise
8
+
| RegExp
9
+
letto_string=function
10
+
Array -> "Array"
11
+
|Blob -> "Blob"
12
+
|Date -> "Date"
13
+
|File -> "File"
14
+
|Promise -> "Promise"
15
+
|RegExp -> "RegExp"
16
+
end
17
+
1
18
typeuntaggedError =
2
19
| OnlyOneUnknownofstring
3
20
| AtMostOneObject
4
-
| AtMostOneArray
21
+
| AtMostOneInstanceofInstance.t
5
22
| AtMostOneFunction
6
23
| AtMostOneString
7
24
| AtMostOneNumber
@@ -29,7 +46,7 @@ let report_error ppf =
29
46
(match untaggedVariant with
30
47
|OnlyOneUnknownname -> "Case "^ name ^" has a payload that is not of one of the recognized shapes (object, array, etc). Then it must be the only case with payloads."
31
48
|AtMostOneObject -> "At most one case can be an object type."
32
-
|AtMostOneArray-> "At most one case can be an array type."
49
+
|AtMostOneInstancei-> "At most one case can be a "^ (Instance.to_string i) ^" type."
33
50
|AtMostOneFunction -> "At most one case can be a function type."
34
51
|AtMostOneString -> "At most one case can be a string type."
35
52
|AtMostOneNumber ->
@@ -42,7 +59,7 @@ type block_type =
42
59
| IntType
43
60
| StringType
44
61
| FloatType
45
-
| ArrayType
62
+
| InstanceTypeofInstance.t
46
63
| FunctionType
47
64
| ObjectType
48
65
| UnknownType
@@ -121,9 +138,26 @@ let type_is_builtin_object (t : Types.type_expr) =
121
138
match t.desc with
122
139
|Tconstr (path, _, _) ->
123
140
let name =Path.name path in
124
-
name ="Js.Dict.t"|| name ="Js_dict.t"|| name ="Js.Re.t"|| name ="RescriptCore.Re.t"
0 commit comments