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 5c0a664
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 43 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
62 changes: 31 additions & 31 deletions tests/analysis_tests/tests/src/expected/CompletionTypeT.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ Path date
"kind": 12,
"tags": [],
"detail": "Js.Date.t",
"documentation": null
"documentation": {"kind": "markdown", "value": "\nA type representing a JavaScript date.\n"}
}, {
"label": "Some(_)",
"kind": 12,
"tags": [],
"detail": "Js.Date.t",
"documentation": null,
"documentation": {"kind": "markdown", "value": "\nA type representing a JavaScript date.\n"},
"insertText": "Some(${1:_})",
"insertTextFormat": 2
}, {
"label": "Some(date)",
"label": "Some(stdlib_Date)",
"kind": 4,
"tags": [],
"detail": "date",
"detail": "stdlib_Date",
"documentation": null,
"insertText": "Some(${0:date})",
"insertText": "Some(${0:stdlib_Date})",
"insertTextFormat": 2
}]

Expand All @@ -35,76 +35,76 @@ Package opens Pervasives.JsxModules.place holder
ContextPath Type[withDate]
Path withDate
[{
"label": "Js.Date.makeWithYMD()",
"label": "Stdlib_Date.makeWithYMD()",
"kind": 12,
"tags": [],
"detail": "(~year: float, ~month: float, ~date: float, unit) => t",
"detail": "(~year: int, ~month: int, ~date: int) => t",
"documentation": null,
"insertText": "Js.Date.makeWithYMD($0)",
"insertText": "Stdlib_Date.makeWithYMD($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.makeWithYMDHM()",
"label": "Stdlib_Date.makeWithYMDHM()",
"kind": 12,
"tags": [],
"detail": "(\n ~year: float,\n ~month: float,\n ~date: float,\n ~hours: float,\n ~minutes: float,\n unit,\n) => t",
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n) => t",
"documentation": null,
"insertText": "Js.Date.makeWithYMDHM($0)",
"insertText": "Stdlib_Date.makeWithYMDHM($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.make()",
"label": "Stdlib_Date.make()",
"kind": 12,
"tags": [],
"detail": "unit => t",
"documentation": null,
"insertText": "Js.Date.make($0)",
"insertText": "Stdlib_Date.make($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.fromString()",
"label": "Stdlib_Date.fromTime()",
"kind": 12,
"tags": [],
"detail": "string => t",
"detail": "msSinceEpoch => t",
"documentation": null,
"insertText": "Js.Date.fromString($0)",
"insertText": "Stdlib_Date.fromTime($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.fromFloat()",
"label": "Stdlib_Date.fromString()",
"kind": 12,
"tags": [],
"detail": "float => t",
"detail": "string => t",
"documentation": null,
"insertText": "Js.Date.fromFloat($0)",
"insertText": "Stdlib_Date.fromString($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.parse()",
"label": "Stdlib_Date.makeWithYMDHMSM()",
"kind": 12,
"tags": [],
"detail": "string => t",
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n ~milliseconds: int,\n) => t",
"documentation": null,
"insertText": "Js.Date.parse($0)",
"insertText": "Stdlib_Date.makeWithYMDHMSM($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.makeWithYM()",
"label": "Stdlib_Date.makeWithYM()",
"kind": 12,
"tags": [],
"detail": "(~year: float, ~month: float, unit) => t",
"detail": "(~year: int, ~month: int) => t",
"documentation": null,
"insertText": "Js.Date.makeWithYM($0)",
"insertText": "Stdlib_Date.makeWithYM($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.makeWithYMDHMS()",
"label": "Stdlib_Date.makeWithYMDHMS()",
"kind": 12,
"tags": [],
"detail": "(\n ~year: float,\n ~month: float,\n ~date: float,\n ~hours: float,\n ~minutes: float,\n ~seconds: float,\n unit,\n) => t",
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n) => t",
"documentation": null,
"insertText": "Js.Date.makeWithYMDHMS($0)",
"insertText": "Stdlib_Date.makeWithYMDHMS($0)",
"insertTextFormat": 2
}, {
"label": "Js.Date.makeWithYMDH()",
"label": "Stdlib_Date.makeWithYMDH()",
"kind": 12,
"tags": [],
"detail": "(\n ~year: float,\n ~month: float,\n ~date: float,\n ~hours: float,\n unit,\n) => t",
"detail": "(~year: int, ~month: int, ~date: int, ~hours: int) => t",
"documentation": null,
"insertText": "Js.Date.makeWithYMDH($0)",
"insertText": "Stdlib_Date.makeWithYMDH($0)",
"insertTextFormat": 2
}]

0 comments on commit 5c0a664

Please sign in to comment.