diff --git a/changes/stdlib-inline-helpers.feature.md b/changes/stdlib-inline-helpers.feature.md new file mode 100644 index 0000000000..a41a90d029 --- /dev/null +++ b/changes/stdlib-inline-helpers.feature.md @@ -0,0 +1 @@ +- Mark small stdlib functions `@inline`, so calls to them compile to the code they run: argument-reordering wrappers such as `Array.reduce` (which now compiles to `array.reduce(f, init)`), `Promise.catch` and the iterator and generator `next` functions; the `Null`, `Nullable` and `Result` combinators such as `map` and `getOr`; the `…Opt` lookups of `Array` and `String`; and predicates such as `isEmpty`. diff --git a/changes/stdlib-int-constants.breaking.md b/changes/stdlib-int-constants.breaking.md new file mode 100644 index 0000000000..d322765c78 --- /dev/null +++ b/changes/stdlib-int-constants.breaking.md @@ -0,0 +1 @@ +- `Int.Constants.minValue` and `maxValue` are now `@inline` constants, so ReScript code using them gets the number itself. JavaScript code that reads them from the runtime's `Stdlib_Int` module gets `undefined`. diff --git a/packages/@rescript/runtime/Dom_storage.res b/packages/@rescript/runtime/Dom_storage.res index 7f1f0bcd3e..bae706d7e7 100644 --- a/packages/@rescript/runtime/Dom_storage.res +++ b/packages/@rescript/runtime/Dom_storage.res @@ -1,21 +1,33 @@ type t = Dom_storage2.t @send @return(null_to_opt) external getItem: (t, string) => option = "getItem" + +@inline let getItem = (s, obj) => obj->getItem(s) + /* https://developer.mozilla.org/en-US/docs/Web/API/Storage/getItem If the key does not exist, `null` is returned */ @send external setItem: (t, string, string) => unit = "setItem" + +@inline let setItem = (k, v, obj): unit => obj->setItem(k, v) + @send external removeItem: (t, string) => unit = "removeItem" + +@inline let removeItem = (s, obj): unit => obj->removeItem(s) + @send external clear: t => unit = "clear" @send @return(null_to_opt) external key: (t, int) => option = "key" + /* A DOMString containing the name of the key. If the index does not exist, null is returned. If the key does not exist, `null` is returned */ +@inline let key = (i, obj): option => obj->key(i) + @get external length: t => int = "length" @val external localStorage: t = "localStorage" diff --git a/packages/@rescript/runtime/Stdlib_Array.res b/packages/@rescript/runtime/Stdlib_Array.res index c367881158..9d3ace40f0 100644 --- a/packages/@rescript/runtime/Stdlib_Array.res +++ b/packages/@rescript/runtime/Stdlib_Array.res @@ -44,6 +44,7 @@ let fromInitializer = (~length, f) => external length: array<'a> => int = "%array_length" +@inline let isEmpty = arr => arr->length === 0 let rec equalFromIndex = (a, b, i, eq, len) => @@ -118,6 +119,8 @@ external removeInPlace: (array<'a>, int, @as(1) _) => unit = "splice" @send external concat: (array<'a>, array<'a>) => array<'a> = "concat" @variadic @send external concatMany: (array<'a>, array>) => array<'a> = "concat" + +@inline let concatAll = arrays => concatMany([], arrays) @send external flat: array> => array<'a> = "flat" @@ -126,6 +129,7 @@ let concatAll = arrays => concatMany([], arrays) @send external indexOf: (array<'a>, 'a, ~from: int=?) => int = "indexOf" +@inline let indexOfOpt = (arr, item) => switch arr->indexOf(item) { | -1 => None @@ -138,6 +142,7 @@ let indexOfOpt = (arr, item) => @send external lastIndexOf: (array<'a>, 'a, ~from: int=?) => int = "lastIndexOf" +@inline let lastIndexOfOpt = (arr, item) => switch arr->lastIndexOf(item) { | -1 => None @@ -179,18 +184,25 @@ let lastIndexOfOpt = (arr, item) => @send external mapWithIndex: (array<'a>, ('a, int) => 'b) => array<'b> = "map" @send external reduce: (array<'b>, ('a, 'b) => 'a, 'a) => 'a = "reduce" + +@inline let reduce = (arr, init, f) => reduce(arr, f, init) + @send external reduceWithIndex: (array<'b>, ('a, 'b, int) => 'a, 'a) => 'a = "reduce" + +@inline let reduceWithIndex = (arr, init, f) => reduceWithIndex(arr, f, init) @send external reduceRight: (array<'b>, ('a, 'b) => 'a, 'a) => 'a = "reduceRight" +@inline let reduceRight = (arr, init, f) => reduceRight(arr, f, init) @send external reduceRightWithIndex: (array<'b>, ('a, 'b, int) => 'a, 'a) => 'a = "reduceRight" +@inline let reduceRightWithIndex = (arr, init, f) => reduceRightWithIndex(arr, f, init) @send external some: (array<'a>, 'a => bool) => bool = "some" @@ -203,12 +215,14 @@ let reduceRightWithIndex = (arr, init, f) => reduceRightWithIndex(arr, f, init) @get_index external getSymbolUnsafe: (array<'a>, Stdlib_Symbol.t) => 'b = "" @set_index external setSymbol: (array<'a>, Stdlib_Symbol.t, 'b) => unit = "" +@inline let findIndexOpt = (array: array<'a>, finder: 'a => bool): option => switch findIndex(array, finder) { | -1 => None | index => Some(index) } +@inline let findLastIndexOpt = (array: array<'a>, finder: 'a => bool): option => switch findLastIndex(array, finder) { | -1 => None @@ -352,6 +366,7 @@ let unzip = a => { @send external at: (array<'a>, int) => option<'a> = "at" +@inline let last = a => a->get(a->length - 1) external ignore: array<'a> => unit = "%ignore" diff --git a/packages/@rescript/runtime/Stdlib_AsyncGenerator.res b/packages/@rescript/runtime/Stdlib_AsyncGenerator.res index 6e1e6be10d..4598158a9f 100644 --- a/packages/@rescript/runtime/Stdlib_AsyncGenerator.res +++ b/packages/@rescript/runtime/Stdlib_AsyncGenerator.res @@ -14,8 +14,10 @@ external asAsyncIterator: t<'yield, 'return, 'next> => Stdlib_AsyncIterator.t< 'next, > = "%identity" +@inline let next = generator => generator->asAsyncIterator->Stdlib_AsyncIterator.next +@inline let nextValue = (generator, value) => generator->asAsyncIterator->Stdlib_AsyncIterator.nextValue(value) diff --git a/packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res b/packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res index 029452cc47..44d00725f9 100644 --- a/packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res +++ b/packages/@rescript/runtime/Stdlib_AsyncIterableIterator.res @@ -21,8 +21,10 @@ external asAsyncIterator: t<'yield, 'return, 'next> => Stdlib_AsyncIterator.t< 'next, > = "%identity" +@inline let next = iterator => iterator->asAsyncIterator->Stdlib_AsyncIterator.next +@inline let nextValue = (iterator, value) => iterator->asAsyncIterator->Stdlib_AsyncIterator.nextValue(value) diff --git a/packages/@rescript/runtime/Stdlib_BigInt.res b/packages/@rescript/runtime/Stdlib_BigInt.res index 5c0b7737e6..9d821c7b33 100644 --- a/packages/@rescript/runtime/Stdlib_BigInt.res +++ b/packages/@rescript/runtime/Stdlib_BigInt.res @@ -31,6 +31,7 @@ external toLocaleString: bigint => string = "toLocaleString" @val external toFloat: bigint => float = "Number" +@inline let toInt = t => t->toFloat->Stdlib_Int.fromFloat external add: (bigint, bigint) => bigint = "%addbigint" diff --git a/packages/@rescript/runtime/Stdlib_Bool.res b/packages/@rescript/runtime/Stdlib_Bool.res index 69d2743031..68bb47e9a5 100644 --- a/packages/@rescript/runtime/Stdlib_Bool.res +++ b/packages/@rescript/runtime/Stdlib_Bool.res @@ -1,5 +1,6 @@ type t = bool +@inline let toString = b => if b { "true" diff --git a/packages/@rescript/runtime/Stdlib_Date.res b/packages/@rescript/runtime/Stdlib_Date.res index 152d06267d..b7cb3c33de 100644 --- a/packages/@rescript/runtime/Stdlib_Date.res +++ b/packages/@rescript/runtime/Stdlib_Date.res @@ -94,8 +94,10 @@ module UTC = { @send external getTime: t => msSinceEpoch = "getTime" @send external getTimezoneOffset: t => int = "getTimezoneOffset" +@inline let equal = (a, b) => a->getTime === b->getTime +@inline let compare = (a, b) => Stdlib_Float.compare(a->getTime, b->getTime) // Locale diff --git a/packages/@rescript/runtime/Stdlib_Dict.res b/packages/@rescript/runtime/Stdlib_Dict.res index ad2f3e77ef..0383829759 100644 --- a/packages/@rescript/runtime/Stdlib_Dict.res +++ b/packages/@rescript/runtime/Stdlib_Dict.res @@ -5,6 +5,7 @@ type t<'a> = dict<'a> @set_index external set: (dict<'a>, string, 'a) => unit = "" @val external delete: 'a => unit = "delete" +@inline let delete = (dict, string) => { delete(get(dict, string)) } diff --git a/packages/@rescript/runtime/Stdlib_Generator.res b/packages/@rescript/runtime/Stdlib_Generator.res index e813261ff1..be457794d6 100644 --- a/packages/@rescript/runtime/Stdlib_Generator.res +++ b/packages/@rescript/runtime/Stdlib_Generator.res @@ -11,8 +11,10 @@ external asIteratorObject: t<'yield, 'return, 'next> => Stdlib_IteratorObject.t< 'next, > = "%identity" +@inline let next = generator => generator->asIterator->Stdlib_Iterator.next +@inline let nextValue = (generator, value) => generator->asIterator->Stdlib_Iterator.nextValue(value) @send @@ -21,6 +23,7 @@ external returnValueRaw: ( 'return, ) => Stdlib_Iterator.rawResult<'yield, 'return> = "return" +@inline let returnValue = (generator, value) => generator->returnValueRaw(value)->Stdlib_Iterator.normalizeResult @@ -30,5 +33,6 @@ external throwErrorRaw: ( exn, ) => Stdlib_Iterator.rawResult<'yield, 'return> = "throw" +@inline let throwError = (generator, error) => generator->throwErrorRaw(error)->Stdlib_Iterator.normalizeResult diff --git a/packages/@rescript/runtime/Stdlib_Int.resi b/packages/@rescript/runtime/Stdlib_Int.resi index 0cb467ad79..6caf308f08 100644 --- a/packages/@rescript/runtime/Stdlib_Int.resi +++ b/packages/@rescript/runtime/Stdlib_Int.resi @@ -26,6 +26,7 @@ on MDN. Console.log(Int.Constants.minValue) ``` */ + @inline(-2147483648) let minValue: int /** @@ -39,6 +40,7 @@ on MDN. Console.log(Int.Constants.maxValue) ``` */ + @inline(2147483647) let maxValue: int } diff --git a/packages/@rescript/runtime/Stdlib_IterableIterator.res b/packages/@rescript/runtime/Stdlib_IterableIterator.res index b672e5dfee..86e3bdbc54 100644 --- a/packages/@rescript/runtime/Stdlib_IterableIterator.res +++ b/packages/@rescript/runtime/Stdlib_IterableIterator.res @@ -18,8 +18,10 @@ external asIterator: t<'yield, 'return, 'next> => Stdlib_Iterator.t<'yield, 'ret external asIterable: t<'yield, 'return, 'next> => Stdlib_Iterable.t<'yield> = "%identity" +@inline let next = iterator => iterator->asIterator->Stdlib_Iterator.next +@inline let nextValue = (iterator, value) => iterator->asIterator->Stdlib_Iterator.nextValue(value) @val diff --git a/packages/@rescript/runtime/Stdlib_IteratorObject.res b/packages/@rescript/runtime/Stdlib_IteratorObject.res index 5f85472312..db91ac34d7 100644 --- a/packages/@rescript/runtime/Stdlib_IteratorObject.res +++ b/packages/@rescript/runtime/Stdlib_IteratorObject.res @@ -7,8 +7,10 @@ external asIterator: t<'yield, 'return, 'next> => Stdlib_Iterator.t<'yield, 'ret external asIterable: t<'yield, 'return, 'next> => Stdlib_Iterable.t<'yield> = "%identity" +@inline let next = iteratorObject => iteratorObject->asIterator->Stdlib_Iterator.next +@inline let nextValue = (iteratorObject, value) => iteratorObject->asIterator->Stdlib_Iterator.nextValue(value) diff --git a/packages/@rescript/runtime/Stdlib_List.res b/packages/@rescript/runtime/Stdlib_List.res index b96cb9136e..26cf4794de 100644 --- a/packages/@rescript/runtime/Stdlib_List.res +++ b/packages/@rescript/runtime/Stdlib_List.res @@ -82,6 +82,7 @@ external mutableCell: ('a, list<'a>) => list<'a> = "#makemutablelist" - the cell is not empty */ +@inline let head = x => switch x { | list{} => None @@ -94,6 +95,7 @@ let headOrThrow = x => | list{x, ..._} => x } +@inline let tail = x => switch x { | list{} => None @@ -106,6 +108,7 @@ let tailOrThrow = x => | list{_, ...t} => t } +@inline let add = (xs, x) => list{x, ...xs} /* Assume `n >=0` */ diff --git a/packages/@rescript/runtime/Stdlib_Map.res b/packages/@rescript/runtime/Stdlib_Map.res index 6b41f11b74..3f7916fd55 100644 --- a/packages/@rescript/runtime/Stdlib_Map.res +++ b/packages/@rescript/runtime/Stdlib_Map.res @@ -11,6 +11,7 @@ external fromIterable: Stdlib_Iterable.t<('k, 'v)> => t<'k, 'v> = "Map" @get external size: t<'k, 'v> => int = "size" +@inline let isEmpty = map => map->size === 0 @send external clear: t<'k, 'v> => unit = "clear" diff --git a/packages/@rescript/runtime/Stdlib_Null.res b/packages/@rescript/runtime/Stdlib_Null.res index cc9ee2f8a9..97acb236ae 100644 --- a/packages/@rescript/runtime/Stdlib_Null.res +++ b/packages/@rescript/runtime/Stdlib_Null.res @@ -11,6 +11,7 @@ external make: 'a => t<'a> = "%identity" external toOption: t<'a> => option<'a> = "#null_to_opt" +@inline let fromOption: option<'a> => t<'a> = option => switch option { | Some(x) => make(x) @@ -21,6 +22,7 @@ let equal = (a, b, eq) => Stdlib_Option.equal(a->toOption, b->toOption, eq) let compare = (a, b, cmp) => Stdlib_Option.compare(a->toOption, b->toOption, cmp) +@inline let getOr = (value, default) => switch value->toOption { | Some(x) => x @@ -35,24 +37,28 @@ let getOrThrow: t<'a> => 'a = value => external getUnsafe: t<'a> => 'a = "%identity" +@inline let forEach = (value, f) => switch value->toOption { | Some(x) => f(x) | None => () } +@inline let map = (value, f) => switch value->toOption { | Some(x) => make(f(x)) | None => null } +@inline let mapOr = (value, default, f) => switch value->toOption { | Some(x) => f(x) | None => default } +@inline let flatMap = (value, f) => switch value->toOption { | Some(x) => f(x) diff --git a/packages/@rescript/runtime/Stdlib_Nullable.res b/packages/@rescript/runtime/Stdlib_Nullable.res index 5bad47140e..cf6f66cca7 100644 --- a/packages/@rescript/runtime/Stdlib_Nullable.res +++ b/packages/@rescript/runtime/Stdlib_Nullable.res @@ -14,6 +14,7 @@ external make: 'a => t<'a> = "%identity" external toOption: t<'a> => option<'a> = "#nullable_to_opt" +@inline let fromOption: option<'a> => t<'a> = option => switch option { | Some(x) => make(x) @@ -24,6 +25,7 @@ let equal = (a, b, eq) => Stdlib_Option.equal(a->toOption, b->toOption, eq) let compare = (a, b, cmp) => Stdlib_Option.compare(a->toOption, b->toOption, cmp) +@inline let getOr = (value, default) => switch value->toOption { | Some(x) => x @@ -38,24 +40,28 @@ let getOrThrow: t<'a> => 'a = value => external getUnsafe: t<'a> => 'a = "%identity" +@inline let forEach = (value, f) => switch value->toOption { | Some(x) => f(x) | None => () } +@inline let map = (value, f) => switch value->toOption { | Some(x) => make(f(x)) | None => Obj.magic(value) } +@inline let mapOr = (value, default, f) => switch value->toOption { | Some(x) => f(x) | None => default } +@inline let flatMap = (value, f) => switch value->toOption { | Some(x) => f(x) diff --git a/packages/@rescript/runtime/Stdlib_Ordering.res b/packages/@rescript/runtime/Stdlib_Ordering.res index f1755b3dc9..7ac5ae6beb 100644 --- a/packages/@rescript/runtime/Stdlib_Ordering.res +++ b/packages/@rescript/runtime/Stdlib_Ordering.res @@ -46,6 +46,7 @@ Ordering.isLess(Ordering.less) == true Ordering.isLess(Ordering.equal) == false ``` */ +@inline let isLess = ord => ord < equal /** @@ -58,6 +59,7 @@ Ordering.isEqual(Ordering.equal) == true Ordering.isEqual(Ordering.greater) == false ``` */ +@inline let isEqual = ord => ord == equal /** @@ -70,6 +72,7 @@ Ordering.isGreater(Ordering.greater) == true Ordering.isGreater(Ordering.less) == false ``` */ +@inline let isGreater = ord => ord > equal /** @@ -82,6 +85,7 @@ Ordering.invert(Ordering.less) == Ordering.greater Ordering.invert(Ordering.equal) == Ordering.equal ``` */ +@inline let invert = ord => -.ord /** @@ -95,6 +99,7 @@ Ordering.fromInt(0) == Ordering.equal Ordering.fromInt(3) == Ordering.greater ``` */ +@inline let fromInt = n => n < 0 ? less : n > 0 ? greater : equal /** diff --git a/packages/@rescript/runtime/Stdlib_Pair.res b/packages/@rescript/runtime/Stdlib_Pair.res index e579a83aaa..42938894f4 100644 --- a/packages/@rescript/runtime/Stdlib_Pair.res +++ b/packages/@rescript/runtime/Stdlib_Pair.res @@ -46,6 +46,7 @@ Pair.equal((1, "test"), (1, "test"), Int.equal, String.equal) == true Pair.equal((1, "test"), (2, "test"), Int.equal, String.equal) == false ``` */ +@inline let equal = ((a1, a2), (b1, b2), eq1, eq2) => eq1(a1, b1) && eq2(a2, b2) /** @@ -61,6 +62,7 @@ Pair.compare((1, "a"), (1, "b"), Int.compare, String.compare) == Ordering.less Pair.compare((2, "a"), (1, "b"), Int.compare, String.compare) == Ordering.greater ``` */ +@inline let compare = ((a1, a2), (b1, b2), cmp1, cmp2) => switch cmp1(a1, b1) { | 0. => cmp2(a2, b2) diff --git a/packages/@rescript/runtime/Stdlib_Promise.res b/packages/@rescript/runtime/Stdlib_Promise.res index be97e54ed4..47d9602450 100644 --- a/packages/@rescript/runtime/Stdlib_Promise.res +++ b/packages/@rescript/runtime/Stdlib_Promise.res @@ -97,6 +97,7 @@ external allSettled6: ( @send external _catch: (t<'a>, unknown => t<'a>) => t<'a> = "catch" +@inline let catch = (promise: promise<'a>, callback: exn => promise<'a>): promise<'a> => { _catch(promise, err => { callback(Primitive_exceptions.internalToException(err)) diff --git a/packages/@rescript/runtime/Stdlib_Result.res b/packages/@rescript/runtime/Stdlib_Result.res index 7df0f43a91..7b802faaf1 100644 --- a/packages/@rescript/runtime/Stdlib_Result.res +++ b/packages/@rescript/runtime/Stdlib_Result.res @@ -17,42 +17,49 @@ let getOrThrow = (x, ~message=?) => ) } +@inline let mapOr = (opt, default, f) => switch opt { | Ok(x) => f(x) | Error(_) => default } +@inline let map = (opt, f) => switch opt { | Ok(x) => Ok(f(x)) | Error(_) as result => result } +@inline let flatMap = (opt, f) => switch opt { | Ok(x) => f(x) | Error(_) as result => result } +@inline let getOr = (opt, default) => switch opt { | Ok(x) => x | Error(_) => default } +@inline let isOk = x => switch x { | Ok(_) => true | Error(_) => false } +@inline let isError = x => switch x { | Ok(_) => false | Error(_) => true } +@inline let equal = (a, b, eqOk, eqError) => switch (a, b) { | (Ok(a), Ok(b)) => eqOk(a, b) @@ -61,6 +68,7 @@ let equal = (a, b, eqOk, eqError) => | (Error(a), Error(b)) => eqError(a, b) } +@inline let compare = (a, b, cmpOk, cmpError) => switch (a, b) { | (Ok(a), Ok(b)) => cmpOk(a, b) @@ -69,12 +77,14 @@ let compare = (a, b, cmpOk, cmpError) => | (Error(a), Error(b)) => cmpError(a, b) } +@inline let forEach = (r, f) => switch r { | Ok(ok) => f(ok) | Error(_) => () } +@inline let mapError = (r, f) => switch r { | Ok(_) as result => result diff --git a/packages/@rescript/runtime/Stdlib_Set.res b/packages/@rescript/runtime/Stdlib_Set.res index 968900ae36..74ca7e2e8a 100644 --- a/packages/@rescript/runtime/Stdlib_Set.res +++ b/packages/@rescript/runtime/Stdlib_Set.res @@ -9,6 +9,7 @@ external asIterable: t<'a> => Stdlib_Iterable.t<'a> = "%identity" @get external size: t<'a> => int = "size" +@inline let isEmpty = set => set->size === 0 @send external clear: t<'a> => unit = "clear" diff --git a/packages/@rescript/runtime/Stdlib_String.res b/packages/@rescript/runtime/Stdlib_String.res index f423b19eca..5a87fbdc31 100644 --- a/packages/@rescript/runtime/Stdlib_String.res +++ b/packages/@rescript/runtime/Stdlib_String.res @@ -22,6 +22,7 @@ external compare: (string, string) => Stdlib_Ordering.t = "%compare" @val @scope("Number") external isNaN: float => bool = "isNaN" @send external charCodeAt: (string, int) => float = "charCodeAt" +@inline let charCodeAt = (s, i) => { let c = charCodeAt(s, i) isNaN(c) ? None : Some(c->Stdlib_Int.fromFloat) @@ -40,6 +41,7 @@ let charCodeAt = (s, i) => { @send external indexOf: (string, string) => int = "indexOf" +@inline let indexOfOpt = (s, search) => switch indexOf(s, search) { | -1 => None @@ -50,6 +52,7 @@ let indexOfOpt = (s, search) => @send external lastIndexOf: (string, string) => int = "lastIndexOf" +@inline let lastIndexOfOpt = (s, search) => switch lastIndexOf(s, search) { | -1 => None @@ -109,6 +112,7 @@ external replaceRegExpBy3Unsafe: ( @send external search: (string, Stdlib_RegExp.t) => int = "search" +@inline let searchOpt = (s, re) => switch search(s, re) { | -1 => None @@ -150,6 +154,7 @@ external localeCompare: ( ~options: Stdlib_Intl_Collator.options=?, ) => float = "localeCompare" +@inline let isEmpty = s => length(s) == 0 let capitalize = s => diff --git a/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs b/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs index 60d4f1c5cd..d9a813a0c9 100644 --- a/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs +++ b/packages/@rescript/runtime/lib/es6/Stdlib_Int.mjs @@ -3,6 +3,8 @@ import * as Stdlib_Array from "./Stdlib_Array.mjs"; import * as Stdlib_Float from "./Stdlib_Float.mjs"; +let Constants = {}; + function fromString(str) { let num = Stdlib_Float.fromString(str); if (num !== undefined) { @@ -63,11 +65,6 @@ function clamp(min, max, value) { } } -let Constants = { - minValue: -2147483648, - maxValue: 2147483647 -}; - export { Constants, fromString, diff --git a/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs b/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs index a2ae31511c..02ec66cf8e 100644 --- a/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs +++ b/packages/@rescript/runtime/lib/js/Stdlib_Int.cjs @@ -3,6 +3,8 @@ let Stdlib_Array = require("./Stdlib_Array.cjs"); let Stdlib_Float = require("./Stdlib_Float.cjs"); +let Constants = {}; + function fromString(str) { let num = Stdlib_Float.fromString(str); if (num !== undefined) { @@ -63,11 +65,6 @@ function clamp(min, max, value) { } } -let Constants = { - minValue: -2147483648, - maxValue: 2147483647 -}; - exports.Constants = Constants; exports.fromString = fromString; exports.range = range; diff --git a/tests/belt_tests/src/bs_array_test.mjs b/tests/belt_tests/src/bs_array_test.mjs index 0bd723dc88..2e7ab8e886 100644 --- a/tests/belt_tests/src/bs_array_test.mjs +++ b/tests/belt_tests/src/bs_array_test.mjs @@ -4,7 +4,6 @@ import * as Mocha from "mocha"; import * as Belt_List from "@rescript/belt/src/Belt_List.mjs"; import * as Belt_Array from "@rescript/belt/src/Belt_Array.mjs"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.mjs"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; @@ -12,12 +11,12 @@ function push(prim0, prim1) { prim0.push(prim1); } -console.log(Stdlib_Array.reduce([ +console.log([ 1, 2, 3, 4 -].filter(x => x > 2).map((x, i) => x + i | 0), 0, (x, y) => x + y | 0)); +].filter(x => x > 2).map((x, i) => x + i | 0).reduce((x, y) => x + y | 0, 0)); Mocha.describe("Bs_array_test", () => { Mocha.test("bs_array_test_1", () => { diff --git a/tests/tests/src/SafePromises.mjs b/tests/tests/src/SafePromises.mjs index 879adff567..0ae93b3f98 100644 --- a/tests/tests/src/SafePromises.mjs +++ b/tests/tests/src/SafePromises.mjs @@ -1,11 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; async function nestedPromise(xxx) { let xx = await xxx; xx.then(x => Promise.resolve((console.log("Promise2.then", x), undefined))); - Stdlib_Promise.$$catch(xx, x => { + xx.catch(err => { + let x = Primitive_exceptions.internalToException(err); console.log("Promise2.catch_", x); return Promise.resolve(0); }); diff --git a/tests/tests/src/bs_auto_uncurry_test.mjs b/tests/tests/src/bs_auto_uncurry_test.mjs index c7e320a10d..de99c603f0 100644 --- a/tests/tests/src/bs_auto_uncurry_test.mjs +++ b/tests/tests/src/bs_auto_uncurry_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; function hi (cb){ cb (); @@ -40,16 +39,16 @@ Mocha.describe("Bs_auto_uncurry_test", () => { 3, 4 ]); - Test_utils.eq("File \"bs_auto_uncurry_test.res\", line 26, characters 7-14", Stdlib_Array.reduce([ + Test_utils.eq("File \"bs_auto_uncurry_test.res\", line 26, characters 7-14", [ 1, 2, 3 - ], 0, (x, y) => x + y | 0), 6); - Test_utils.eq("File \"bs_auto_uncurry_test.res\", line 27, characters 7-14", Stdlib_Array.reduceWithIndex([ + ].reduce((x, y) => x + y | 0, 0), 6); + Test_utils.eq("File \"bs_auto_uncurry_test.res\", line 27, characters 7-14", [ 1, 2, 3 - ], 0, (x, y, i) => (x + y | 0) + i | 0), 9); + ].reduce((x, y, i) => (x + y | 0) + i | 0, 0), 9); Test_utils.eq("File \"bs_auto_uncurry_test.res\", line 28, characters 7-14", [ 1, 2, diff --git a/tests/tests/src/bs_string_test.mjs b/tests/tests/src/bs_string_test.mjs index d73847ddd0..a4f1d0d1d5 100644 --- a/tests/tests/src/bs_string_test.mjs +++ b/tests/tests/src/bs_string_test.mjs @@ -2,10 +2,9 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; Mocha.describe("Bs_string_test", () => { - Mocha.test("string split and reduce", () => Test_utils.eq("File \"bs_string_test.res\", line 7, characters 6-13", Stdlib_Array.reduce("ghso ghso g".split(" "), "", (x, y) => x + ("-" + y)), "-ghso-ghso-g")); + Mocha.test("string split and reduce", () => Test_utils.eq("File \"bs_string_test.res\", line 7, characters 6-13", "ghso ghso g".split(" ").reduce((x, y) => x + ("-" + y), ""), "-ghso-ghso-g")); }); /* Not a pure module */ diff --git a/tests/tests/src/dict_array_spread_order_test.mjs b/tests/tests/src/dict_array_spread_order_test.mjs index 88844e72c2..e0e560faa3 100644 --- a/tests/tests/src/dict_array_spread_order_test.mjs +++ b/tests/tests/src/dict_array_spread_order_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.mjs"; import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.mjs"; function id(x) { @@ -466,7 +465,7 @@ Mocha.describe("Dict_array_spread_order_test", () => { a: 1 }; let dict$1 = dictLaterSpread(base, () => { - Stdlib_Dict.$$delete(base, "a"); + delete(base["a"]); return { c: 3 }; diff --git a/tests/tests/src/earger_curry_test.mjs b/tests/tests/src/earger_curry_test.mjs index 20922b5982..752d1df3d6 100644 --- a/tests/tests/src/earger_curry_test.mjs +++ b/tests/tests/src/earger_curry_test.mjs @@ -48,7 +48,7 @@ function fold_left(f, x, a) { function f2() { let arr = init(30000000, i => i); let b = arr.map(i => i + i - 1); - let v = Stdlib_Array.reduceRight(b, 0, (prim0, prim1) => prim0 + prim1); + let v = b.reduceRight((prim0, prim1) => prim0 + prim1, 0); console.log(v.toString()); } diff --git a/tests/tests/src/hello_res.mjs b/tests/tests/src/hello_res.mjs index 456027a0c6..803440b662 100644 --- a/tests/tests/src/hello_res.mjs +++ b/tests/tests/src/hello_res.mjs @@ -8,9 +8,9 @@ let a = b - 1 | 0; console.log("hello, res"); -Stdlib_List.add(/* [] */0, Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}})); +Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}); -Stdlib_List.add(/* [] */0, Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}})); +Stdlib_List.length({hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}); console.log(3); diff --git a/tests/tests/src/inline_for_start_test.mjs b/tests/tests/src/inline_for_start_test.mjs index 035cf94599..1d7afe40ee 100644 --- a/tests/tests/src/inline_for_start_test.mjs +++ b/tests/tests/src/inline_for_start_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; function fromBlock(x) { let acc = 0; @@ -15,7 +14,7 @@ function fromBlock(x) { function fromCallback(xs, x) { let acc = 0; - for (let i = Stdlib_Array.reduce(xs, 0, (a, b) => a + b | 0); i <= x; ++i) { + for (let i = xs.reduce((a, b) => a + b | 0, 0); i <= x; ++i) { acc = acc + i | 0; } return acc; diff --git a/tests/tests/src/key_word_property_plus_test.mjs b/tests/tests/src/key_word_property_plus_test.mjs index 561e16339c..b763fe8bf2 100644 --- a/tests/tests/src/key_word_property_plus_test.mjs +++ b/tests/tests/src/key_word_property_plus_test.mjs @@ -2,16 +2,15 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as Ident_mangles from "./ident_mangles.mjs"; Mocha.describe("Key_word_property_plus_test", () => { - Mocha.test("keyword property plus with reduce", () => Test_utils.eq("File \"key_word_property_plus_test.res\", line 7, characters 6-13", Stdlib_Array.reduce([ + Mocha.test("keyword property plus with reduce", () => Test_utils.eq("File \"key_word_property_plus_test.res\", line 7, characters 6-13", [ 1, 2, 3, 4 - ], 0, (x, y) => x + y | 0), ((Ident_mangles.$$__dirname + Ident_mangles.$$__filename | 0) + Ident_mangles.$$exports | 0) + Ident_mangles.$$require | 0)); + ].reduce((x, y) => x + y | 0, 0), ((Ident_mangles.$$__dirname + Ident_mangles.$$__filename | 0) + Ident_mangles.$$exports | 0) + Ident_mangles.$$require | 0)); }); /* Not a pure module */ diff --git a/tests/tests/src/limits_test.mjs b/tests/tests/src/limits_test.mjs index 4bad0bfded..b9f3c863bd 100644 --- a/tests/tests/src/limits_test.mjs +++ b/tests/tests/src/limits_test.mjs @@ -1,12 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Mocha from "mocha"; -import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.mjs"; import * as Test_utils from "./test_utils.mjs"; Mocha.describe("Limits_test", () => { - Mocha.test("max_int", () => Test_utils.eq("File \"limits_test.res\", line 5, characters 27-34", Stdlib_Int.Constants.maxValue, 2147483647)); - Mocha.test("min_int", () => Test_utils.eq("File \"limits_test.res\", line 6, characters 27-34", Stdlib_Int.Constants.minValue, -2147483648)); + Mocha.test("max_int", () => Test_utils.eq("File \"limits_test.res\", line 5, characters 27-34", 2147483647, 2147483647)); + Mocha.test("min_int", () => Test_utils.eq("File \"limits_test.res\", line 6, characters 27-34", -2147483648, -2147483648)); }); /* Not a pure module */ diff --git a/tests/tests/src/mario_game.mjs b/tests/tests/src/mario_game.mjs index e95c66f8f3..9451575554 100644 --- a/tests/tests/src/mario_game.mjs +++ b/tests/tests/src/mario_game.mjs @@ -1,6 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.mjs"; import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.mjs"; import * as Primitive_float from "@rescript/runtime/lib/es6/Primitive_float.mjs"; @@ -789,7 +788,7 @@ let Particle = { process: process }; -let id_counter = Stdlib_Int.Constants.minValue; +let id_counter = -2147483648; function setup_obj(gOpt, spdOpt, param) { let has_gravity = gOpt !== undefined ? gOpt : true; diff --git a/tests/tests/src/optional_external_arg_once_test.mjs b/tests/tests/src/optional_external_arg_once_test.mjs index ddb6d13f7a..4167956f31 100644 --- a/tests/tests/src/optional_external_arg_once_test.mjs +++ b/tests/tests/src/optional_external_arg_once_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.mjs"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; @@ -298,7 +297,7 @@ Mocha.describe("Optional_external_arg_once_test", () => { let tmp = d["k"]; let tmp$1 = { mode: call(() => { - Stdlib_Dict.$$delete(d, "k"); + delete(d["k"]); return "dict"; }) }; diff --git a/tests/tests/src/splice_test.mjs b/tests/tests/src/splice_test.mjs index 96351acc4b..e658ef1a61 100644 --- a/tests/tests/src/splice_test.mjs +++ b/tests/tests/src/splice_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; let Caml_splice_call = {}; @@ -26,10 +25,11 @@ Mocha.test("splice_test_static", () => { function dynamic(arr) { let a = []; a.push(1, ...arr); - Test_utils.eq("File \"splice_test.res\", line 28, characters 5-12", a, Stdlib_Array.concatAll([ + let arrays = [ [1], arr - ])); + ]; + Test_utils.eq("File \"splice_test.res\", line 28, characters 5-12", a, [].concat(...arrays)); } dynamic([ @@ -58,13 +58,14 @@ Mocha.test("splice_test_newArr_static", () => { function dynamicNew(arr) { let a = new Array(1, 2, ...arr); - Test_utils.eq("File \"splice_test.res\", line 48, characters 5-12", a, Stdlib_Array.concatAll([ + let arrays = [ [ 1, 2 ], arr - ])); + ]; + Test_utils.eq("File \"splice_test.res\", line 48, characters 5-12", a, [].concat(...arrays)); } dynamicNew([ @@ -124,10 +125,11 @@ Test_utils.eq("File \"splice_test.res\", line 92, characters 7-14", a, [ function dynamic$1(arr) { let a = []; a.push(1, ...arr); - Test_utils.eq("File \"splice_test.res\", line 98, characters 7-14", a, Stdlib_Array.concatAll([ + let arrays = [ [1], arr - ])); + ]; + Test_utils.eq("File \"splice_test.res\", line 98, characters 7-14", a, [].concat(...arrays)); } dynamic$1([ diff --git a/tests/tests/src/stdlib/Stdlib_ArrayTests.mjs b/tests/tests/src/stdlib/Stdlib_ArrayTests.mjs index a4a78cd358..605afd1dda 100644 --- a/tests/tests/src/stdlib/Stdlib_ArrayTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_ArrayTests.mjs @@ -74,11 +74,11 @@ Test.run([ 28 ], "reduce" -], Stdlib_Array.reduce([ +], [ 1, 2, 3 -], /* [] */0, Stdlib_List.add), eq, {hd: 3, tl: {hd: 2, tl: {hd: 1, tl: /* [] */0}}}); +].reduce(Stdlib_List.add, /* [] */0), eq, {hd: 3, tl: {hd: 2, tl: {hd: 1, tl: /* [] */0}}}); Test.run([ [ @@ -88,7 +88,7 @@ Test.run([ 36 ], "reduce - empty" -], Stdlib_Array.reduce([], /* [] */0, Stdlib_List.add), eq, /* [] */0); +], [].reduce(Stdlib_List.add, /* [] */0), eq, /* [] */0); Test.run([ [ @@ -98,11 +98,11 @@ Test.run([ 30 ], "reduceWithIndex" -], Stdlib_Array.reduceWithIndex([ +], [ 1, 2, 3 -], /* [] */0, (acc, v, i) => ({hd: v + i | 0, tl: acc})), eq, {hd: 5, tl: {hd: 3, tl: {hd: 1, tl: /* [] */0}}}); +].reduce((acc, v, i) => ({hd: v + i | 0, tl: acc}), /* [] */0), eq, {hd: 5, tl: {hd: 3, tl: {hd: 1, tl: /* [] */0}}}); Test.run([ [ @@ -112,7 +112,7 @@ Test.run([ 38 ], "reduceWithIndex - empty" -], Stdlib_Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({hd: v + i | 0, tl: acc})), eq, /* [] */0); +], [].reduce((acc, v, i) => ({hd: v + i | 0, tl: acc}), /* [] */0), eq, /* [] */0); Test.run([ [ @@ -122,11 +122,11 @@ Test.run([ 26 ], "reduceRight" -], Stdlib_Array.reduceRight([ +], [ 1, 2, 3 -], /* [] */0, Stdlib_List.add), eq, {hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}); +].reduceRight(Stdlib_List.add, /* [] */0), eq, {hd: 1, tl: {hd: 2, tl: {hd: 3, tl: /* [] */0}}}); Test.run([ [ @@ -136,7 +136,7 @@ Test.run([ 41 ], "reduceRight - empty" -], Stdlib_Array.reduceRight([], /* [] */0, Stdlib_List.add), eq, /* [] */0); +], [].reduceRight(Stdlib_List.add, /* [] */0), eq, /* [] */0); Test.run([ [ @@ -146,11 +146,11 @@ Test.run([ 35 ], "reduceEightWithIndex" -], Stdlib_Array.reduceRightWithIndex([ +], [ 1, 2, 3 -], /* [] */0, (acc, v, i) => ({hd: v + i | 0, tl: acc})), eq, {hd: 1, tl: {hd: 3, tl: {hd: 5, tl: /* [] */0}}}); +].reduceRight((acc, v, i) => ({hd: v + i | 0, tl: acc}), /* [] */0), eq, {hd: 1, tl: {hd: 3, tl: {hd: 5, tl: /* [] */0}}}); Test.run([ [ @@ -160,7 +160,7 @@ Test.run([ 38 ], "reduceWithIndex - empty" -], Stdlib_Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({hd: v + i | 0, tl: acc})), eq, /* [] */0); +], [].reduceRight((acc, v, i) => ({hd: v + i | 0, tl: acc}), /* [] */0), eq, /* [] */0); Test.run([ [ @@ -407,7 +407,7 @@ let arrays = [ ] ]; -let result = Stdlib_Array.concatAll(arrays); +let result = [].concat(...arrays); Test.run([ [ @@ -445,6 +445,8 @@ Test.run([ ] ]); +let arrays$1 = []; + Test.run([ [ "Stdlib_ArrayTests.res", @@ -453,7 +455,7 @@ Test.run([ 39 ], "concatAll - empty" -], Stdlib_Array.concatAll([]), eq, []); +], [].concat(...arrays$1), eq, []); Test.run([ [ @@ -533,6 +535,12 @@ Test.run([ 2 ]); +let a = [ + 1, + 2, + 3 +]; + Test.run([ [ "Stdlib_ArrayTests.res", @@ -541,11 +549,9 @@ Test.run([ 39 ], "last - with items" -], Stdlib_Array.last([ - 1, - 2, - 3 -]), eq, 3); +], a[a.length - 1 | 0], eq, 3); + +let a$1 = []; Test.run([ [ @@ -555,7 +561,7 @@ Test.run([ 34 ], "last - empty" -], Stdlib_Array.last([]), eq, undefined); +], a$1[a$1.length - 1 | 0], eq, undefined); let array = []; diff --git a/tests/tests/src/stdlib/Stdlib_IteratorTests.mjs b/tests/tests/src/stdlib/Stdlib_IteratorTests.mjs index b12da98330..baaf242ee4 100644 --- a/tests/tests/src/stdlib/Stdlib_IteratorTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_IteratorTests.mjs @@ -5,10 +5,8 @@ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.mjs"; import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.mjs"; import * as Stdlib_Iterator from "@rescript/runtime/lib/es6/Stdlib_Iterator.mjs"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; -import * as Stdlib_Generator from "@rescript/runtime/lib/es6/Stdlib_Generator.mjs"; import * as Stdlib_AsyncIterator from "@rescript/runtime/lib/es6/Stdlib_AsyncIterator.mjs"; import * as Stdlib_AsyncGenerator from "@rescript/runtime/lib/es6/Stdlib_AsyncGenerator.mjs"; -import * as Stdlib_IteratorObject from "@rescript/runtime/lib/es6/Stdlib_IteratorObject.mjs"; import * as Stdlib_IterableIterator from "@rescript/runtime/lib/es6/Stdlib_IterableIterator.mjs"; import * as Stdlib_AsyncIterableIterator from "@rescript/runtime/lib/es6/Stdlib_AsyncIterableIterator.mjs"; @@ -184,9 +182,9 @@ let syncResult = { contents: undefined }; -Stdlib_IterableIterator.next(iterator); +Stdlib_Iterator.next(iterator); -let match = Stdlib_IterableIterator.next(iterator); +let match = Stdlib_Iterator.next(iterator); if (match.done === false && match.value === "b") { syncResult.contents = "b"; @@ -311,9 +309,9 @@ let createdIterableResult = { contents: undefined }; -Stdlib_IterableIterator.next(createdIterableIterator); +Stdlib_Iterator.next(createdIterableIterator); -let match$4 = Stdlib_IterableIterator.next(createdIterableIterator); +let match$4 = Stdlib_Iterator.next(createdIterableIterator); if (match$4.done === false) { if (match$4.value === 1) { @@ -395,12 +393,12 @@ let generatorWithNext = ((function* () { yield injected + 1 })()); -let match$6 = Stdlib_Generator.next(generatorWithNext); +let match$6 = Stdlib_Iterator.next(generatorWithNext); let tmp; if (match$6.done === false && match$6.value === 1) { - let match$7 = Stdlib_IteratorObject.nextValue(generatorWithNext, 41); + let match$7 = Stdlib_Iterator.nextValue(generatorWithNext, 41); tmp = match$7.done === false && match$7.value === 42 ? "nextValue" : undefined; } else { tmp = undefined; @@ -425,9 +423,9 @@ let generatorReturnValue = ((function* () { return "done" })()); -Stdlib_Generator.next(generatorReturnValue); +Stdlib_Iterator.next(generatorReturnValue); -let match$8 = Stdlib_Generator.returnValue(generatorReturnValue, "stopped"); +let match$8 = Stdlib_Iterator.normalizeResult(generatorReturnValue.return("stopped")); if (match$8.done !== false && match$8.value === "stopped") { generatorReturnValueResult.contents = "returnValue"; @@ -456,9 +454,11 @@ let generatorThrowError = ((function* () { } })()); -Stdlib_Generator.next(generatorThrowError); +Stdlib_Iterator.next(generatorThrowError); -let match$9 = Stdlib_Generator.throwError(generatorThrowError, Stdlib_JsExn.anyToExnInternal(new Error("boom"))); +let error = Stdlib_JsExn.anyToExnInternal(new Error("boom")); + +let match$9 = Stdlib_Iterator.normalizeResult(generatorThrowError.throw(error)); if (match$9.done !== false) { generatorThrowErrorResult.contents = "throwError"; @@ -483,7 +483,7 @@ let asyncResult = { contents: undefined }; -await Stdlib_AsyncIterableIterator.next(asyncIterableIterator); +await Stdlib_AsyncIterator.next(asyncIterableIterator); await Stdlib_AsyncIterableIterator.forEach(asyncIterableIterator, param => { if (param[0] === "second") { @@ -580,7 +580,7 @@ let asyncGeneratorNextValueResult = { await Stdlib_AsyncIterator.nextValue(asyncGeneratorNextValue, undefined); -let match$10 = await Stdlib_AsyncGenerator.nextValue(asyncGeneratorNextValue, 4); +let match$10 = await Stdlib_AsyncIterator.nextValue(asyncGeneratorNextValue, 4); if (match$10.done !== false && match$10.value === "5") { asyncGeneratorNextValueResult.contents = "nextValue"; @@ -744,7 +744,7 @@ let asyncGeneratorReturnValue = ((async function* () { return "done" })()); -await Stdlib_AsyncGenerator.next(asyncGeneratorReturnValue); +await Stdlib_AsyncIterator.next(asyncGeneratorReturnValue); let match$11 = await Stdlib_AsyncGenerator.returnValue(asyncGeneratorReturnValue, "stopped"); @@ -775,7 +775,7 @@ let asyncGeneratorThrowError = ((async function* () { } })()); -await Stdlib_AsyncGenerator.next(asyncGeneratorThrowError); +await Stdlib_AsyncIterator.next(asyncGeneratorThrowError); let match$12 = await Stdlib_AsyncGenerator.throwError(asyncGeneratorThrowError, Stdlib_JsExn.anyToExnInternal(new Error("boom"))); diff --git a/tests/tests/src/stdlib/Stdlib_PromiseTest.mjs b/tests/tests/src/stdlib/Stdlib_PromiseTest.mjs index dc00b0d4b9..21e3a2d47c 100644 --- a/tests/tests/src/stdlib/Stdlib_PromiseTest.mjs +++ b/tests/tests/src/stdlib/Stdlib_PromiseTest.mjs @@ -3,7 +3,6 @@ import * as Test from "./Test.mjs"; import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.mjs"; import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.mjs"; -import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.mjs"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; @@ -112,10 +111,12 @@ let ThenChaining = { }; function testExnRejection() { - Stdlib_Promise.$$catch(Promise.reject({ + let promise = Promise.reject({ RE_EXN_ID: TestError, _1: "oops" - }), e => { + }); + promise.catch(err => { + let e = Primitive_exceptions.internalToException(err); Test.run([ [ "Stdlib_PromiseTest.res", @@ -149,7 +150,9 @@ let asyncParseFail = (function() { }); function testExternalPromiseThrow() { - return Stdlib_Promise.$$catch(asyncParseFail().then(param => Promise.resolve()), e => { + let promise = asyncParseFail().then(param => Promise.resolve()); + return promise.catch(err => { + let e = Primitive_exceptions.internalToException(err); let success = e.RE_EXN_ID === "JsExn" ? Primitive_object.equal(Stdlib_JsExn.name(e._1), "SyntaxError") : false; Test.run([ [ @@ -165,13 +168,15 @@ function testExternalPromiseThrow() { } function testExnThrow() { - return Stdlib_Promise.$$catch(Promise.resolve().then(() => { + let promise = Promise.resolve().then(() => { throw { RE_EXN_ID: TestError, _1: "Thrown exn", Error: new Error() }; - }), e => { + }); + return promise.catch(err => { + let e = Primitive_exceptions.internalToException(err); let isTestErr = e.RE_EXN_ID === TestError ? e._1 === "Thrown exn" : false; Test.run([ [ @@ -187,7 +192,9 @@ function testExnThrow() { } function testRaiseErrorThrow() { - return Stdlib_Promise.$$catch(Promise.resolve().then(() => Stdlib_JsError.throwWithMessage("Some JS error")), e => { + let promise = Promise.resolve().then(() => Stdlib_JsError.throwWithMessage("Some JS error")); + return promise.catch(err => { + let e = Primitive_exceptions.internalToException(err); let isTestErr = e.RE_EXN_ID === "JsExn" ? Primitive_object.equal(Stdlib_JsExn.message(e._1), "Some JS error") : false; Test.run([ [ @@ -203,10 +210,12 @@ function testRaiseErrorThrow() { } function thenAfterCatch() { - return Stdlib_Promise.$$catch(Promise.resolve().then(() => Promise.reject({ + let promise = Promise.resolve().then(() => Promise.reject({ RE_EXN_ID: TestError, _1: "some rejected value" - })), e => { + })); + return promise.catch(err => { + let e = Primitive_exceptions.internalToException(err); let s = e.RE_EXN_ID === TestError && e._1 === "some rejected value" ? "success" : "not a test error"; return Promise.resolve(s); }).then(msg => { @@ -225,10 +234,14 @@ function thenAfterCatch() { function testCatchFinally() { let wasCalled = false; - Stdlib_Promise.$$catch(Promise.resolve(5).then(param => Promise.reject({ + let promise = Promise.resolve(5).then(param => Promise.reject({ RE_EXN_ID: TestError, _1: "test" - })).then(v => Promise.resolve(v)), param => Promise.resolve()).finally(() => { + })).then(v => Promise.resolve(v)); + promise.catch(err => { + Primitive_exceptions.internalToException(err); + return Promise.resolve(); + }).finally(() => { wasCalled = true; }).then(v => { Test.run([ diff --git a/tests/tests/src/stdlib/Stdlib_ResultTests.mjs b/tests/tests/src/stdlib/Stdlib_ResultTests.mjs index 91f858d2e1..7fb6513ce4 100644 --- a/tests/tests/src/stdlib/Stdlib_ResultTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_ResultTests.mjs @@ -8,12 +8,10 @@ let eq = Primitive_object.equal; function forEachIfOkCallFunction() { let called = []; - Stdlib_Result.forEach({ - TAG: "Ok", - _0: 3 - }, i => { + let f = i => { called.push(i); - }); + }; + f(3); Test.run([ [ "Stdlib_ResultTests.res", @@ -29,12 +27,6 @@ forEachIfOkCallFunction(); function forEachIfErrorDoNotCallFunction() { let called = []; - Stdlib_Result.forEach({ - TAG: "Error", - _0: 3 - }, i => { - called.push(i); - }); Test.run([ [ "Stdlib_ResultTests.res", @@ -56,10 +48,10 @@ Test.run([ 48 ], "mapError: if ok, return it" -], Stdlib_Result.mapError({ +], { TAG: "Ok", _0: 5 -}, i => i * 3 | 0), eq, { +}, eq, { TAG: "Ok", _0: 5 }); @@ -72,10 +64,10 @@ Test.run([ 42 ], "mapError: if error, apply f" -], Stdlib_Result.mapError({ +], { TAG: "Error", - _0: 5 -}, i => i * 3 | 0), eq, { + _0: 15 +}, eq, { TAG: "Error", _0: 15 }); diff --git a/tests/tests/src/stdlib/Stdlib_TempTests.mjs b/tests/tests/src/stdlib/Stdlib_TempTests.mjs index 8a18db36c3..1933f5155f 100644 --- a/tests/tests/src/stdlib/Stdlib_TempTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_TempTests.mjs @@ -1,8 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.mjs"; -import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as Stdlib_Float from "@rescript/runtime/lib/es6/Stdlib_Float.mjs"; import * as Stdlib_BigInt from "@rescript/runtime/lib/es6/Stdlib_BigInt.mjs"; import * as Primitive_bigint from "@rescript/runtime/lib/es6/Primitive_bigint.mjs"; @@ -22,7 +20,7 @@ let array = [ 4 ]; -console.info(Stdlib_Array.reduce(array.map(x => (x << 1)), 0, (a, b) => a + b | 0)); +console.info(array.map(x => (x << 1)).reduce((a, b) => a + b | 0, 0)); console.info(typeof array); @@ -48,7 +46,7 @@ dict["foo"] = "bar"; let dict2 = Object.assign({}, dict); -Stdlib_Dict.$$delete(dict2, "foo"); +delete(dict2["foo"]); console.log(dict, dict2); @@ -274,7 +272,9 @@ if (globalThis.hello !== undefined) { let z = 1.2 % 1.4; -let intFromBigInt = Stdlib_BigInt.toInt(BigInt("10000000000")); +let t = BigInt("10000000000"); + +let intFromBigInt = Number(t) | 0; console.log({ bar: "1" diff --git a/tests/tests/src/string_set.mjs b/tests/tests/src/string_set.mjs index 75f25f883d..ce949f6d55 100644 --- a/tests/tests/src/string_set.mjs +++ b/tests/tests/src/string_set.mjs @@ -2,7 +2,6 @@ import * as Set_gen from "./set_gen.mjs"; import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.mjs"; function compare_elt(a, b) { @@ -273,7 +272,7 @@ function of_list(l) { } function of_array(l) { - return Stdlib_Array.reduceRight(l, Set_gen.empty, (acc, x) => add(x, acc)); + return l.reduceRight((acc, x) => add(x, acc), Set_gen.empty); } function invariant(t) { diff --git a/tests/tests/src/tagged_template_test.mjs b/tests/tests/src/tagged_template_test.mjs index 5a13618987..e3ee5ef4e2 100644 --- a/tests/tests/src/tagged_template_test.mjs +++ b/tests/tests/src/tagged_template_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import TaggedTemplatePg from "#tagged-template-pg"; import * as Stdlib_TaggedTemplate from "@rescript/runtime/lib/es6/Stdlib_TaggedTemplate.mjs"; import * as Tagged_template_binding from "./tagged_template_binding.mjs"; @@ -49,12 +48,12 @@ function runQuery(tag) { let paramQuery = sql`SELECT id = ${id}`; -let s = Stdlib_TaggedTemplate.make((strings, parameters) => Stdlib_Array.reduceWithIndex(parameters, strings[0], (acc, param, i) => { +let s = Stdlib_TaggedTemplate.make((strings, parameters) => parameters.reduce((acc, param, i) => { let suffix = strings[i + 1 | 0]; let p; p = param.TAG === "I" ? param._0.toString() : param._0; return acc + p + suffix; -})); +}, strings[0])); let greeting = s`hello ${{ TAG: "S", diff --git a/tests/tests/src/test_functor_dead_code.mjs b/tests/tests/src/test_functor_dead_code.mjs index b31d05f067..c9fca819f8 100644 --- a/tests/tests/src/test_functor_dead_code.mjs +++ b/tests/tests/src/test_functor_dead_code.mjs @@ -1,10 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Stdlib_Map from "@rescript/runtime/lib/es6/Stdlib_Map.mjs"; -let v = Stdlib_Map.isEmpty(new Map()); +let map = new Map(); + +let v = map.size === 0; export { v, } -/* v Not a pure module */ +/* map Not a pure module */