Skip to content

Improve Core__Type / Add support for BigInt #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2023
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

- Map, Set, WeakMap, WeakSet: use the types defined in the Js namespace. https://github.com/rescript-association/rescript-core/pull/143
- Symbol: use the types defined in the Js namespace. https://github.com/rescript-association/rescript-core/pull/145
- The types `RescriptCore.Type.function` and `RescriptCore.Type.object` use the types defined in the Js namespace. https://github.com/rescript-association/rescript-core/pull/146
- The type `RescriptCore.Type.symbol` removed in favor of `RescriptCore.Symbol.t`. https://github.com/rescript-association/rescript-core/pull/146
- Added `BigInt` support for `RescriptCore.Classify.t`. https://github.com/rescript-association/rescript-core/pull/146
- `Array` mutable & immutable helper name changed to conform to JS' upcoming APIs [such as `toSorted`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
- `sort` -> `toSorted`, `sortInPlace` -> `sort`
- `reverse` -> `toReversed`, `reverseInPlace` -> `reverse`
Expand Down
12 changes: 7 additions & 5 deletions src/Core__Type.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ type t = [#undefined | #object | #boolean | #number | #bigint | #string | #symbo
external typeof: 'a => t = "#typeof"

module Classify = {
type function
type object
type symbol
type function = Js.Types.function_val
type object = Js.Types.obj_val

type t =
| Bool(bool)
Expand All @@ -15,15 +14,17 @@ module Classify = {
| Number(float)
| Object(object)
| Function(function)
| Symbol(symbol)
| Symbol(Core__Symbol.t)
| BigInt(Core__BigInt.t)

@val external _internalClass: 'a => string = "Object.prototype.toString.call"
external _asBool: 'a => bool = "%identity"
external _asString: 'a => string = "%identity"
external _asFloat: 'a => float = "%identity"
external _asObject: 'a => object = "%identity"
external _asFunction: 'a => function = "%identity"
external _asSymbol: 'a => symbol = "%identity"
external _asSymbol: 'a => Core__Symbol.t = "%identity"
external _asBigInt: 'a => Core__BigInt.t = "%identity"

let classify = value => {
switch _internalClass(value) {
Expand All @@ -37,6 +38,7 @@ module Classify = {
| "[object AsyncFunction]" =>
Function(_asFunction(value))
| "[object Symbol]" => Symbol(_asSymbol(value))
| "[object BigInt]" => BigInt(_asBigInt(value))
| _ => Object(_asObject(value))
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/Core__Type.resi
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ module Classify: {
*/
type object

/**
An abstract type representing a JavaScript symbol.

See [`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) on MDN.
*/
type symbol

/**
The type representing a classified JavaScript value.
*/
Expand All @@ -65,7 +58,8 @@ module Classify: {
| Number(float)
| Object(object)
| Function(function)
| Symbol(symbol)
| Symbol(Core__Symbol.t)
| BigInt(Core__BigInt.t)

/**
`classify(anyValue)`
Expand Down