Skip to content

Commit e0e262c

Browse files
committed
add blob and file to untagged variants instanceof support
1 parent 98f9a4e commit e0e262c

File tree

15 files changed

+75
-8
lines changed

15 files changed

+75
-8
lines changed

jscomp/ml/ast_untagged_variants.ml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
module Instance = struct
2-
type t = Array | Promise | Date | RegExp
2+
type t =
3+
| Array
4+
| Promise
5+
| Date
6+
| RegExp
7+
| File
8+
| Blob
39
let to_string = function
410
Array -> "Array"
511
| Promise -> "Promise"
612
| Date -> "Date"
713
| RegExp -> "RegExp"
14+
| File -> "File"
15+
| Blob -> "Blob"
816
end
917

1018
type untaggedError =
@@ -137,10 +145,12 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
137145
match t.desc with
138146
| Tconstr (path, _, _) -> (
139147
match Path.name path with
140-
| "Js.Date.t" -> Some(Instance.Date)
141-
| "Js.Re.t" | "RescriptCore.Re.t" ->
148+
| "Js.Date.t" | "Js_date.t" -> Some(Instance.Date)
149+
| "Js.Re.t" | "Js_re.t" | "RescriptCore.Re.t" ->
142150
(* TODO: Get rid of explicit Core by digging through aliases *)
143151
Some(RegExp)
152+
| "Js.File.t" | "Js_file.t" -> Some(File)
153+
| "Js.Blob.t" | "Js_blob.t" -> Some(Blob)
144154
| _ -> None)
145155
| _ -> None
146156

jscomp/others/js.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ module Int = Js_int
261261
module Bigint = Js_bigint
262262
(** Provide utilities for bigint *)
263263

264+
module File = Js_file
265+
(** Provide utilities for File *)
266+
267+
module Blob = Js_blob
268+
(** Provide utilities for Blob *)
269+
264270
module Option = Js_option
265271
(** Provide utilities for option *)
266272

jscomp/others/js_blob.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*** JavaScript Blob API */
2+
3+
type t

jscomp/others/js_file.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*** JavaScript File API */
2+
3+
type t

