Skip to content

Commit 3c10463

Browse files
committed
just deprecate %external
1 parent 5373886 commit 3c10463

13 files changed

+42
-209
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
- Improve unused attribute warning message. https://github.com/rescript-lang/rescript-compiler/pull/6787
8888
- Remove internal option `use-stdlib` from build schema. https://github.com/rescript-lang/rescript-compiler/pull/6778
8989
- Fix `Js.Types.JSBigInt` payload to use native `bigint` type. https://github.com/rescript-lang/rescript-compiler/pull/6911
90+
- Deprecate `%external` extension, which has never been officially introduced. https://github.com/rescript-lang/rescript-compiler/pull/6906
9091

9192
# 11.1.2
9293

Diff for: jscomp/frontend/ast_exp_extension.ml

+4-12
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,11 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
6161
Exp.constraint_ ~loc
6262
(Ast_exp_handle_external.handle_raw ~kind:Raw_re loc payload)
6363
(Ast_comb.to_js_re_type loc)
64-
| "global" | "external" -> (
65-
if txt = "external" then
66-
Location.deprecated loc
67-
"%external is deprecated, use %global or %define instead.";
64+
| "external" -> (
65+
Location.deprecated loc
66+
"%external is deprecated, use %raw or regular FFI syntax instead.";
6867
match Ast_payload.as_ident payload with
69-
| Some {txt = Lident x} -> Ast_exp_handle_external.handle_global loc x
70-
| None | Some _ ->
71-
Location.raise_errorf ~loc "external expects a single identifier")
72-
| "define" -> (
73-
match Ast_payload.as_ident payload with
74-
| Some {txt = Lident x} ->
75-
Ast_exp_handle_external.handle_define loc x
76-
(* TODO: we need to support %define(gg.xx) *)
68+
| Some {txt = Lident x} -> Ast_exp_handle_external.handle_external loc x
7769
| None | Some _ ->
7870
Location.raise_errorf ~loc "external expects a single identifier")
7971
| "time" -> (

Diff for: jscomp/frontend/ast_exp_handle_external.ml

+3-20
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,16 @@
2525
open Ast_helper
2626

2727
(**
28-
{[ Js.undefinedToOption (Js.globalThis["x"]) ]}
29-
*)
30-
let handle_global loc (x : string) : Parsetree.expression =
31-
let global_reference : Parsetree.expression =
32-
{
33-
pexp_loc = loc;
34-
pexp_attributes = [];
35-
pexp_desc =
36-
Ast_util.js_property loc
37-
(Exp.ident {loc; txt = Ldot (Lident "Js", "globalThis")})
38-
x;
39-
}
40-
in
41-
let undefined_typeof =
42-
Exp.ident {loc; txt = Ldot (Lident "Js", "undefinedToOption")}
43-
in
44-
Ast_compatible.app1 ~loc undefined_typeof global_reference
45-
46-
(*
4728
{[
4829
Js.undefinedToOption
4930
(if Js.typeof x = "undefined" then undefined
5031
else x )
5132
5233
]}
34+
35+
@deprecated
5336
*)
54-
let handle_define loc (x : string) : Parsetree.expression =
37+
let handle_external loc (x : string) : Parsetree.expression =
5538
let raw_exp : Ast_exp.t =
5639
let str_exp =
5740
Ast_compatible.const_exp_string ~loc x ~delimiter:Ext_string.empty

Diff for: jscomp/frontend/ast_exp_handle_external.mli

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
val handle_global : Location.t -> string -> Parsetree.expression
26-
27-
val handle_define : Location.t -> string -> Parsetree.expression
25+
val handle_external : Location.t -> string -> Parsetree.expression
2826

2927
val handle_debugger : Location.t -> Ast_payload.t -> Parsetree.expression_desc
3028

Diff for: jscomp/others/js.res

-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latt
7777
/** JS object type */
7878
type t<'a> = {..} as 'a
7979

80-
/** JS global object reference */
81-
@val external globalThis: t<'a> = "globalThis"
82-
8380
/**
8481
Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t.
8582
*/

Diff for: jscomp/runtime/js.res

-3
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latt
7777
/** JS object type */
7878
type t<'a> = {..} as 'a
7979

80-
/** JS global object reference */
81-
@val external globalThis: t<'a> = "globalThis"
82-
8380
/**
8481
Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t.
8582
*/

Diff for: jscomp/test/build.ninja

+1-2
Large diffs are not rendered by default.

Diff for: jscomp/test/reasonReactRouter.js

+10-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: jscomp/test/reasonReactRouter.res

+20-14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ external createEventNonIEBrowsers: string => Dom.event = "createEvent"
3333
@send
3434
external initEventNonIEBrowsers: (Dom.event, string, bool, bool) => unit = "initEvent"
3535

36+
@val @scope("globalThis")
37+
external window: option<Dom.window> = "window"
38+
39+
@val @scope("globalThis")
40+
external history: option<Dom.history> = "history"
41+
3642
let safeMakeEvent = eventName =>
3743
if Js.typeof(event) == "function" {
3844
makeEventIE11Compatible(eventName)
@@ -60,9 +66,9 @@ let arrayToList = a => {
6066
/* actually you know what, not gonna provide search for now. It's a mess.
6167
We'll let users roll their own solution/data structure for now */
6268
let path = () =>
63-
switch %global(window) {
69+
switch window {
6470
| None => list{}
65-
| Some(window: Dom.window) =>
71+
| Some(window) =>
6672
switch window |> location |> pathname {
6773
| ""
6874
| "/" => list{}
@@ -78,9 +84,9 @@ let path = () =>
7884
}
7985
}
8086
let hash = () =>
81-
switch %global(window) {
87+
switch window {
8288
| None => ""
83-
| Some(window: Dom.window) =>
89+
| Some(window) =>
8490
switch window |> location |> hash {
8591
| ""
8692
| "#" => ""
@@ -91,9 +97,9 @@ let hash = () =>
9197
}
9298
}
9399
let search = () =>
94-
switch %global(window) {
100+
switch window {
95101
| None => ""
96-
| Some(window: Dom.window) =>
102+
| Some(window) =>
97103
switch window |> location |> search {
98104
| ""
99105
| "?" => ""
@@ -103,18 +109,18 @@ let search = () =>
103109
}
104110
}
105111
let push = path =>
106-
switch (%global(history), %global(window)) {
112+
switch (history, window) {
107113
| (None, _)
108114
| (_, None) => ()
109-
| (Some(history: Dom.history), Some(window: Dom.window)) =>
115+
| (Some(history), Some(window)) =>
110116
pushState(history, ~href=path)
111117
dispatchEvent(window, safeMakeEvent("popstate"))
112118
}
113119
let replace = path =>
114-
switch (%global(history), %global(window)) {
120+
switch (history, window) {
115121
| (None, _)
116122
| (_, None) => ()
117-
| (Some(history: Dom.history), Some(window: Dom.window)) =>
123+
| (Some(history), Some(window)) =>
118124
replaceState(history, ~href=path)
119125
dispatchEvent(window, safeMakeEvent("popstate"))
120126
}
@@ -143,17 +149,17 @@ let url = () => {path: path(), hash: hash(), search: search()}
143149
/* alias exposed publicly */
144150
let dangerouslyGetInitialUrl = url
145151
let watchUrl = callback =>
146-
switch %global(window) {
152+
switch window {
147153
| None => () => ()
148-
| Some(window: Dom.window) =>
154+
| Some(window) =>
149155
let watcherID = () => callback(url())
150156
addEventListener(window, "popstate", watcherID)
151157
watcherID
152158
}
153159
let unwatchUrl = watcherID =>
154-
switch %global(window) {
160+
switch window {
155161
| None => ()
156-
| Some(window: Dom.window) => removeEventListener(window, "popstate", watcherID)
162+
| Some(window) => removeEventListener(window, "popstate", watcherID)
157163
}
158164

159165
let useUrl = (~serverUrl=?, ()) => {

Diff for: jscomp/test/undef_regression2_test.js

-97
This file was deleted.

0 commit comments

Comments
 (0)