Skip to content

Commit 3c4b033

Browse files
authored
Add @notundefined attribute to more Stdlib abstract types (#7464)
* Add @notundefined attribute to Stdlib_Map.t * Add @notundefined attribute to Stdlib_Set.t * Add @notundefined attribute to Stdlib_WeakMap.t and Stdlib_WeakSet.t * Add @notundefined attribute to Stdlib_TypedArray * Add @notundefined attribute to Stdlib_Symbol * Add @notundefined attribute to Stdlib_JsError * Add @notundefined attribute to Stdlib_ArrayBuffer * Add @notundefined attribute to Stdlib_DataView * Add @notundefined attribute to Stdlib_Iterator * Add @notundefined attribute to Stdlib_AsyncIterator * Remove outdated comment regarding Intl.Segmenter Firefox compatibility * Add @notundefined attribute to Stdlib_Intl_* * Typo * Use throw instead of deprecated raise in internal unused test * Restore trimmed whitespace * Add CHANGELOG entry
1 parent e9bc2c1 commit 3c4b033

33 files changed

+144
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
- In type errors, recommend stdlib over Belt functions for converting between float/int/string. https://github.com/rescript-lang/rescript/pull/7453
4747
- Remove unused type `Jsx.ref`. https://github.com/rescript-lang/rescript/pull/7459
48+
- Add `@notUndefined` attribute to all relevant abstract types in `Stdlib`. https://github.com/rescript-lang/rescript/pull/7464
4849

4950
# 12.0.0-alpha.12
5051

runtime/Stdlib_ArrayBuffer.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
@new external make: int => t = "ArrayBuffer"

runtime/Stdlib_AsyncIterator.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t<'a>
23

34
type value<'a> = {

runtime/Stdlib_AsyncIterator.resi

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ See [async iterator protocols](https://developer.mozilla.org/en-US/docs/Web/Java
66
/**
77
The type representing an async iterator.
88
*/
9+
@notUndefined
910
type t<'a>
1011

1112
type value<'a> = {

runtime/Stdlib_DataView.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
@new external fromBuffer: Stdlib_ArrayBuffer.t => t = "DataView"

runtime/Stdlib_Intl_Collator.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
type usage = [#sort | #search]

runtime/Stdlib_Intl_DateTimeFormat.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
type dateStyle = [#full | #long | #medium | #short]

runtime/Stdlib_Intl_ListFormat.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
type listType = [

runtime/Stdlib_Intl_Locale.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
type options = {

runtime/Stdlib_Intl_NumberFormat.res

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Grouping = Stdlib_Intl_NumberFormat_Grouping
22

3+
@notUndefined
34
type t
45

56
/**
@@ -211,7 +212,7 @@ external formatBigIntRangeToParts: (t, ~start: bigint, ~end: bigint) => array<nu
211212
external formatStringToParts: (t, string) => array<numberFormatRangePart> = "formatToParts"
212213

213214
/**
214-
`ignore(numberGrouping)` ignores the provided numberGrouping and returns unit.
215+
`ignore(numberFormat)` ignores the provided numberFormat and returns unit.
215216
216217
This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
217218
without having to store or process it further.

runtime/Stdlib_Intl_NumberFormat_Grouping.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
type parsed = [#bool(bool) | #always | #auto | #min2]

runtime/Stdlib_Intl_PluralRules.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
type localeType = [#cardinal | #ordinal]

runtime/Stdlib_Intl_RelativeTimeFormat.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
type numeric = [#always | #auto]

runtime/Stdlib_Intl_Segmenter.res

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/***
2-
Not supported in Firefox
3-
*/
1+
@notUndefined
42
type t
53

64
type granularity = [#grapheme | #word | #sentence]

runtime/Stdlib_Intl_Segments.res

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
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.
33
https://tc39.es/ecma402/#sec-segments-objects
44
*/
5+
@notUndefined
56
type t
67

78
type segmentData = {

runtime/Stdlib_Iterator.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t<'a>
23

34
type value<'a> = {

runtime/Stdlib_Iterator.resi

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ See [`iterator protocols`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
77
/**
88
The type representing an iterator.
99
*/
10+
@notUndefined
1011
type t<'a>
1112

1213
/**

runtime/Stdlib_JsError.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
@get external stack: t => option<string> = "stack"

runtime/Stdlib_JsError.resi

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ See [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
55
*/
66

77
/** Represents a JavaScript error. */
8+
@notUndefined
89
type t
910

1011
/**

runtime/Stdlib_Map.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t<'k, 'v>
23

34
@new external make: unit => t<'k, 'v> = "Map"

runtime/Stdlib_Map.resi

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ See [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl
77
/**
88
Type representing an instance of `Map`.
99
*/
10+
@notUndefined
1011
type t<'k, 'v>
1112

1213
/**

runtime/Stdlib_Pair.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Pair.second((1, 2))->assertEqual(2)
2727
external second: (('a, 'b)) => 'b = "%field1"
2828

2929
/**
30-
`ignore(option)` ignores the provided pair and returns unit.
30+
`ignore(pair)` ignores the provided pair and returns unit.
3131
3232
This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
3333
without having to store or process it further.

runtime/Stdlib_Set.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t<'a>
23

34
@new external make: unit => t<'a> = "Set"

runtime/Stdlib_Set.resi

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ See [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Gl
77
/**
88
Type representing an instance of `Set`.
99
*/
10+
@notUndefined
1011
type t<'a>
1112

1213
/**

runtime/Stdlib_Symbol.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t
23

34
@val external make: string => t = "Symbol"

runtime/Stdlib_Symbol.resi

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Compiles to a regular JavaScript Symbol.
77
/**
88
Type representing a Symbol.
99
*/
10+
@notUndefined
1011
type t
1112

1213
/**
@@ -28,7 +29,7 @@ external make: string => t = "Symbol"
2829
/**
2930
`getFor(key)`
3031

31-
Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found.
32+
Searches for existing registered Symbols in the global Symbol registry with the given key and returns it if found.
3233
Otherwise a new Symbol gets created and registered with key.
3334

3435
## Examples

runtime/Stdlib_TypedArray.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t<'a>
23

34
@get_index external get: (t<'a>, int) => option<'a> = ""

runtime/Stdlib_WeakMap.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t<'k, 'v>
23

34
@new external make: unit => t<'k, 'v> = "WeakMap"

runtime/Stdlib_WeakSet.res

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@notUndefined
12
type t<'a>
23

34
@new external make: unit => t<'a> = "WeakSet"

tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import * as Primitive_option from "rescript/lib/es6/Primitive_option.js";
43
import * as Stdlib_Intl_NumberFormat_Grouping from "rescript/lib/es6/Stdlib_Intl_NumberFormat_Grouping.js";
54

65
console.log("---");
@@ -26,7 +25,7 @@ let roundingFormatter = new Intl.NumberFormat(undefined, {
2625
});
2726

2827
let groupingFormatter1 = new Intl.NumberFormat(undefined, {
29-
useGrouping: Primitive_option.some(true)
28+
useGrouping: true
3029
});
3130

3231
let groupingFormatter2 = new Intl.NumberFormat(undefined, {

tests/tests/src/internal_unused_test.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module P1 = {
1717
}
1818
open! P1
1919

20-
let f = () => raise(A)
20+
let f = () => throw(A)
2121

2222
%%private(let b = 3)
2323

tests/tests/src/option_wrapping_test.mjs

+83
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3+
import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
34
import * as Primitive_option from "rescript/lib/es6/Primitive_option.js";
5+
import * as Stdlib_AsyncIterator from "rescript/lib/es6/Stdlib_AsyncIterator.js";
46

57
let x6 = {
68
x: 42
@@ -24,6 +26,54 @@ let x21 = new Date();
2426

2527
let x22 = /test/;
2628

29+
let x23 = new Map();
30+
31+
let x24 = new Set();
32+
33+
let x25 = new WeakMap();
34+
35+
let x26 = new WeakSet();
36+
37+
let x27 = new Float32Array([1.0]);
38+
39+
let x28 = Symbol("");
40+
41+
let x29 = new Error("");
42+
43+
let x30 = new ArrayBuffer(0);
44+
45+
let x31 = new DataView(new ArrayBuffer(0));
46+
47+
let x32 = new Map().values();
48+
49+
let x33 = Stdlib_AsyncIterator.make(() => Promise.resolve(Stdlib_AsyncIterator.value(true)));
50+
51+
let x34 = new Intl.ListFormat();
52+
53+
let x35 = new Intl.Segmenter();
54+
55+
let x36 = new Intl.Segmenter().segment("");
56+
57+
let x37 = new Intl.DateTimeFormat();
58+
59+
let x38 = new Intl.NumberFormat();
60+
61+
let x39 = true;
62+
63+
let x40 = new Intl.Collator();
64+
65+
let x41 = new Intl.RelativeTimeFormat();
66+
67+
let x42 = new Intl.PluralRules();
68+
69+
let x43 = new Intl.Locale("en");
70+
71+
let x45 = Promise.resolve(true);
72+
73+
let x47 = {};
74+
75+
let x48 = Stdlib_Lazy.make(() => true);
76+
2777
let x1 = "hello";
2878

2979
let x2 = 1;
@@ -41,6 +91,13 @@ let x5 = {
4191

4292
let x12 = "test";
4393

94+
let x44 = [
95+
1,
96+
2
97+
];
98+
99+
let x46 = /* [] */0;
100+
44101
export {
45102
x1,
46103
x2,
@@ -56,5 +113,31 @@ export {
56113
x20,
57114
x21,
58115
x22,
116+
x23,
117+
x24,
118+
x25,
119+
x26,
120+
x27,
121+
x28,
122+
x29,
123+
x30,
124+
x31,
125+
x32,
126+
x33,
127+
x34,
128+
x35,
129+
x36,
130+
x37,
131+
x38,
132+
x39,
133+
x40,
134+
x41,
135+
x42,
136+
x43,
137+
x44,
138+
x45,
139+
x46,
140+
x47,
141+
x48,
59142
}
60143
/* x20 Not a pure module */

tests/tests/src/option_wrapping_test.res

+28
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,31 @@ let x12 = Some(Nullable.Value("test"))
1616
let x20 = Some(Jsx.null)
1717
let x21 = Some(Date.make())
1818
let x22 = Some(/test/)
19+
let x23 = Some((Map.make(): Map.t<string, string>))
20+
let x24 = Some((Set.make(): Set.t<string>))
21+
let x25 = Some((WeakMap.make(): WeakMap.t<string, string>))
22+
let x26 = Some((WeakSet.make(): WeakSet.t<string>))
23+
let x27 = Some(Float32Array.fromArray([1.0]))
24+
let x28 = Some(Symbol.make(""))
25+
let x29 = Some(JsError.make(""))
26+
let x30 = Some(ArrayBuffer.make(0))
27+
let x31 = Some(ArrayBuffer.make(0)->DataView.fromBuffer)
28+
let x32 = Some((Map.make(): Map.t<string, string>)->Map.values)
29+
let x33 = Some(AsyncIterator.make(_ => AsyncIterator.value(true)->Promise.resolve))
30+
31+
let x34 = Some(Intl.ListFormat.make())
32+
let x35 = Some(Intl.Segmenter.make())
33+
let x36 = Some(Intl.Segmenter.make()->Intl.Segmenter.segment(""))
34+
let x37 = Some(Intl.DateTimeFormat.make())
35+
let x38 = Some(Intl.NumberFormat.make())
36+
let x39 = Some(Intl.NumberFormat.Grouping.fromBool(true))
37+
let x40 = Some(Intl.Collator.make())
38+
let x41 = Some(Intl.RelativeTimeFormat.make())
39+
let x42 = Some(Intl.PluralRules.make())
40+
let x43 = Some(Intl.Locale.make("en"))
41+
42+
let x44 = Some((1, 2))
43+
let x45 = Some(Promise.resolve(true))
44+
let x46 = Some(list{})
45+
let x47 = Some((Dict.make(): dict<string>))
46+
let x48 = Some(Lazy.make(_ => true))

0 commit comments

Comments
 (0)