From 58284607b9f6bc78b86943ea7e2bb53521298ac3 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 25 Oct 2024 11:00:41 +0200 Subject: [PATCH] Core typedefs for date and regExp --- compiler/ml/ast_untagged_variants.ml | 4 ++-- lib/es6/CoreTypes.js | 1 + lib/js/CoreTypes.js | 1 + runtime/CoreTypes.res | 3 +++ runtime/Date.res | 2 +- runtime/Date.resi | 2 +- runtime/Js_date.res | 2 +- runtime/Js_re.res | 2 +- runtime/Pervasives.res | 17 +++++++---------- runtime/RegExp.res | 2 +- .../typescript-react-example/package-lock.json | 2 +- .../src/nested/Types.res | 2 +- .../idempotency/pupilfirst/shared/DateTime.res | 2 +- .../idempotency/pupilfirst/shared/DateTime.resi | 2 +- 14 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 lib/es6/CoreTypes.js create mode 100644 lib/js/CoreTypes.js create mode 100644 runtime/CoreTypes.res diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index ab53f3961e..ec8e84ac8c 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -166,8 +166,8 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) = | Tconstr (path, _, _) when Path.same path Predef.path_array -> Some Array | Tconstr (path, _, _) -> ( match Path.name path with - | "Js_date.t" -> Some Date - | "Js_re.t" -> Some RegExp + | "CoreTypes.date" -> Some Date + | "CoreTypes.regExp" -> Some RegExp | "Js_file.t" -> Some File | "Js_blob.t" -> Some Blob | _ -> None) diff --git a/lib/es6/CoreTypes.js b/lib/es6/CoreTypes.js new file mode 100644 index 0000000000..ae1b9f17e6 --- /dev/null +++ b/lib/es6/CoreTypes.js @@ -0,0 +1 @@ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/js/CoreTypes.js b/lib/js/CoreTypes.js new file mode 100644 index 0000000000..ae1b9f17e6 --- /dev/null +++ b/lib/js/CoreTypes.js @@ -0,0 +1 @@ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/runtime/CoreTypes.res b/runtime/CoreTypes.res new file mode 100644 index 0000000000..768f941866 --- /dev/null +++ b/runtime/CoreTypes.res @@ -0,0 +1,3 @@ +type date + +type regExp diff --git a/runtime/Date.res b/runtime/Date.res index 925afcc190..0f1d424af5 100644 --- a/runtime/Date.res +++ b/runtime/Date.res @@ -1,4 +1,4 @@ -type t = Js.Date.t +type t = CoreTypes.date type msSinceEpoch = float diff --git a/runtime/Date.resi b/runtime/Date.resi index f0d975ba1a..8e0c14f65b 100644 --- a/runtime/Date.resi +++ b/runtime/Date.resi @@ -5,7 +5,7 @@ /** A type representing a JavaScript date. */ -type t = Js.Date.t +type t = CoreTypes.date /** Time, in milliseconds, since / until the UNIX epoch (January 1, 1970 00:00:00 UTC). diff --git a/runtime/Js_date.res b/runtime/Js_date.res index 2a7b6be24b..7d2fd8ea0c 100644 --- a/runtime/Js_date.res +++ b/runtime/Js_date.res @@ -29,7 +29,7 @@ on MDN.) JavaScript stores dates as the number of milliseconds since the UNIX *epoch*, midnight 1 January 1970, UTC. */ -type t +type t = CoreTypes.date @send /** diff --git a/runtime/Js_re.res b/runtime/Js_re.res index 05e46ec64a..2253b6c4b5 100644 --- a/runtime/Js_re.res +++ b/runtime/Js_re.res @@ -31,7 +31,7 @@ and subsequent uses will continue the search from the previous [`lastIndex`](). */ /** The RegExp object. */ -type t +type t = CoreTypes.regExp /** The result of a executing a RegExp on a string. */ type result diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index 8f05695ddc..d4c6f4d8e9 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -1,15 +1,12 @@ -/** - Since [others] depend on this file, its public mli files **should not - export types** introduced here, otherwise it would cause - conflicts here. +/* Core type aliases */ - If the type exported here is also exported in modules from others, - you will get a type not equivalent. -*/ -@deprecated("Do not use. This will be removed in v13") -external /* Internal */ +type date = CoreTypes.date +type regExp = CoreTypes.regExp -__unsafe_cast: 'a => 'b = "%identity" +/* Internal */ + +@deprecated("Do not use. This will be removed in v13") +external __unsafe_cast: 'a => 'b = "%identity" /* Exceptions */ diff --git a/runtime/RegExp.res b/runtime/RegExp.res index 9f19af81ab..6ac623a935 100644 --- a/runtime/RegExp.res +++ b/runtime/RegExp.res @@ -1,4 +1,4 @@ -type t = Js.Re.t +type t = CoreTypes.regExp module Result = { type t = array> diff --git a/tests/gentype_tests/typescript-react-example/package-lock.json b/tests/gentype_tests/typescript-react-example/package-lock.json index 3d1726bcb8..090c2be357 100644 --- a/tests/gentype_tests/typescript-react-example/package-lock.json +++ b/tests/gentype_tests/typescript-react-example/package-lock.json @@ -22,7 +22,7 @@ }, "../../..": { "name": "rescript", - "version": "12.0.0-alpha.4", + "version": "12.0.0-alpha.5", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", diff --git a/tests/gentype_tests/typescript-react-example/src/nested/Types.res b/tests/gentype_tests/typescript-react-example/src/nested/Types.res index 54fa80803c..c7d074824d 100644 --- a/tests/gentype_tests/typescript-react-example/src/nested/Types.res +++ b/tests/gentype_tests/typescript-react-example/src/nested/Types.res @@ -122,7 +122,7 @@ type instantiateTypeParameter = ocaml_array @genType @genType.as("Vector") type vector<'a> = ('a, 'a) -@genType type date = Js.Date.t +@genType type date = Date.t @genType let currentTime = Js.Date.make() diff --git a/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.res b/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.res index b902ba4261..b0b83d9bcd 100644 --- a/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.res +++ b/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.res @@ -1,4 +1,4 @@ -type t = Js.Date.t +type t = Date.t @val @module("date-fns") external dateFormat: (t, string) => string = "format" diff --git a/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.resi b/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.resi index 0bcbd37e00..1dcf30fdea 100644 --- a/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.resi +++ b/tests/syntax_tests/data/idempotency/pupilfirst/shared/DateTime.resi @@ -1,4 +1,4 @@ -type t = Js.Date.t +type t = Date.t type format = | OnlyDate