Skip to content

Commit 4dcd84b

Browse files
authored
Use dict instead of Dict.t everywhere (#7136)
* Use dict instead of Dict.t everywhere * CHANGELOG
1 parent 41e2fd6 commit 4dcd84b

File tree

37 files changed

+96
-95
lines changed

37 files changed

+96
-95
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
- Move `syntax_tests` into the `tests` folder. https://github.com/rescript-lang/rescript-compiler/pull/7090 https://github.com/rescript-lang/rescript-compiler/pull/7097
7070
- Capitalize runtime filenames. https://github.com/rescript-lang/rescript-compiler/pull/7110
7171
- Build mocha tests as esmodule / .mjs. https://github.com/rescript-lang/rescript-compiler/pull/7115
72+
- Use dict instead of Dict.t everywhere. https://github.com/rescript-lang/rescript-compiler/pull/7136
7273

7374
# 12.0.0-alpha.3
7475

runtime/Dict.res

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
type t<'a> = Js.Dict.t<'a>
1+
type t<'a> = dict<'a>
22

3-
@get_index external getUnsafe: (t<'a>, string) => 'a = ""
4-
@get_index external get: (t<'a>, string) => option<'a> = ""
5-
@set_index external set: (t<'a>, string, 'a) => unit = ""
3+
@get_index external getUnsafe: (dict<'a>, string) => 'a = ""
4+
@get_index external get: (dict<'a>, string) => option<'a> = ""
5+
@set_index external set: (dict<'a>, string, 'a) => unit = ""
66
@val external delete: 'a => unit = "delete"
77

88
let delete = (dict, string) => {
99
delete(get(dict, string))
1010
}
1111

12-
@obj external make: unit => t<'a> = ""
12+
@obj external make: unit => dict<'a> = ""
1313

14-
@val external fromArray: array<(string, 'a)> => t<'a> = "Object.fromEntries"
15-
@val external fromIterator: Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"
14+
@val external fromArray: array<(string, 'a)> => dict<'a> = "Object.fromEntries"
15+
@val external fromIterator: Iterator.t<(string, 'a)> => dict<'a> = "Object.fromEntries"
1616

17-
@val external toArray: t<'a> => array<(string, 'a)> = "Object.entries"
17+
@val external toArray: dict<'a> => array<(string, 'a)> = "Object.entries"
1818

19-
@val external keysToArray: t<'a> => array<string> = "Object.keys"
19+
@val external keysToArray: dict<'a> => array<string> = "Object.keys"
2020

21-
@val external valuesToArray: t<'a> => array<'a> = "Object.values"
21+
@val external valuesToArray: dict<'a> => array<'a> = "Object.values"
2222

23-
@val external assign: (t<'a>, t<'a>) => t<'a> = "Object.assign"
23+
@val external assign: (dict<'a>, dict<'a>) => dict<'a> = "Object.assign"
2424

25-
@val external copy: (@as(json`{}`) _, t<'a>) => t<'a> = "Object.assign"
25+
@val external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
2626

2727
let forEach = (dict, f) => {
2828
dict->valuesToArray->Array.forEach(value => f(value))

runtime/Dict.resi

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Compiles to a regular JavaScript object.*/
66
/**
77
Type representing a dictionary of value `'a`.
88
*/
9-
type t<'a> = Js.Dict.t<'a>
9+
type t<'a> = dict<'a>
1010

1111
/**
1212
`getUnsafe(dict, key)` Returns the `value` at the provided `key`.
@@ -23,7 +23,7 @@ Console.log(value) // value1
2323
```
2424
*/
2525
@get_index
26-
external getUnsafe: (t<'a>, string) => 'a = ""
26+
external getUnsafe: (dict<'a>, string) => 'a = ""
2727

2828
/**
2929
Returns the value at the provided key, if it exists. Returns an option.
@@ -39,7 +39,7 @@ switch dict->Dict.get("someKey") {
3939
```
4040
*/
4141
@get_index
42-
external get: (t<'a>, string) => option<'a> = ""
42+
external get: (dict<'a>, string) => option<'a> = ""
4343

4444
/**
4545
`set(dictionary, key, value)` sets the value at the provided key to the provided value.
@@ -52,7 +52,7 @@ dict->Dict.set("someKey", "someValue")
5252
```
5353
*/
5454
@set_index
55-
external set: (t<'a>, string, 'a) => unit = ""
55+
external set: (dict<'a>, string, 'a) => unit = ""
5656

5757
/**
5858
`delete(dictionary, key)` deletes the value at `key`, if it exists.
@@ -64,21 +64,21 @@ let dict = Dict.fromArray([("someKey", "someValue")])
6464
dict->Dict.delete("someKey")
6565
```
6666
*/
67-
let delete: (t<'a>, string) => unit
67+
let delete: (dict<'a>, string) => unit
6868

6969
/**
7070
`make()` creates a new, empty dictionary.
7171
7272
## Examples
7373
```rescript
74-
let dict1: Dict.t<int> = Dict.make() // You can annotate the type of the values of your dict yourself if you want
74+
let dict1: dict<int> = Dict.make() // You can annotate the type of the values of your dict yourself if you want
7575
7676
let dict2 = Dict.make() // Or you can let ReScript infer it via usage.
7777
dict2->Dict.set("someKey", 12)
7878
```
7979
*/
8080
@obj
81-
external make: unit => t<'a> = ""
81+
external make: unit => dict<'a> = ""
8282

8383
/**
8484
`fromArray(entries)` creates a new dictionary from the provided array of key/value pairs.
@@ -89,7 +89,7 @@ let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")])
8989
```
9090
*/
9191
@val
92-
external fromArray: array<(string, 'a)> => t<'a> = "Object.fromEntries"
92+
external fromArray: array<(string, 'a)> => dict<'a> = "Object.fromEntries"
9393

9494
/**
9595
`fromIterator(entries)` creates a new dictionary from the provided iterator of key/value pairs.
@@ -99,11 +99,11 @@ external fromArray: array<(string, 'a)> => t<'a> = "Object.fromEntries"
9999
// Pretend we have an iterator of the correct shape
100100
@val external someIterator: Iterator.t<(string, int)> = "someIterator"
101101
102-
let dict = Dict.fromIterator(someIterator) // Dict.t<int>
102+
let dict = Dict.fromIterator(someIterator) // dict<int>
103103
```
104104
*/
105105
@val
106-
external fromIterator: Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"
106+
external fromIterator: Iterator.t<(string, 'a)> => dict<'a> = "Object.fromEntries"
107107

108108
/**
109109
`toArray(dictionary)` returns an array of all the key/value pairs of the dictionary.
@@ -118,7 +118,7 @@ Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console
118118
```
119119
*/
120120
@val
121-
external toArray: t<'a> => array<(string, 'a)> = "Object.entries"
121+
external toArray: dict<'a> => array<(string, 'a)> = "Object.entries"
122122

123123
/**
124124
`keysToArray(dictionary)` returns an array of all the keys of the dictionary.
@@ -133,7 +133,7 @@ Console.log(keys) // Logs `["someKey", "someKey2"]` to the console
133133
```
134134
*/
135135
@val
136-
external keysToArray: t<'a> => array<string> = "Object.keys"
136+
external keysToArray: dict<'a> => array<string> = "Object.keys"
137137

138138
/**
139139
`valuesToArray(dictionary)` returns an array of all the values of the dictionary.
@@ -148,7 +148,7 @@ Console.log(values) // Logs `[1, 2]` to the console
148148
```
149149
*/
150150
@val
151-
external valuesToArray: t<'a> => array<'a> = "Object.values"
151+
external valuesToArray: dict<'a> => array<'a> = "Object.values"
152152

153153
/**
154154
`assign(dictionary1, dictionary2)` [shallowly](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) merges dictionary2 into dictionary1, and returns dictionary1.
@@ -172,7 +172,7 @@ Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"
172172
```
173173
*/
174174
@val
175-
external assign: (t<'a>, t<'a>) => t<'a> = "Object.assign"
175+
external assign: (dict<'a>, dict<'a>) => dict<'a> = "Object.assign"
176176

177177
/**
178178
`copy(dictionary)` [shallowly copies](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) the provided dictionary to a new dictionary.
@@ -187,7 +187,7 @@ Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray)
187187
```
188188
*/
189189
@val
190-
external copy: (@as(json`{}`) _, t<'a>) => t<'a> = "Object.assign"
190+
external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
191191

192192
/**
193193
`forEach(dictionary, f)` iterates through all values of the dict.
@@ -203,7 +203,7 @@ dict->Dict.forEach(value => {
203203
})
204204
```
205205
*/
206-
let forEach: (t<'a>, 'a => unit) => unit
206+
let forEach: (dict<'a>, 'a => unit) => unit
207207

208208
/**
209209
`forEachWithKey(dictionary, f)` iterates through all values of the dict, including the key for each value.
@@ -217,7 +217,7 @@ dict->Dict.forEachWithKey((value, key) => {
217217
})
218218
```
219219
*/
220-
let forEachWithKey: (t<'a>, ('a, string) => unit) => unit
220+
let forEachWithKey: (dict<'a>, ('a, string) => unit) => unit
221221

222222
/**
223223
`mapValues(dictionary, f)` returns a new dictionary with the same keys, and `f` applied to each value in the original dictionary.
@@ -231,4 +231,4 @@ dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)]
231231
dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")]
232232
```
233233
*/
234-
let mapValues: (t<'a>, 'a => 'b) => t<'b>
234+
let mapValues: (dict<'a>, 'a => 'b) => dict<'b>

runtime/JSON.res

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type rec t = Js.Json.t =
44
| @as(null) Null
55
| String(string)
66
| Number(float)
7-
| Object(Dict.t<t>)
7+
| Object(dict<t>)
88
| Array(array<t>)
99

1010
@unboxed
@@ -47,15 +47,15 @@ module Classify = {
4747
| Null
4848
| String(string)
4949
| Number(float)
50-
| Object(Dict.t<t>)
50+
| Object(dict<t>)
5151
| Array(array<t>)
5252

5353
@val external _internalClass: 'a => string = "Object.prototype.toString.call"
5454
external _asBool: 'a => bool = "%identity"
5555
external _asString: 'a => string = "%identity"
5656
external _asFloat: 'a => float = "%identity"
5757
external _asArray: 'a => array<Js.Json.t> = "%identity"
58-
external _asDict: 'a => Dict.t<Js.Json.t> = "%identity"
58+
external _asDict: 'a => dict<Js.Json.t> = "%identity"
5959

6060
let classify = value => {
6161
switch _internalClass(value) {
@@ -75,7 +75,7 @@ module Encode = {
7575
external string: string => t = "%identity"
7676
external int: int => t = "%identity"
7777
external float: float => t = "%identity"
78-
external object: Dict.t<t> => t = "%identity"
78+
external object: dict<t> => t = "%identity"
7979
external array: array<t> => t = "%identity"
8080
}
8181

@@ -86,7 +86,7 @@ module Decode = {
8686
let float = (json: t) => Type.typeof(json) === #number ? Some((Obj.magic(json): float)) : None
8787
let object = (json: t) =>
8888
if Type.typeof(json) === #object && !Array.isArray(json) && !(Obj.magic(json) === Null.null) {
89-
Some((Obj.magic(json): Dict.t<t>))
89+
Some((Obj.magic(json): dict<t>))
9090
} else {
9191
None
9292
}

runtime/JSON.resi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type rec t = Js.Json.t =
1111
| @as(null) Null
1212
| String(string)
1313
| Number(float)
14-
| Object(Dict.t<t>)
14+
| Object(dict<t>)
1515
| Array(array<t>)
1616

1717
@unboxed
@@ -578,7 +578,7 @@ module Classify: {
578578
| Null
579579
| String(string)
580580
| Number(float)
581-
| Object(Dict.t<t>)
581+
| Object(dict<t>)
582582
| Array(array<t>)
583583

584584
/**
@@ -660,7 +660,7 @@ module Encode: {
660660
JSON.Encode.object(dict)
661661
```
662662
*/
663-
external object: Dict.t<t> => t = "%identity"
663+
external object: dict<t> => t = "%identity"
664664

665665
/**
666666
Returns an array as a JSON object.
@@ -733,7 +733,7 @@ module Decode: {
733733
let float: t => option<float>
734734

735735
/**
736-
Decodes a single JSON value. If the value is an object, it will return `Some(Dict.t)` - otherwise it will return `None`.
736+
Decodes a single JSON value. If the value is an object, it will return `Some(dict)` - otherwise it will return `None`.
737737
738738
## Examples
739739
```rescript
@@ -744,7 +744,7 @@ module Decode: {
744744
// None
745745
```
746746
*/
747-
let object: t => option<Dict.t<t>>
747+
let object: t => option<dict<t>>
748748

749749
/**
750750
Decodes a single JSON value. If the value is an array, it will return `Some(array)` - otherwise it will return `None`.

runtime/Js_json.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ type rec t =
3030
| @as(null) Null
3131
| String(string)
3232
| Number(float)
33-
| Object(Js_dict.t<t>)
33+
| Object(dict<t>)
3434
| Array(array<t>)
3535

3636
module Kind = {
3737
type json = t
3838
type rec t<_> =
3939
| String: t<Js_string.t>
4040
| Number: t<float>
41-
| Object: t<Js_dict.t<json>>
41+
| Object: t<dict<json>>
4242
| Array: t<array<json>>
4343
| Boolean: t<bool>
4444
| Null: t<Js_types.null_val>
@@ -50,7 +50,7 @@ type tagged_t =
5050
| JSONNull
5151
| JSONString(string)
5252
| JSONNumber(float)
53-
| JSONObject(Js_dict.t<t>)
53+
| JSONObject(dict<t>)
5454
| JSONArray(array<t>)
5555

5656
let classify = (x: t): tagged_t => {
@@ -105,7 +105,7 @@ let decodeObject = json =>
105105
(!Js_array2.isArray(json) &&
106106
!((Obj.magic(json): Js_null.t<'a>) === Js_extern.null))
107107
) {
108-
Some((Obj.magic((json: t)): Js_dict.t<t>))
108+
Some((Obj.magic((json: t)): dict<t>))
109109
} else {
110110
None
111111
}
@@ -143,15 +143,15 @@ let decodeNull = (json): option<Js_null.t<_>> =>
143143
external string: string => t = "%identity"
144144
external number: float => t = "%identity"
145145
external boolean: bool => t = "%identity"
146-
external object_: Js_dict.t<t> => t = "%identity"
146+
external object_: dict<t> => t = "%identity"
147147

148148
/* external array_ : t array -> t = "%identity" */
149149

150150
external array: array<t> => t = "%identity"
151151
external stringArray: array<string> => t = "%identity"
152152
external numberArray: array<float> => t = "%identity"
153153
external booleanArray: array<bool> => t = "%identity"
154-
external objectArray: array<Js_dict.t<t>> => t = "%identity"
154+
external objectArray: array<dict<t>> => t = "%identity"
155155
@val @scope("JSON") external stringify: t => string = "stringify"
156156
@val @scope("JSON") external stringifyWithSpace: (t, @as(json`null`) _, int) => string = "stringify"
157157

0 commit comments

Comments
 (0)