jscomp/others/release.ninja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ o others/js_OO.cmi others/js_OO.cmj : cc others/js_OO.res | others/belt_internal
1919
o others/js_array.cmi others/js_array.cmj : cc others/js_array.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj $bsc
2020
o others/js_array2.cmi others/js_array2.cmj : cc others/js_array2.res | others/belt_internals.cmi others/js.cmi $bsc
2121
o others/js_bigint.cmi others/js_bigint.cmj : cc others/js_bigint.res | others/belt_internals.cmi others/js.cmi $bsc
22+
o others/js_blob.cmi others/js_blob.cmj : cc others/js_blob.res | others/belt_internals.cmi others/js.cmi $bsc
2223
o others/js_cast.cmj : cc_cmi others/js_cast.res | others/belt_internals.cmi others/js.cmi others/js_cast.cmi $bsc
2324
o others/js_cast.cmi : cc others/js_cast.resi | others/belt_internals.cmi others/js.cmi $bsc
2425
o others/js_console.cmi others/js_console.cmj : cc others/js_console.res | others/belt_internals.cmi others/js.cmi $bsc
@@ -27,6 +28,7 @@ o others/js_dict.cmj : cc_cmi others/js_dict.res | others/belt_internals.cmi oth
2728
o others/js_dict.cmi : cc others/js_dict.resi | others/belt_internals.cmi others/js.cmi $bsc
2829
o others/js_exn.cmj : cc_cmi others/js_exn.res | others/belt_internals.cmi others/js.cmi others/js_exn.cmi $bsc
2930
o others/js_exn.cmi : cc others/js_exn.resi | others/belt_internals.cmi others/js.cmi $bsc
31+
o others/js_file.cmi others/js_file.cmj : cc others/js_file.res | others/belt_internals.cmi others/js.cmi $bsc
3032
o others/js_float.cmi others/js_float.cmj : cc others/js_float.res | others/belt_internals.cmi others/js.cmi $bsc
3133
o others/js_global.cmi others/js_global.cmj : cc others/js_global.res | others/belt_internals.cmi others/js.cmi $bsc
3234
o others/js_int.cmi others/js_int.cmj : cc others/js_int.res | others/belt_internals.cmi others/js.cmi $bsc
@@ -72,7 +74,7 @@ o others/jsxEventU.cmi others/jsxEventU.cmj : cc others/jsxEventU.res | others/b
7274
o others/jsxPPXReactSupportC.cmi others/jsxPPXReactSupportC.cmj : cc others/jsxPPXReactSupportC.res | others/belt_internals.cmi others/js.cmi others/jsxC.cmj $bsc
7375
o others/jsxPPXReactSupportU.cmi others/jsxPPXReactSupportU.cmj : cc others/jsxPPXReactSupportU.res | others/belt_internals.cmi others/js.cmi others/jsxU.cmj $bsc
7476
o others/jsxU.cmi others/jsxU.cmj : cc others/jsxU.res | others/belt_internals.cmi others/js.cmi $bsc
75-
o js_pkg : phony others/js_OO.cmi others/js_OO.cmj others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_bigint.cmi others/js_bigint.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_map.cmi others/js_map.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re.cmj others/js_result.cmi others/js_result.cmj others/js_set.cmi others/js_set.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj others/js_weakmap.cmi others/js_weakmap.cmj others/js_weakset.cmi others/js_weakset.cmj others/jsxC.cmi others/jsxC.cmj others/jsxDOMC.cmi others/jsxDOMC.cmj others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj others/jsxDOMU.cmi others/jsxDOMU.cmj others/jsxEventC.cmi others/jsxEventC.cmj others/jsxEventU.cmi others/jsxEventU.cmj others/jsxPPXReactSupportC.cmi others/jsxPPXReactSupportC.cmj others/jsxPPXReactSupportU.cmi others/jsxPPXReactSupportU.cmj others/jsxU.cmi others/jsxU.cmj
77+
o js_pkg : phony others/js_OO.cmi others/js_OO.cmj others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_bigint.cmi others/js_bigint.cmj others/js_blob.cmi others/js_blob.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_file.cmi others/js_file.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_map.cmi others/js_map.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re.cmj others/js_result.cmi others/js_result.cmj others/js_set.cmi others/js_set.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj others/js_weakmap.cmi others/js_weakmap.cmj others/js_weakset.cmi others/js_weakset.cmj others/jsxC.cmi others/jsxC.cmj others/jsxDOMC.cmi others/jsxDOMC.cmj others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj others/jsxDOMU.cmi others/jsxDOMU.cmj others/jsxEventC.cmi others/jsxEventC.cmj others/jsxEventU.cmi others/jsxEventU.cmj others/jsxPPXReactSupportC.cmi others/jsxPPXReactSupportC.cmj others/jsxPPXReactSupportU.cmi others/jsxPPXReactSupportU.cmj others/jsxU.cmi others/jsxU.cmj
7678
o others/belt_Array.cmj : cc_cmi others/belt_Array.res | others/belt.cmi others/belt_Array.cmi others/belt_internals.cmi others/js.cmi others/js.cmj others/js_math.cmj $bsc js_pkg
7779
o others/belt_Array.cmi : cc others/belt_Array.resi | others/belt.cmi others/belt_internals.cmi others/js.cmi others/js.cmj $bsc js_pkg
7880
o others/belt_Float.cmj : cc_cmi others/belt_Float.res | others/belt.cmi others/belt_Float.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg

jscomp/runtime/js.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ module Int = Js_int
228228
module Bigint = Js_bigint
229229
(** Provide utilities for bigint *)
230230

231+
module File = Js_file
232+
(** Provide utilities for File *)
233+
234+
module Blob = Js_blob
235+
(** Provide utilities for Blob *)
236+
231237
module Option = Js_option
232238
(** Provide utilities for option *)
233239

