diff --git a/CHANGELOG.md b/CHANGELOG.md index e3c1527a..6bced219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Fixed type signatures of `Array.fromArrayLikeWithMap` and `Array.fromIteratorWithMap`. https://github.com/rescript-association/rescript-core/pull/50 - Remove internal async/await helpers that do not need to be exposed in `Core`. - Add locale and formatting options to `localeDateString`, `localeString` and `localTimeString` functions https://github.com/rescript-association/rescript-core/pull/30 +- Remove `Undefined` module. `Nullable` or `option` directly (where appropriate) can be used instead. https://github.com/rescript-association/rescript-core/pull/59 - Change `RegExp.source` to return a `string`. Was previously returning a `bool`, which is wrong. https://github.com/rescript-association/rescript-core/pull/47 - Remove `Date.valueOf` as it returns the same as `Date.getTime`. https://github.com/rescript-association/rescript-core/pull/61 diff --git a/src/Core__Undefined.mjs b/src/Core__Undefined.mjs deleted file mode 100644 index bdc0e58c..00000000 --- a/src/Core__Undefined.mjs +++ /dev/null @@ -1,15 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Caml_option from "rescript/lib/es6/caml_option.js"; - -function fromOption(option) { - if (option !== undefined) { - return Caml_option.valFromOption(option); - } - -} - -export { - fromOption , -} -/* No side effect */ diff --git a/src/Core__Undefined.res b/src/Core__Undefined.res deleted file mode 100644 index c5a19acf..00000000 --- a/src/Core__Undefined.res +++ /dev/null @@ -1,15 +0,0 @@ -type t<'a> = Js.Undefined.t<'a> - -external asNullable: t<'a> => Core__Nullable.t<'a> = "%identity" - -external undefined: t<'a> = "#undefined" - -external make: 'a => t<'a> = "%identity" - -external toOption: t<'a> => option<'a> = "#undefined_to_opt" - -let fromOption: option<'a> => t<'a> = option => - switch option { - | Some(x) => make(x) - | None => undefined - } diff --git a/src/Core__Undefined.resi b/src/Core__Undefined.resi deleted file mode 100644 index 0ffbf5d1..00000000 --- a/src/Core__Undefined.resi +++ /dev/null @@ -1,75 +0,0 @@ -/*** -Functions for handling values that could be `undefined`. - -Please note that a regular `option` is also represented as `undefined` or the value `'a`. In many cases it makes sense to use `option` directly. - -If you also need to cover `null`, check out `Nullable` instead. -*/ - -/** -A type representing a value that can be either `'a` or `undefined`. -*/ -type t<'a> = Js.Undefined.t<'a> - -/** -Converts a `Undefined.t` into a `Nullable.t`. - -## Examples -```rescript -let undefinedValue = Undefined.make("Hello") -let asNullable = undefinedValue->Undefined.asNullable // Nullable.t -``` -*/ -external asNullable: t<'a> => Core__Nullable.t<'a> = "%identity" - -/** -The value `undefined`. - -See [`undefined`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/undefined) on MDN. - -## Examples -```rescript -Console.log(Undefined.undefined) // Logs `undefined` to the console. -``` -*/ -external undefined: t<'a> = "#undefined" - -/** -Creates a new `Undefined.t` from the provided value. -This means the compiler will enforce `undefined` checks for the new value. - -## Examples -```rescript -let myStr = "Hello" -let asUndefinedValue = myStr->Undefined.make // The compiler now thinks this can be `string` or `undefined`. -``` -*/ -external make: 'a => t<'a> = "%identity" - -/** -Converts a potentially undefined value into an option, so it can be pattern matched on. -Will convert `undefined` to `None`, and a present value to `Some(value)`. - -## Examples -```rescript -let undefinedStr = Undefined.make("Hello") - -switch undefinedStr->Undefined.toOption { -| Some(str) => Console.log2("Got string:", str) -| None => Console.log("Didn't have a value.") -} -``` -*/ -external toOption: t<'a> => option<'a> = "#undefined_to_opt" - -/** -Turns an `option` into a `Undefined.t`. `None` will be converted to `undefined`. - -## Examples -```rescript -let optString: option = None -let asUndefined = optString->Undefined.fromOption // Undefined.t -Console.log(asUndefined == Undefined.undefined) // Logs `true` to the console. -``` -*/ -let fromOption: option<'a> => t<'a> diff --git a/src/RescriptCore.mjs b/src/RescriptCore.mjs index 760c8d0d..7706a777 100644 --- a/src/RescriptCore.mjs +++ b/src/RescriptCore.mjs @@ -33,8 +33,6 @@ var $$RegExp; var $$String; -var Undefined; - var $$Symbol; var Type; @@ -112,7 +110,6 @@ export { $$Promise , $$RegExp , $$String , - Undefined , $$Symbol , Type , $$JSON , diff --git a/src/RescriptCore.res b/src/RescriptCore.res index e8262f17..7cd77db2 100644 --- a/src/RescriptCore.res +++ b/src/RescriptCore.res @@ -16,7 +16,6 @@ module Object = Core__Object module Promise = Core__Promise module RegExp = Core__RegExp module String = Core__String -module Undefined = Core__Undefined module Symbol = Core__Symbol module Type = Core__Type module JSON = Core__JSON @@ -49,7 +48,7 @@ module Intl = Core__Intl @val external globalThis: {..} = "globalThis" external null: Core__Null.t<'a> = "#null" -external undefined: Core__Undefined.t<'a> = "#undefined" +external undefined: Core__Nullable.t<'a> = "#undefined" external typeof: 'a => Core__Type.t = "#typeof" type t<'a> = Js.t<'a> diff --git a/test/TempTests.mjs b/test/TempTests.mjs index 6c63e1e9..9807a51a 100644 --- a/test/TempTests.mjs +++ b/test/TempTests.mjs @@ -8,7 +8,6 @@ import * as Core__Array from "../src/Core__Array.mjs"; import * as Core__Float from "../src/Core__Float.mjs"; import * as Core__BigInt from "../src/Core__BigInt.mjs"; import * as Core__Option from "../src/Core__Option.mjs"; -import * as Core__Undefined from "../src/Core__Undefined.mjs"; console.info(""); @@ -311,8 +310,6 @@ var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions(); var timeZone = resolvedOptions.timeZone; -var x$1 = Core__Undefined.fromOption(1); - var z = 1.2 % 1.4; var intFromBigInt = Core__BigInt.toInt(BigInt("10000000000")); @@ -350,11 +347,11 @@ export { result$1 as result, set , regexp , + x , array$1 as array, timeout , resolvedOptions , timeZone , - x$1 as x, z , intFromBigInt , Bugfix , diff --git a/test/TempTests.res b/test/TempTests.res index 4c3233b9..82784cea 100644 --- a/test/TempTests.res +++ b/test/TempTests.res @@ -194,8 +194,6 @@ if globalThis["hello"] !== undefined { let resolvedOptions = Intl.DateTimeFormat.make()->Intl.DateTimeFormat.resolvedOptions let timeZone = resolvedOptions["timeZone"] -let x = Some(1)->Undefined.fromOption - let z = Float.mod(1.2, 1.4) let intFromBigInt = BigInt.fromString("10000000000")->BigInt.toInt