Skip to content

Commit ee454c6

Browse files
committed
second approach to inlining dicts
1 parent db30a51 commit ee454c6

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

jscomp/others/js_dict.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
/** The dict type */
2828
type t<'a> = dict<'a>
2929

30+
external _unsafe_create: array<(string, 'a)> => dict<'a> = "?createDict"
31+
3032
/** The key type, an alias of string */
3133
type key = string
3234

jscomp/others/js_dict.resi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ mostly used with the Js_json.t type.
4141
*/
4242
type t<'a> = dict<'a>
4343

44+
external _unsafe_create: array<(string, 'a)> => dict<'a> = "?createDict"
45+
4446
/**
4547
The type for dictionary keys. This means that dictionaries *must* use `string`s as their keys.
4648
*/

jscomp/test/DictTests.js

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

jscomp/test/DictTests.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ let dictCreationCanBeInlined = Js.Dict.fromArray([
77
external imaginaryExternalArgs: array<(string, string)> = "imaginary"
88

99
let dictCreationCanNotBeInlined = Js.Dict.fromArray(imaginaryExternalArgs)
10+
11+
let dictCreationCanBeInlined2 = Js.Dict._unsafe_create([
12+
("name", "hello"),
13+
("age", "what"),
14+
("more", "stuff"),
15+
])

0 commit comments

Comments
 (0)