jscomp/test/UntaggedVariants.js

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/UntaggedVariants.res

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ module Arr = {
387387
module AllInstanceofTypes = {
388388
type record = {userName: string}
389389

390+
@get external fileName: Js.File.t => string = "name"
391+
@get external blobSize: Js.Blob.t => float = "size"
392+
390393
@unboxed
391394
type t =
392395
| String(string)
@@ -395,7 +398,8 @@ module AllInstanceofTypes = {
395398
| Object(record)
396399
| Date(Js.Date.t)
397400
| RegExp(Js.Re.t)
398-
| BigInt(Js.Bigint.t)
401+
| File(Js.File.t)
402+
| Blob(Js.Blob.t)
399403

400404
let classifyAll = async (t: t) =>
401405
switch t {
@@ -404,7 +408,8 @@ module AllInstanceofTypes = {
404408
| Object({userName}) => Js.log(userName)
405409
| Date(date) => Js.log(date->Js.Date.toString)
406410
| RegExp(re) => Js.log(re->Js.Re.test_("test"))
407-
| BigInt(i) => Js.log(Js.String.make(i))
408411
| Array(arr) => Js.log(arr->Belt.Array.joinWith("-"))
412+
| File(file) => Js.log(file->fileName)
413+
| Blob(blob) => Js.log(blob->blobSize)
409414
}
410415
}

lib/es6/js.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ var Int;
5353

5454
var Bigint;
5555

56+
var $$File;
57+
58+
var $$Blob;
59+
5660
var $$Option;
5761

5862
var Result;
@@ -98,6 +102,8 @@ export {
98102
Float ,
99103
Int ,
100104
Bigint ,
105+
$$File ,
106+
$$Blob ,
101107
$$Option ,
102108
Result ,
103109
List ,

lib/es6/js_blob.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/es6/js_file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/js/js.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ var Int;
5353

5454
var Bigint;
5555

56+
var $$File;
57+
58+
var $$Blob;
59+
5660
var $$Option;
5761

5862
var Result;
@@ -97,6 +101,8 @@ exports.Types = Types;
97101
exports.Float = Float;
98102
exports.Int = Int;
99103
exports.Bigint = Bigint;
104+
exports.$$File = $$File;
105+
exports.$$Blob = $$Blob;
100106
exports.$$Option = $$Option;
101107
exports.Result = Result;
102108
exports.List = List;

lib/js/js_blob.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/js/js_file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

packages/artifacts.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ lib/es6/js_OO.js
112112
lib/es6/js_array.js
113113
lib/es6/js_array2.js
114114
lib/es6/js_bigint.js
115+
lib/es6/js_blob.js
115116
lib/es6/js_cast.js
116117
lib/es6/js_console.js
117118
lib/es6/js_date.js
118119
lib/es6/js_dict.js
119120
lib/es6/js_exn.js
121+
lib/es6/js_file.js
120122
lib/es6/js_float.js
121123
lib/es6/js_global.js
122124
lib/es6/js_int.js
@@ -273,11 +275,13 @@ lib/js/js_OO.js
273275
lib/js/js_array.js
274276
lib/js/js_array2.js
275277
lib/js/js_bigint.js
278+
lib/js/js_blob.js
276279
lib/js/js_cast.js
277280
lib/js/js_console.js
278281
lib/js/js_date.js
279282
lib/js/js_dict.js
280283
lib/js/js_exn.js
284+
lib/js/js_file.js
281285
lib/js/js_float.js
282286
lib/js/js_global.js
283287
lib/js/js_int.js
@@ -716,6 +720,10 @@ lib/ocaml/js_bigint.cmi
716720
lib/ocaml/js_bigint.cmj
717721
lib/ocaml/js_bigint.cmt
718722
lib/ocaml/js_bigint.res
723+
lib/ocaml/js_blob.cmi
724+
lib/ocaml/js_blob.cmj
725+
lib/ocaml/js_blob.cmt
726+
lib/ocaml/js_blob.res
719727
lib/ocaml/js_cast.cmi
720728
lib/ocaml/js_cast.cmj
721729
lib/ocaml/js_cast.cmt
@@ -742,6 +750,10 @@ lib/ocaml/js_exn.cmt
742750
lib/ocaml/js_exn.cmti
743751
lib/ocaml/js_exn.res
744752
lib/ocaml/js_exn.resi
753+
lib/ocaml/js_file.cmi
754+
lib/ocaml/js_file.cmj
755+
lib/ocaml/js_file.cmt
756+
lib/ocaml/js_file.res
745757
lib/ocaml/js_float.cmi
746758
lib/ocaml/js_float.cmj
747759
lib/ocaml/js_float.cmt

0 commit comments

Comments
 (0)