From df07a056adb92f4607e054577d36c54ac26b68d5 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 25 Jul 2024 02:55:04 +0900 Subject: [PATCH 1/2] Add `Js.globalThis` object binding --- jscomp/others/js.res | 3 +++ jscomp/runtime/js.res | 3 +++ 2 files changed, 6 insertions(+) diff --git a/jscomp/others/js.res b/jscomp/others/js.res index 10ce264026..6f828e95eb 100644 --- a/jscomp/others/js.res +++ b/jscomp/others/js.res @@ -77,6 +77,9 @@ Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latt /** JS object type */ type t<'a> = {..} as 'a +/** JS global object reference */ +@val external globalThis: t<'a> = "globalThis" + /** Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t. */ diff --git a/jscomp/runtime/js.res b/jscomp/runtime/js.res index 420be9c836..2958a8012b 100644 --- a/jscomp/runtime/js.res +++ b/jscomp/runtime/js.res @@ -77,6 +77,9 @@ Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latt /** JS object type */ type t<'a> = {..} as 'a +/** JS global object reference */ +@val external globalThis: t<'a> = "globalThis" + /** Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t. */ From 1b9a5049ed292adaff1123342ef8c663c2f4ac3c Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 25 Jul 2024 03:03:57 +0900 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba2a0b5c2b..2ca2742683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Allow `private` in with constraints. https://github.com/rescript-lang/rescript-compiler/pull/6843 - Add regex literals as syntax sugar for `@bs.re`. https://github.com/rescript-lang/rescript-compiler/pull/6776 - Improved mechanism to determine arity of externals, which is consistent however the type is written. https://github.com/rescript-lang/rescript-compiler/pull/6874 https://github.com/rescript-lang/rescript-compiler/pull/6881 https://github.com/rescript-lang/rescript-compiler/pull/6883 +- Add `Js.globalThis` object binding. https://github.com/rescript-lang/rescript-compiler/pull/6909 #### :boom: Breaking Change