diff --git a/CHANGELOG.md b/CHANGELOG.md index fcdf8236a6..637f479aad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ - In type errors, recommend stdlib over Belt functions for converting between float/int/string. https://github.com/rescript-lang/rescript/pull/7453 - Remove unused type `Jsx.ref`. https://github.com/rescript-lang/rescript/pull/7459 +- Add `@notUndefined` attribute to all relevant abstract types in `Stdlib`. https://github.com/rescript-lang/rescript/pull/7464 # 12.0.0-alpha.12 diff --git a/runtime/Stdlib_ArrayBuffer.res b/runtime/Stdlib_ArrayBuffer.res index 2b0cf3a36b..4b672e196d 100644 --- a/runtime/Stdlib_ArrayBuffer.res +++ b/runtime/Stdlib_ArrayBuffer.res @@ -1,3 +1,4 @@ +@notUndefined type t @new external make: int => t = "ArrayBuffer" diff --git a/runtime/Stdlib_AsyncIterator.res b/runtime/Stdlib_AsyncIterator.res index 03504dafc0..b62128c821 100644 --- a/runtime/Stdlib_AsyncIterator.res +++ b/runtime/Stdlib_AsyncIterator.res @@ -1,3 +1,4 @@ +@notUndefined type t<'a> type value<'a> = { diff --git a/runtime/Stdlib_AsyncIterator.resi b/runtime/Stdlib_AsyncIterator.resi index 50db4fdf3b..5d2e9b6dcf 100644 --- a/runtime/Stdlib_AsyncIterator.resi +++ b/runtime/Stdlib_AsyncIterator.resi @@ -6,6 +6,7 @@ See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/Java /** The type representing an async iterator. */ +@notUndefined type t<'a> type value<'a> = { diff --git a/runtime/Stdlib_DataView.res b/runtime/Stdlib_DataView.res index 8ab0025336..2c0ccd91bf 100644 --- a/runtime/Stdlib_DataView.res +++ b/runtime/Stdlib_DataView.res @@ -1,3 +1,4 @@ +@notUndefined type t @new external fromBuffer: Stdlib_ArrayBuffer.t => t = "DataView" diff --git a/runtime/Stdlib_Intl_Collator.res b/runtime/Stdlib_Intl_Collator.res index f457c247f7..4329a6f1c5 100644 --- a/runtime/Stdlib_Intl_Collator.res +++ b/runtime/Stdlib_Intl_Collator.res @@ -1,3 +1,4 @@ +@notUndefined type t type usage = [#sort | #search] diff --git a/runtime/Stdlib_Intl_DateTimeFormat.res b/runtime/Stdlib_Intl_DateTimeFormat.res index 9c2be84b11..00992bee49 100644 --- a/runtime/Stdlib_Intl_DateTimeFormat.res +++ b/runtime/Stdlib_Intl_DateTimeFormat.res @@ -1,3 +1,4 @@ +@notUndefined type t type dateStyle = [#full | #long | #medium | #short] diff --git a/runtime/Stdlib_Intl_ListFormat.res b/runtime/Stdlib_Intl_ListFormat.res index 3dd0b280e6..3f4b0cb41f 100644 --- a/runtime/Stdlib_Intl_ListFormat.res +++ b/runtime/Stdlib_Intl_ListFormat.res @@ -1,3 +1,4 @@ +@notUndefined type t type listType = [ diff --git a/runtime/Stdlib_Intl_Locale.res b/runtime/Stdlib_Intl_Locale.res index 45c9388e29..f250413f53 100644 --- a/runtime/Stdlib_Intl_Locale.res +++ b/runtime/Stdlib_Intl_Locale.res @@ -1,3 +1,4 @@ +@notUndefined type t type options = { diff --git a/runtime/Stdlib_Intl_NumberFormat.res b/runtime/Stdlib_Intl_NumberFormat.res index f69d7f1148..4962de43d4 100644 --- a/runtime/Stdlib_Intl_NumberFormat.res +++ b/runtime/Stdlib_Intl_NumberFormat.res @@ -1,5 +1,6 @@ module Grouping = Stdlib_Intl_NumberFormat_Grouping +@notUndefined type t /** @@ -211,7 +212,7 @@ external formatBigIntRangeToParts: (t, ~start: bigint, ~end: bigint) => array array = "formatToParts" /** - `ignore(numberGrouping)` ignores the provided numberGrouping and returns unit. + `ignore(numberFormat)` ignores the provided numberFormat and returns unit. This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further. diff --git a/runtime/Stdlib_Intl_NumberFormat_Grouping.res b/runtime/Stdlib_Intl_NumberFormat_Grouping.res index 47227b6e7f..f0b0c82a4a 100644 --- a/runtime/Stdlib_Intl_NumberFormat_Grouping.res +++ b/runtime/Stdlib_Intl_NumberFormat_Grouping.res @@ -1,3 +1,4 @@ +@notUndefined type t type parsed = [#bool(bool) | #always | #auto | #min2] diff --git a/runtime/Stdlib_Intl_PluralRules.res b/runtime/Stdlib_Intl_PluralRules.res index 8e52f7d98a..49348b9aac 100644 --- a/runtime/Stdlib_Intl_PluralRules.res +++ b/runtime/Stdlib_Intl_PluralRules.res @@ -1,3 +1,4 @@ +@notUndefined type t type localeType = [#cardinal | #ordinal] diff --git a/runtime/Stdlib_Intl_RelativeTimeFormat.res b/runtime/Stdlib_Intl_RelativeTimeFormat.res index f3173520d7..2454473e36 100644 --- a/runtime/Stdlib_Intl_RelativeTimeFormat.res +++ b/runtime/Stdlib_Intl_RelativeTimeFormat.res @@ -1,3 +1,4 @@ +@notUndefined type t type numeric = [#always | #auto] diff --git a/runtime/Stdlib_Intl_Segmenter.res b/runtime/Stdlib_Intl_Segmenter.res index fd79657ef0..16bf7a2c07 100644 --- a/runtime/Stdlib_Intl_Segmenter.res +++ b/runtime/Stdlib_Intl_Segmenter.res @@ -1,6 +1,4 @@ -/*** -Not supported in Firefox -*/ +@notUndefined type t type granularity = [#grapheme | #word | #sentence] diff --git a/runtime/Stdlib_Intl_Segments.res b/runtime/Stdlib_Intl_Segments.res index 32b0d4cb0e..39f2ff7269 100644 --- a/runtime/Stdlib_Intl_Segments.res +++ b/runtime/Stdlib_Intl_Segments.res @@ -2,6 +2,7 @@ A Segments instance is an object that represents the segments of a specific string, subject to the locale and options of its constructing Intl.Segmenter instance. https://tc39.es/ecma402/#sec-segments-objects */ +@notUndefined type t type segmentData = { diff --git a/runtime/Stdlib_Iterator.res b/runtime/Stdlib_Iterator.res index f631b604d1..01d14aa5a1 100644 --- a/runtime/Stdlib_Iterator.res +++ b/runtime/Stdlib_Iterator.res @@ -1,3 +1,4 @@ +@notUndefined type t<'a> type value<'a> = { diff --git a/runtime/Stdlib_Iterator.resi b/runtime/Stdlib_Iterator.resi index 359039a588..91e43fe00e 100644 --- a/runtime/Stdlib_Iterator.resi +++ b/runtime/Stdlib_Iterator.resi @@ -7,6 +7,7 @@ See [`iterator protocols`](https://developer.mozilla.org/en-US/docs/Web/JavaScri /** The type representing an iterator. */ +@notUndefined type t<'a> /** diff --git a/runtime/Stdlib_JsError.res b/runtime/Stdlib_JsError.res index 17ff192439..0622973178 100644 --- a/runtime/Stdlib_JsError.res +++ b/runtime/Stdlib_JsError.res @@ -1,3 +1,4 @@ +@notUndefined type t @get external stack: t => option = "stack" diff --git a/runtime/Stdlib_JsError.resi b/runtime/Stdlib_JsError.resi index 9f55fd7a82..2304cf9569 100644 --- a/runtime/Stdlib_JsError.resi +++ b/runtime/Stdlib_JsError.resi @@ -5,6 +5,7 @@ See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ */ /** Represents a JavaScript error. */ +@notUndefined type t /** diff --git a/runtime/Stdlib_Map.res b/runtime/Stdlib_Map.res index 2a4ea8d8ca..7d534aa7d8 100644 --- a/runtime/Stdlib_Map.res +++ b/runtime/Stdlib_Map.res @@ -1,3 +1,4 @@ +@notUndefined type t<'k, 'v> @new external make: unit => t<'k, 'v> = "Map" diff --git a/runtime/Stdlib_Map.resi b/runtime/Stdlib_Map.resi index 3fc56d3f1a..3df63191e3 100644 --- a/runtime/Stdlib_Map.resi +++ b/runtime/Stdlib_Map.resi @@ -7,6 +7,7 @@ See [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl /** Type representing an instance of `Map`. */ +@notUndefined type t<'k, 'v> /** diff --git a/runtime/Stdlib_Pair.res b/runtime/Stdlib_Pair.res index 767ad280ff..745bad6557 100644 --- a/runtime/Stdlib_Pair.res +++ b/runtime/Stdlib_Pair.res @@ -27,7 +27,7 @@ Pair.second((1, 2))->assertEqual(2) external second: (('a, 'b)) => 'b = "%field1" /** - `ignore(option)` ignores the provided pair and returns unit. + `ignore(pair)` ignores the provided pair and returns unit. This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further. diff --git a/runtime/Stdlib_Set.res b/runtime/Stdlib_Set.res index 724058afb1..61040dc863 100644 --- a/runtime/Stdlib_Set.res +++ b/runtime/Stdlib_Set.res @@ -1,3 +1,4 @@ +@notUndefined type t<'a> @new external make: unit => t<'a> = "Set" diff --git a/runtime/Stdlib_Set.resi b/runtime/Stdlib_Set.resi index 9437fe85e1..4945add4d1 100644 --- a/runtime/Stdlib_Set.resi +++ b/runtime/Stdlib_Set.resi @@ -7,6 +7,7 @@ See [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl /** Type representing an instance of `Set`. */ +@notUndefined type t<'a> /** diff --git a/runtime/Stdlib_Symbol.res b/runtime/Stdlib_Symbol.res index 195f82cfe9..bbdb978313 100644 --- a/runtime/Stdlib_Symbol.res +++ b/runtime/Stdlib_Symbol.res @@ -1,3 +1,4 @@ +@notUndefined type t @val external make: string => t = "Symbol" diff --git a/runtime/Stdlib_Symbol.resi b/runtime/Stdlib_Symbol.resi index 5dceef04c3..3a2bf3bf17 100644 --- a/runtime/Stdlib_Symbol.resi +++ b/runtime/Stdlib_Symbol.resi @@ -7,6 +7,7 @@ Compiles to a regular JavaScript Symbol. /** Type representing a Symbol. */ +@notUndefined type t /** @@ -28,7 +29,7 @@ external make: string => t = "Symbol" /** `getFor(key)` -Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found. +Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found. Otherwise a new Symbol gets created and registered with key. ## Examples diff --git a/runtime/Stdlib_TypedArray.res b/runtime/Stdlib_TypedArray.res index 2d9a5add76..759f81cb18 100644 --- a/runtime/Stdlib_TypedArray.res +++ b/runtime/Stdlib_TypedArray.res @@ -1,3 +1,4 @@ +@notUndefined type t<'a> @get_index external get: (t<'a>, int) => option<'a> = "" diff --git a/runtime/Stdlib_WeakMap.res b/runtime/Stdlib_WeakMap.res index f6846eb17a..9fd4e99c82 100644 --- a/runtime/Stdlib_WeakMap.res +++ b/runtime/Stdlib_WeakMap.res @@ -1,3 +1,4 @@ +@notUndefined type t<'k, 'v> @new external make: unit => t<'k, 'v> = "WeakMap" diff --git a/runtime/Stdlib_WeakSet.res b/runtime/Stdlib_WeakSet.res index 6d6deefdfd..5316552323 100644 --- a/runtime/Stdlib_WeakSet.res +++ b/runtime/Stdlib_WeakSet.res @@ -1,3 +1,4 @@ +@notUndefined type t<'a> @new external make: unit => t<'a> = "WeakSet" diff --git a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs index 988d5795bb..132cd9709b 100644 --- a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs @@ -1,6 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; import * as Stdlib_Intl_NumberFormat_Grouping from "rescript/lib/es6/Stdlib_Intl_NumberFormat_Grouping.js"; console.log("---"); @@ -26,7 +25,7 @@ let roundingFormatter = new Intl.NumberFormat(undefined, { }); let groupingFormatter1 = new Intl.NumberFormat(undefined, { - useGrouping: Primitive_option.some(true) + useGrouping: true }); let groupingFormatter2 = new Intl.NumberFormat(undefined, { diff --git a/tests/tests/src/internal_unused_test.res b/tests/tests/src/internal_unused_test.res index 437c3cf754..23a11190e0 100644 --- a/tests/tests/src/internal_unused_test.res +++ b/tests/tests/src/internal_unused_test.res @@ -17,7 +17,7 @@ module P1 = { } open! P1 -let f = () => raise(A) +let f = () => throw(A) %%private(let b = 3) diff --git a/tests/tests/src/option_wrapping_test.mjs b/tests/tests/src/option_wrapping_test.mjs index 4efe8a0437..1f04be7cd7 100644 --- a/tests/tests/src/option_wrapping_test.mjs +++ b/tests/tests/src/option_wrapping_test.mjs @@ -1,6 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js"; import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; +import * as Stdlib_AsyncIterator from "rescript/lib/es6/Stdlib_AsyncIterator.js"; let x6 = { x: 42 @@ -24,6 +26,54 @@ let x21 = new Date(); let x22 = /test/; +let x23 = new Map(); + +let x24 = new Set(); + +let x25 = new WeakMap(); + +let x26 = new WeakSet(); + +let x27 = new Float32Array([1.0]); + +let x28 = Symbol(""); + +let x29 = new Error(""); + +let x30 = new ArrayBuffer(0); + +let x31 = new DataView(new ArrayBuffer(0)); + +let x32 = new Map().values(); + +let x33 = Stdlib_AsyncIterator.make(() => Promise.resolve(Stdlib_AsyncIterator.value(true))); + +let x34 = new Intl.ListFormat(); + +let x35 = new Intl.Segmenter(); + +let x36 = new Intl.Segmenter().segment(""); + +let x37 = new Intl.DateTimeFormat(); + +let x38 = new Intl.NumberFormat(); + +let x39 = true; + +let x40 = new Intl.Collator(); + +let x41 = new Intl.RelativeTimeFormat(); + +let x42 = new Intl.PluralRules(); + +let x43 = new Intl.Locale("en"); + +let x45 = Promise.resolve(true); + +let x47 = {}; + +let x48 = Stdlib_Lazy.make(() => true); + let x1 = "hello"; let x2 = 1; @@ -41,6 +91,13 @@ let x5 = { let x12 = "test"; +let x44 = [ + 1, + 2 +]; + +let x46 = /* [] */0; + export { x1, x2, @@ -56,5 +113,31 @@ export { x20, x21, x22, + x23, + x24, + x25, + x26, + x27, + x28, + x29, + x30, + x31, + x32, + x33, + x34, + x35, + x36, + x37, + x38, + x39, + x40, + x41, + x42, + x43, + x44, + x45, + x46, + x47, + x48, } /* x20 Not a pure module */ diff --git a/tests/tests/src/option_wrapping_test.res b/tests/tests/src/option_wrapping_test.res index d9d7040d84..57e03476f2 100644 --- a/tests/tests/src/option_wrapping_test.res +++ b/tests/tests/src/option_wrapping_test.res @@ -16,3 +16,31 @@ let x12 = Some(Nullable.Value("test")) let x20 = Some(Jsx.null) let x21 = Some(Date.make()) let x22 = Some(/test/) +let x23 = Some((Map.make(): Map.t)) +let x24 = Some((Set.make(): Set.t)) +let x25 = Some((WeakMap.make(): WeakMap.t)) +let x26 = Some((WeakSet.make(): WeakSet.t)) +let x27 = Some(Float32Array.fromArray([1.0])) +let x28 = Some(Symbol.make("")) +let x29 = Some(JsError.make("")) +let x30 = Some(ArrayBuffer.make(0)) +let x31 = Some(ArrayBuffer.make(0)->DataView.fromBuffer) +let x32 = Some((Map.make(): Map.t)->Map.values) +let x33 = Some(AsyncIterator.make(_ => AsyncIterator.value(true)->Promise.resolve)) + +let x34 = Some(Intl.ListFormat.make()) +let x35 = Some(Intl.Segmenter.make()) +let x36 = Some(Intl.Segmenter.make()->Intl.Segmenter.segment("")) +let x37 = Some(Intl.DateTimeFormat.make()) +let x38 = Some(Intl.NumberFormat.make()) +let x39 = Some(Intl.NumberFormat.Grouping.fromBool(true)) +let x40 = Some(Intl.Collator.make()) +let x41 = Some(Intl.RelativeTimeFormat.make()) +let x42 = Some(Intl.PluralRules.make()) +let x43 = Some(Intl.Locale.make("en")) + +let x44 = Some((1, 2)) +let x45 = Some(Promise.resolve(true)) +let x46 = Some(list{}) +let x47 = Some((Dict.make(): dict)) +let x48 = Some(Lazy.make(_ => true))