Skip to content

Commit 5c0a664

Browse files
committed
Stdlib namespace for Core modules
1 parent d4e5c8e commit 5c0a664

14 files changed

+70
-43
lines changed

compiler/core/res_compmisc.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ let initial_env ?modulename () =
5454
let initial = Env.initial_safe_string in
5555
let env =
5656
if !Clflags.nopervasives then initial
57-
else open_implicit_module "Pervasives" initial
57+
else
58+
initial
59+
|> open_implicit_module "Pervasives"
60+
|> open_implicit_module "Stdlib"
5861
in
5962
List.fold_left
6063
(fun env m -> open_implicit_module m env)

compiler/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
8686
{dependencies = []; type_ = string_t}
8787
| (["Js"; "Types"; "bigint_val"] | ["BigInt"; "t"]), [] ->
8888
{dependencies = []; type_ = bigint_t}
89-
| (["Js"; "Date"; "t"] | ["Date"; "t"]), [] ->
89+
| (["Js"; "Date"; "t"] | ["Date"; "t"] | ["Stdlib_Date"; "t"]), [] ->
9090
{dependencies = []; type_ = date_t}
9191
| ["Map"; "t"], [param_translation1; param_translation2] ->
9292
{

compiler/ml/ast_untagged_variants.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
179179
| Tconstr (path, _, _) when Path.same path Predef.path_array -> Some Array
180180
| Tconstr (path, _, _) -> (
181181
match Path.name path with
182-
| "Js_date.t" -> Some Date
182+
| "Stdlib_Date.t" -> Some Date
183183
| "Js_re.t" -> Some RegExp
184184
| "Js_file.t" -> Some File
185185
| "Js_blob.t" -> Some Blob

lib/es6/Stdlib.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
3+
4+
let $$Date;
5+
6+
export {
7+
$$Date,
8+
}
9+
/* No side effect */
File renamed without changes.

lib/js/Stdlib.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
4+
let $$Date;
5+
6+
exports.$$Date = $$Date;
7+
/* No side effect */
File renamed without changes.

runtime/Intl_DateTimeFormat.res

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,17 @@ external supportedLocalesOf: (array<string>, ~options: supportedLocalesOptions=?
113113

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

116-
@send external format: (t, Date.t) => string = "format"
116+
@send external format: (t, Stdlib_Date.t) => string = "format"
117117
@send
118-
external formatToParts: (t, Date.t) => array<dateTimePart> = "formatToParts"
118+
external formatToParts: (t, Stdlib_Date.t) => array<dateTimePart> = "formatToParts"
119119

120120
@send
121-
external formatRange: (t, ~startDate: Date.t, ~endDate: Date.t) => string = "formatRange"
121+
external formatRange: (t, ~startDate: Stdlib_Date.t, ~endDate: Stdlib_Date.t) => string =
122+
"formatRange"
122123

123124
@send
124-
external formatRangeToParts: (t, ~startDate: Date.t, ~endDate: Date.t) => array<dateTimeRangePart> =
125-
"formatRangeToParts"
125+
external formatRangeToParts: (
126+
t,
127+
~startDate: Stdlib_Date.t,
128+
~endDate: Stdlib_Date.t,
129+
) => array<dateTimeRangePart> = "formatRangeToParts"

runtime/Js_date.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ on MDN.) JavaScript stores dates as the number of milliseconds since the UNIX
2929
*epoch*, midnight 1 January 1970, UTC.
3030
*/
3131

32-
type t
32+
type t = Stdlib_Date.t
3333

3434
@send
3535
/**

runtime/JsxDOM.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ type domProps = {
209209
loop?: bool,
210210
low?: int,
211211
manifest?: string /* uri */,
212-
max?: string /* should be int or Js.Date.t */,
212+
max?: string /* should be int or Date.t */,
213213
maxLength?: int,
214214
media?: string /* a valid media query */,
215215
mediaGroup?: string,

runtime/Stdlib.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Date = Stdlib_Date
2+
3+
// Aliases for convenience
4+
type date = Date.t

runtime/Date.res renamed to runtime/Stdlib_Date.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type t = Js.Date.t
1+
type t
22

33
type msSinceEpoch = float
44

runtime/Date.resi renamed to runtime/Stdlib_Date.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
A type representing a JavaScript date.
77
*/
8-
type t = Js.Date.t
8+
type t
99

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

tests/analysis_tests/tests/src/expected/CompletionTypeT.res.txt

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ Path date
99
"kind": 12,
1010
"tags": [],
1111
"detail": "Js.Date.t",
12-
"documentation": null
12+
"documentation": {"kind": "markdown", "value": "\nA type representing a JavaScript date.\n"}
1313
}, {
1414
"label": "Some(_)",
1515
"kind": 12,
1616
"tags": [],
1717
"detail": "Js.Date.t",
18-
"documentation": null,
18+
"documentation": {"kind": "markdown", "value": "\nA type representing a JavaScript date.\n"},
1919
"insertText": "Some(${1:_})",
2020
"insertTextFormat": 2
2121
}, {
22-
"label": "Some(date)",
22+
"label": "Some(stdlib_Date)",
2323
"kind": 4,
2424
"tags": [],
25-
"detail": "date",
25+
"detail": "stdlib_Date",
2626
"documentation": null,
27-
"insertText": "Some(${0:date})",
27+
"insertText": "Some(${0:stdlib_Date})",
2828
"insertTextFormat": 2
2929
}]
3030

