Skip to content

Commit

Permalink
Stdlib namespace for Core modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cknitt committed Feb 8, 2025
1 parent d4e5c8e commit af47499
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 12 deletions.
5 changes: 4 additions & 1 deletion compiler/core/res_compmisc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ let initial_env ?modulename () =
let initial = Env.initial_safe_string in
let env =
if !Clflags.nopervasives then initial
else open_implicit_module "Pervasives" initial
else
initial
|> open_implicit_module "Pervasives"
|> open_implicit_module "Stdlib"
in
List.fold_left
(fun env m -> open_implicit_module m env)
Expand Down
2 changes: 1 addition & 1 deletion compiler/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
{dependencies = []; type_ = string_t}
| (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] ->
{dependencies = []; type_ = bigint_t}
| (["Js"; "Date"; "t"] | ["Date"; "t"]), [] ->
| (["Js"; "Date"; "t"] | ["Date"; "t"] | ["Stdlib_Date"; "t"]), [] ->
{dependencies = []; type_ = date_t}
| ["Map"; "t"], [param_translation1; param_translation2] ->
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/ml/ast_untagged_variants.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ 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
| "Stdlib_Date.t" -> Some Date
| "Js_re.t" -> Some RegExp
| "Js_file.t" -> Some File
| "Js_blob.t" -> Some Blob
Expand Down
9 changes: 9 additions & 0 deletions lib/es6/Stdlib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@



let $$Date;

export {
$$Date,
}
/* No side effect */
File renamed without changes.
7 changes: 7 additions & 0 deletions lib/js/Stdlib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';


let $$Date;

exports.$$Date = $$Date;
/* No side effect */
File renamed without changes.
14 changes: 9 additions & 5 deletions runtime/Intl_DateTimeFormat.res
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,17 @@ external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?

@send external resolvedOptions: t => resolvedOptions = "resolvedOptions"

@send external format: (t, Date.t) => string = "format"
@send external format: (t, Stdlib_Date.t) => string = "format"
@send
external formatToParts: (t, Date.t) => array<dateTimePart> = "formatToParts"
external formatToParts: (t, Stdlib_Date.t) => array<dateTimePart> = "formatToParts"

@send
external formatRange: (t, ~startDate: Date.t, ~endDate: Date.t) => string = "formatRange"
external formatRange: (t, ~startDate: Stdlib_Date.t, ~endDate: Stdlib_Date.t) => string =
"formatRange"

@send
external formatRangeToParts: (t, ~startDate: Date.t, ~endDate: Date.t) => array<dateTimeRangePart> =
"formatRangeToParts"
external formatRangeToParts: (
t,
~startDate: Stdlib_Date.t,
~endDate: Stdlib_Date.t,
) => array<dateTimeRangePart> = "formatRangeToParts"
2 changes: 1 addition & 1 deletion runtime/Js_date.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Stdlib_Date.t

@send
/**
Expand Down
2 changes: 1 addition & 1 deletion runtime/JsxDOM.res
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type domProps = {
loop?: bool,
low?: int,
manifest?: string /* uri */,
max?: string /* should be int or Js.Date.t */,
max?: string /* should be int or Date.t */,
maxLength?: int,
media?: string /* a valid media query */,
mediaGroup?: string,
Expand Down
4 changes: 4 additions & 0 deletions runtime/Stdlib.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Date = Stdlib_Date

// Aliases for convenience
type date = Date.t
2 changes: 1 addition & 1 deletion runtime/Date.res → runtime/Stdlib_Date.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type t = Js.Date.t
type t

type msSinceEpoch = float

Expand Down
2 changes: 1 addition & 1 deletion runtime/Date.resi → runtime/Stdlib_Date.resi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
A type representing a JavaScript date.
*/
type t = Js.Date.t
type t

/**
Time, in milliseconds, since / until the UNIX epoch (January 1, 1970 00:00:00 UTC).
Expand Down

0 comments on commit af47499

Please sign in to comment.