diff --git a/CHANGELOG.md b/CHANGELOG.md index b3272d4ce0..44059a7f9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ #### :rocket: New Feature +- Add support for Set, Map, WeakSet and WeakMap to `@unboxed`. https://github.com/rescript-lang/rescript/pull/8009 + #### :bug: Bug fix - Fix fatal compiler error that occurred when an `%ffi` extension point contained invalid JavaScript https://github.com/rescript-lang/rescript/pull/7998 diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index 9cb7d015c8..06673db5ed 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -19,6 +19,10 @@ module Instance = struct | Uint32Array | Uint8Array | Uint8ClampedArray + | Set + | Map + | WeakSet + | WeakMap let to_string = function | Array -> "Array" | ArrayBuffer -> "ArrayBuffer" @@ -39,6 +43,10 @@ module Instance = struct | Uint32Array -> "Uint32Array" | Uint8Array -> "Uint8Array" | Uint8ClampedArray -> "Uint8ClampedArray" + | Set -> "Set" + | Map -> "Map" + | WeakSet -> "WeakSet" + | WeakMap -> "WeakMap" end type untagged_error = @@ -256,6 +264,10 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) = | "Stdlib.Uint8ClampedArray.t" -> Some Uint8ClampedArray | "Js_file.t" -> Some File | "Js_blob.t" -> Some Blob + | "Stdlib.Set.t" -> Some Set + | "Stdlib.Map.t" -> Some Map + | "Stdlib.WeakSet.t" -> Some WeakSet + | "Stdlib.WeakMap.t" -> Some WeakMap | _ -> None) | _ -> None diff --git a/tests/tests/src/UntaggedVariants.mjs b/tests/tests/src/UntaggedVariants.mjs index b5384b39ec..29e4477626 100644 --- a/tests/tests/src/UntaggedVariants.mjs +++ b/tests/tests/src/UntaggedVariants.mjs @@ -573,6 +573,22 @@ async function classifyAll(t) { console.log("DataView"); return; } + if (t instanceof Set) { + console.log("Set"); + return; + } + if (t instanceof Map) { + console.log("Map"); + return; + } + if (t instanceof WeakSet) { + console.log("WeakSet"); + return; + } + if (t instanceof WeakMap) { + console.log("WeakMap"); + return; + } switch (typeof t) { case "string" : console.log(t); diff --git a/tests/tests/src/UntaggedVariants.res b/tests/tests/src/UntaggedVariants.res index 8b55e268a4..9ec7aa0d92 100644 --- a/tests/tests/src/UntaggedVariants.res +++ b/tests/tests/src/UntaggedVariants.res @@ -413,6 +413,10 @@ module AllInstanceofTypes = { | BigInt64Array(BigInt64Array.t) | BigUint64Array(BigUint64Array.t) | DataView(DataView.t) + | Set(Set.t) + | Map(Map.t) + | WeakSet(WeakSet.t) + | WeakMap(WeakMap.t) let classifyAll = async (t: t) => switch t { @@ -437,6 +441,10 @@ module AllInstanceofTypes = { | BigInt64Array(_) => Console.log("BigInt64Array") | BigUint64Array(_) => Console.log("BigUint64Array") | DataView(_) => Console.log("DataView") + | Set(_) => Console.log("Set") + | Map(_) => Console.log("Map") + | WeakSet(_) => Console.log("WeakSet") + | WeakMap(_) => Console.log("WeakMap") } }