diff --git a/compiler/core/res_compmisc.ml b/compiler/core/res_compmisc.ml index 3f8650858a..3f21ce9cc5 100644 --- a/compiler/core/res_compmisc.ml +++ b/compiler/core/res_compmisc.ml @@ -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) diff --git a/compiler/gentype/TranslateTypeExprFromTypes.ml b/compiler/gentype/TranslateTypeExprFromTypes.ml index 75615bcdef..93c8c2e729 100644 --- a/compiler/gentype/TranslateTypeExprFromTypes.ml +++ b/compiler/gentype/TranslateTypeExprFromTypes.ml @@ -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] -> { diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index 253791acf1..b02f6ea839 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -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 diff --git a/lib/es6/Stdlib.js b/lib/es6/Stdlib.js new file mode 100644 index 0000000000..cdd1de9eaf --- /dev/null +++ b/lib/es6/Stdlib.js @@ -0,0 +1,9 @@ + + + +let $$Date; + +export { + $$Date, +} +/* No side effect */ diff --git a/lib/es6/Date.js b/lib/es6/Stdlib_Date.js similarity index 100% rename from lib/es6/Date.js rename to lib/es6/Stdlib_Date.js diff --git a/lib/js/Stdlib.js b/lib/js/Stdlib.js new file mode 100644 index 0000000000..16ac8c6e3c --- /dev/null +++ b/lib/js/Stdlib.js @@ -0,0 +1,7 @@ +'use strict'; + + +let $$Date; + +exports.$$Date = $$Date; +/* No side effect */ diff --git a/lib/js/Date.js b/lib/js/Stdlib_Date.js similarity index 100% rename from lib/js/Date.js rename to lib/js/Stdlib_Date.js diff --git a/runtime/Intl_DateTimeFormat.res b/runtime/Intl_DateTimeFormat.res index 12738b5e0d..42e329823d 100644 --- a/runtime/Intl_DateTimeFormat.res +++ b/runtime/Intl_DateTimeFormat.res @@ -113,13 +113,17 @@ external supportedLocalesOf: (array, ~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 = "formatToParts" +external formatToParts: (t, Stdlib_Date.t) => array = "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 = - "formatRangeToParts" +external formatRangeToParts: ( + t, + ~startDate: Stdlib_Date.t, + ~endDate: Stdlib_Date.t, +) => array = "formatRangeToParts" diff --git a/runtime/Js_date.res b/runtime/Js_date.res index 2a7b6be24b..0892211745 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 = Stdlib_Date.t @send /** diff --git a/runtime/JsxDOM.res b/runtime/JsxDOM.res index aca2a0570b..ea1c407d5b 100644 --- a/runtime/JsxDOM.res +++ b/runtime/JsxDOM.res @@ -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, diff --git a/runtime/Stdlib.res b/runtime/Stdlib.res new file mode 100644 index 0000000000..74e9e76b5c --- /dev/null +++ b/runtime/Stdlib.res @@ -0,0 +1,4 @@ +module Date = Stdlib_Date + +// Aliases for convenience +type date = Date.t diff --git a/runtime/Date.res b/runtime/Stdlib_Date.res similarity index 99% rename from runtime/Date.res rename to runtime/Stdlib_Date.res index 925afcc190..02ffee6d89 100644 --- a/runtime/Date.res +++ b/runtime/Stdlib_Date.res @@ -1,4 +1,4 @@ -type t = Js.Date.t +type t type msSinceEpoch = float diff --git a/runtime/Date.resi b/runtime/Stdlib_Date.resi similarity index 99% rename from runtime/Date.resi rename to runtime/Stdlib_Date.resi index f0d975ba1a..1e67a96c1a 100644 --- a/runtime/Date.resi +++ b/runtime/Stdlib_Date.resi @@ -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). diff --git a/tests/analysis_tests/tests/src/expected/CompletionTypeT.res.txt b/tests/analysis_tests/tests/src/expected/CompletionTypeT.res.txt index 975d97d3e9..7d95210cc9 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionTypeT.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionTypeT.res.txt @@ -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 }] @@ -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 }]