Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate %external extension #6906

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
- Improve unused attribute warning message. https://github.com/rescript-lang/rescript-compiler/pull/6787
- Remove internal option `use-stdlib` from build schema. https://github.com/rescript-lang/rescript-compiler/pull/6778
- Fix `Js.Types.JSBigInt` payload to use native `bigint` type. https://github.com/rescript-lang/rescript-compiler/pull/6911
- Deprecate `%external` extension, which has never been officially introduced. https://github.com/rescript-lang/rescript-compiler/pull/6906

# 11.1.2

Expand Down
9 changes: 3 additions & 6 deletions jscomp/frontend/ast_exp_extension.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
(Ast_exp_handle_external.handle_raw ~kind:Raw_re loc payload)
(Ast_comb.to_js_re_type loc)
| "external" -> (
Location.deprecated loc
"%external is deprecated, use %raw or regular FFI syntax instead.";
match Ast_payload.as_ident payload with
| Some {txt = Lident x} ->
Ast_exp_handle_external.handle_external loc x
(* do we need support [%external gg.xx ]

{[ Js.Undefined.to_opt (if Js.typeof x == "undefined" then x else Js.Undefined.empty ) ]}
*)
| Some {txt = Lident x} -> Ast_exp_handle_external.handle_external loc x
| None | Some _ ->
Location.raise_errorf ~loc "external expects a single identifier")
| "time" -> (
Expand Down
4 changes: 3 additions & 1 deletion jscomp/frontend/ast_exp_handle_external.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@

open Ast_helper

(*
(**
{[
Js.undefinedToOption
(if Js.typeof x = "undefined" then undefined
else x )

]}

@deprecated
*)
let handle_external loc (x : string) : Parsetree.expression =
let raw_exp : Ast_exp.t =
Expand Down
3 changes: 1 addition & 2 deletions jscomp/test/build.ninja

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions jscomp/test/reasonReactRouter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 20 additions & 14 deletions jscomp/test/reasonReactRouter.res
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ external createEventNonIEBrowsers: string => Dom.event = "createEvent"
@send
external initEventNonIEBrowsers: (Dom.event, string, bool, bool) => unit = "initEvent"

@val @scope("globalThis")
external window: option<Dom.window> = "window"

@val @scope("globalThis")
external history: option<Dom.history> = "history"

let safeMakeEvent = eventName =>
if Js.typeof(event) == "function" {
makeEventIE11Compatible(eventName)
Expand Down Expand Up @@ -60,9 +66,9 @@ let arrayToList = a => {
/* actually you know what, not gonna provide search for now. It's a mess.
We'll let users roll their own solution/data structure for now */
let path = () =>
switch %external(window) {
switch window {
| None => list{}
| Some(window: Dom.window) =>
| Some(window) =>
switch window |> location |> pathname {
| ""
| "/" => list{}
Expand All @@ -78,9 +84,9 @@ let path = () =>
}
}
let hash = () =>
switch %external(window) {
switch window {
| None => ""
| Some(window: Dom.window) =>
| Some(window) =>
switch window |> location |> hash {
| ""
| "#" => ""
Expand All @@ -91,9 +97,9 @@ let hash = () =>
}
}
let search = () =>
switch %external(window) {
switch window {
| None => ""
| Some(window: Dom.window) =>
| Some(window) =>
switch window |> location |> search {
| ""
| "?" => ""
Expand All @@ -103,18 +109,18 @@ let search = () =>
}
}
let push = path =>
switch (%external(history), %external(window)) {
switch (history, window) {
| (None, _)
| (_, None) => ()
| (Some(history: Dom.history), Some(window: Dom.window)) =>
| (Some(history), Some(window)) =>
pushState(history, ~href=path)
dispatchEvent(window, safeMakeEvent("popstate"))
}
let replace = path =>
switch (%external(history), %external(window)) {
switch (history, window) {
| (None, _)
| (_, None) => ()
| (Some(history: Dom.history), Some(window: Dom.window)) =>
| (Some(history), Some(window)) =>
replaceState(history, ~href=path)
dispatchEvent(window, safeMakeEvent("popstate"))
}
Expand Down Expand Up @@ -143,17 +149,17 @@ let url = () => {path: path(), hash: hash(), search: search()}
/* alias exposed publicly */
let dangerouslyGetInitialUrl = url
let watchUrl = callback =>
switch %external(window) {
switch window {
| None => () => ()
| Some(window: Dom.window) =>
| Some(window) =>
let watcherID = () => callback(url())
addEventListener(window, "popstate", watcherID)
watcherID
}
let unwatchUrl = watcherID =>
switch %external(window) {
switch window {
| None => ()
| Some(window: Dom.window) => removeEventListener(window, "popstate", watcherID)
| Some(window) => removeEventListener(window, "popstate", watcherID)
}

let useUrl = (~serverUrl=?, ()) => {
Expand Down
97 changes: 0 additions & 97 deletions jscomp/test/undef_regression2_test.js

This file was deleted.

44 changes: 0 additions & 44 deletions jscomp/test/undef_regression2_test.res

This file was deleted.