@@ -35,76 +35,76 @@ Package opens Pervasives.JsxModules.place holder
3535
ContextPath Type[withDate]
3636
Path withDate
3737
[{
38-
"label": "Js.Date.makeWithYMD()",
38+
"label": "Stdlib_Date.makeWithYMD()",
3939
"kind": 12,
4040
"tags": [],
41-
"detail": "(~year: float, ~month: float, ~date: float, unit) => t",
41+
"detail": "(~year: int, ~month: int, ~date: int) => t",
4242
"documentation": null,
43-
"insertText": "Js.Date.makeWithYMD($0)",
43+
"insertText": "Stdlib_Date.makeWithYMD($0)",
4444
"insertTextFormat": 2
4545
}, {
46-
"label": "Js.Date.makeWithYMDHM()",
46+
"label": "Stdlib_Date.makeWithYMDHM()",
4747
"kind": 12,
4848
"tags": [],
49-
"detail": "(\n ~year: float,\n ~month: float,\n ~date: float,\n ~hours: float,\n ~minutes: float,\n unit,\n) => t",
49+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n) => t",
5050
"documentation": null,
51-
"insertText": "Js.Date.makeWithYMDHM($0)",
51+
"insertText": "Stdlib_Date.makeWithYMDHM($0)",
5252
"insertTextFormat": 2
5353
}, {
54-
"label": "Js.Date.make()",
54+
"label": "Stdlib_Date.make()",
5555
"kind": 12,
5656
"tags": [],
5757
"detail": "unit => t",
5858
"documentation": null,
59-
"insertText": "Js.Date.make($0)",
59+
"insertText": "Stdlib_Date.make($0)",
6060
"insertTextFormat": 2
6161
}, {
62-
"label": "Js.Date.fromString()",
62+
"label": "Stdlib_Date.fromTime()",
6363
"kind": 12,
6464
"tags": [],
65-
"detail": "string => t",
65+
"detail": "msSinceEpoch => t",
6666
"documentation": null,
67-
"insertText": "Js.Date.fromString($0)",
67+
"insertText": "Stdlib_Date.fromTime($0)",
6868
"insertTextFormat": 2
6969
}, {
70-
"label": "Js.Date.fromFloat()",
70+
"label": "Stdlib_Date.fromString()",
7171
"kind": 12,
7272
"tags": [],
73-
"detail": "float => t",
73+
"detail": "string => t",
7474
"documentation": null,
75-
"insertText": "Js.Date.fromFloat($0)",
75+
"insertText": "Stdlib_Date.fromString($0)",
7676
"insertTextFormat": 2
7777
}, {
78-
"label": "Js.Date.parse()",
78+
"label": "Stdlib_Date.makeWithYMDHMSM()",
7979
"kind": 12,
8080
"tags": [],
81-
"detail": "string => t",
81+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n ~milliseconds: int,\n) => t",
8282
"documentation": null,
83-
"insertText": "Js.Date.parse($0)",
83+
"insertText": "Stdlib_Date.makeWithYMDHMSM($0)",
8484
"insertTextFormat": 2
8585
}, {
86-
"label": "Js.Date.makeWithYM()",
86+
"label": "Stdlib_Date.makeWithYM()",
8787
"kind": 12,
8888
"tags": [],
89-
"detail": "(~year: float, ~month: float, unit) => t",
89+
"detail": "(~year: int, ~month: int) => t",
9090
"documentation": null,
91-
"insertText": "Js.Date.makeWithYM($0)",
91+
"insertText": "Stdlib_Date.makeWithYM($0)",
9292
"insertTextFormat": 2
9393
}, {
94-
"label": "Js.Date.makeWithYMDHMS()",
94+
"label": "Stdlib_Date.makeWithYMDHMS()",
9595
"kind": 12,
9696
"tags": [],
97-
"detail": "(\n ~year: float,\n ~month: float,\n ~date: float,\n ~hours: float,\n ~minutes: float,\n ~seconds: float,\n unit,\n) => t",
97+
"detail": "(\n ~year: int,\n ~month: int,\n ~date: int,\n ~hours: int,\n ~minutes: int,\n ~seconds: int,\n) => t",
9898
"documentation": null,
99-
"insertText": "Js.Date.makeWithYMDHMS($0)",
99+
"insertText": "Stdlib_Date.makeWithYMDHMS($0)",
100100
"insertTextFormat": 2
101101
}, {
102-
"label": "Js.Date.makeWithYMDH()",
102+
"label": "Stdlib_Date.makeWithYMDH()",
103103
"kind": 12,
104104
"tags": [],
105-
"detail": "(\n ~year: float,\n ~month: float,\n ~date: float,\n ~hours: float,\n unit,\n) => t",
105+
"detail": "(~year: int, ~month: int, ~date: int, ~hours: int) => t",
106106
"documentation": null,
107-
"insertText": "Js.Date.makeWithYMDH($0)",
107+
"insertText": "Stdlib_Date.makeWithYMDH($0)",
108108
"insertTextFormat": 2
109109
}]
110110

0 commit comments

Comments
 (0)