Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/stdlib-no-as-json-args.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Pass the constant arguments of `Dict.concat`, `Dict.concatMany`, `Dict.concatAll`, `Dict.copy`, `Object.copy`, `Object.createWithNull` and `Object.createWithNullAndProperties` from `@inline` functions instead of `@as(json)`.
16 changes: 12 additions & 4 deletions packages/@rescript/runtime/Stdlib_Dict.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,22 @@ external fromIterable: Stdlib_Iterable.t<(string, 'a)> => dict<'a> = "Object.fro

@variadic @val external assignMany: (dict<'a>, array<dict<'a>>) => dict<'a> = "Object.assign"

@val external concat: (@as(json`{}`) _, dict<'a>, dict<'a>) => dict<'a> = "Object.assign"
@val external concat: (dict<'a>, dict<'a>, dict<'a>) => dict<'a> = "Object.assign"

@inline
let concat = (dict1, dict2) => concat(make(), dict1, dict2)

@variadic @val
external concatMany: (@as(json`{}`) _, dict<'a>, array<dict<'a>>) => dict<'a> = "Object.assign"
external concatMany: (dict<'a>, dict<'a>, array<dict<'a>>) => dict<'a> = "Object.assign"

@inline
let concatMany = (target, sources) => concatMany(make(), target, sources)

@variadic @val external concatAll: (@as(json`{}`) _, array<dict<'a>>) => dict<'a> = "Object.assign"
@inline
let concatAll = dictionaries => assignMany(make(), dictionaries)

@val external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
@inline
let copy = dictionary => assign(make(), dictionary)

// Use %raw to support for..in which is a ~10% faster than .forEach
let forEach: (dict<'a>, 'a => unit) => unit = %raw(`(dict, f) => {
Expand Down
12 changes: 4 additions & 8 deletions packages/@rescript/runtime/Stdlib_Dict.resi
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ merged == dict{"firstKey": 2, "someKey": 3}
(merged === dict1) == false
```
*/
@val
external concat: (@as(json`{}`) _, dict<'a>, dict<'a>) => dict<'a> = "Object.assign"
let concat: (dict<'a>, dict<'a>) => dict<'a>

/**
`concatMany(target, sources)` [shallowly](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) merges `target` and each dictionary in `sources` into a fresh dictionary, and returns the new dictionary.
Expand All @@ -300,8 +299,7 @@ merged == dict{"firstKey": 1, "someKey": 3, "someKey2": 4}
(merged === target) == false
```
*/
@variadic @val
external concatMany: (@as(json`{}`) _, dict<'a>, array<dict<'a>>) => dict<'a> = "Object.assign"
let concatMany: (dict<'a>, array<dict<'a>>) => dict<'a>

/**
`concatAll(dictionaries)` [shallowly](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) merges all dictionaries in `dictionaries` into a fresh dictionary, and returns the new dictionary.
Expand All @@ -321,8 +319,7 @@ merged == dict{"firstKey": 1, "someKey": 3, "someKey2": 4}
(merged === dict1) == false
```
*/
@variadic @val
external concatAll: (@as(json`{}`) _, array<dict<'a>>) => dict<'a> = "Object.assign"
let concatAll: array<dict<'a>> => dict<'a>

/**
`copy(dictionary)` [shallowly copies](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) the provided dictionary to a new dictionary.
Expand All @@ -336,8 +333,7 @@ let dict2 = dict->Dict.copy
Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray)
```
*/
@val
external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
let copy: dict<'a> => dict<'a>

/**
`forEach(dictionary, f)` iterates through all values of the dict.
Expand Down
18 changes: 15 additions & 3 deletions packages/@rescript/runtime/Stdlib_Object.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ obj->Object.get("kind") == Some("fruit")
*/
@val external createWithProperties: ({..}, {..}) => {..} = "Object.create"

@val external createWithNull: Primitive_js_extern.null<{..}> => {..} = "Object.create"

/**
`createWithNull()` creates an object with a `null` prototype (no inherited properties).

Expand All @@ -85,7 +87,12 @@ let obj = Object.createWithNull()
obj->Object.get("toString") == None
```
*/
@val external createWithNull: (@as(json`null`) _, unit) => {..} = "Object.create"
@inline
let createWithNull = () => createWithNull(Primitive_js_extern.null)

@val
external createWithNullAndProperties: (Primitive_js_extern.null<{..}>, {..}) => {..} =
"Object.create"

/**
`createWithNullAndProperties(descriptors)` creates an object with a `null` prototype and defines properties using descriptor objects.
Expand All @@ -100,7 +107,9 @@ obj->Object.get("name") == Some("banana")
obj->Object.get("toString") == None
```
*/
@val external createWithNullAndProperties: (@as(json`null`) _, {..}) => {..} = "Object.create"
@inline
let createWithNullAndProperties = properties =>
createWithNullAndProperties(Primitive_js_extern.null, properties)

/**
`assign(target, source)` copies enumerable own properties from the source to the target, overwriting properties with the same name. It returns the modified target object. A deep clone is not created; properties are copied by reference.
Expand Down Expand Up @@ -130,6 +139,8 @@ See [Object.assign on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScri
@variadic @val
external assignMany: ({..}, array<{..}>) => {..} = "Object.assign"

@val external copy: ({..}, {..} as 'a) => 'a = "Object.assign"

/**
`copy(object)` creates a shallow copy of `object`.

Expand All @@ -144,7 +155,8 @@ cloned->Object.get("name") == Some("banana")
Object.is(original, cloned) == false
```
*/
@val external copy: (@as(json`{}`) _, {..} as 'a) => 'a = "Object.assign"
@inline
let copy = object => copy(make(), object)

/**
`get` gets the value of a property by name. Returns `None` if the property does not exist or has the value `undefined`. Otherwise returns `Some`, including if the value is `null`.
Expand Down
20 changes: 20 additions & 0 deletions packages/@rescript/runtime/lib/es6/Stdlib_Dict.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ function $$delete$1(dict, string) {
delete(dict[string]);
}

function concat(dict1, dict2) {
return Object.assign({}, dict1, dict2);
}

function concatMany(target, sources) {
return Object.assign({}, target, ...sources);
}

function concatAll(dictionaries) {
return Object.assign({}, ...dictionaries);
}

function copy(dictionary) {
return Object.assign({}, dictionary);
}

let forEach = ((dict, f) => {
for (var i in dict) {
f(dict[i]);
Expand Down Expand Up @@ -44,6 +60,10 @@ export {
$$delete$1 as $$delete,
size,
isEmpty,
concat,
concatMany,
concatAll,
copy,
forEach,
forEachWithKey,
mapValues,
Expand Down
22 changes: 21 additions & 1 deletion packages/@rescript/runtime/lib/es6/Stdlib_Object.mjs
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */



function createWithNull() {
return Object.create(null);
}

function createWithNullAndProperties(properties) {
return Object.create(null, properties);
}

function copy(object) {
return Object.assign({}, object);
}

export {
createWithNull,
createWithNullAndProperties,
copy,
}
/* No side effect */
20 changes: 20 additions & 0 deletions packages/@rescript/runtime/lib/js/Stdlib_Dict.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ function $$delete$1(dict, string) {
delete(dict[string]);
}

function concat(dict1, dict2) {
return Object.assign({}, dict1, dict2);
}

function concatMany(target, sources) {
return Object.assign({}, target, ...sources);
}

function concatAll(dictionaries) {
return Object.assign({}, ...dictionaries);
}

function copy(dictionary) {
return Object.assign({}, dictionary);
}

let forEach = ((dict, f) => {
for (var i in dict) {
f(dict[i]);
Expand Down Expand Up @@ -43,6 +59,10 @@ let isEmpty = ((dict) => {
exports.$$delete = $$delete$1;
exports.size = size;
exports.isEmpty = isEmpty;
exports.concat = concat;
exports.concatMany = concatMany;
exports.concatAll = concatAll;
exports.copy = copy;
exports.forEach = forEach;
exports.forEachWithKey = forEachWithKey;
exports.mapValues = mapValues;
Expand Down
20 changes: 19 additions & 1 deletion packages/@rescript/runtime/lib/js/Stdlib_Object.cjs
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
'use strict';


function createWithNull() {
return Object.create(null);
}

function createWithNullAndProperties(properties) {
return Object.create(null, properties);
}

function copy(object) {
return Object.assign({}, object);
}

exports.createWithNull = createWithNull;
exports.createWithNullAndProperties = createWithNullAndProperties;
exports.copy = copy;
/* No side effect */
Loading