1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

feat: Show hints when using window global (#25805)

This commit adds better handling for terminal errors when
`window` global is used. This global is removed in Deno 2,
and while we have lints to help with that, an information and
hints are helpful to guide users to working code.

Ref https://github.com/denoland/deno/issues/25797
This commit is contained in:
Bartek Iwańczuk 2024-09-22 23:05:42 +01:00 committed by GitHub
parent 0cb00a6e89
commit ef3e4a8f74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 48 additions and 0 deletions

View file

@ -380,6 +380,11 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
"Run again with `--unstable-broadcast-channel` flag to enable this API.",
),
];
} else if msg.contains("window is not defined") {
return vec![
FixSuggestion::info("window global is not available in Deno 2."),
FixSuggestion::hint("Replace `window` with `globalThis`."),
];
}
}

View file

@ -0,0 +1,19 @@
{
"tests": {
"window1": {
"args": "run window1.js",
"exitCode": 1,
"output": "window1.out"
},
"window2": {
"args": "run window2.js",
"exitCode": 1,
"output": "window2.out"
},
"window3": {
"args": "run window3.js",
"exitCode": 1,
"output": "window3.out"
}
}
}

View file

@ -0,0 +1 @@
"TextEncoder" in window;

View file

@ -0,0 +1,7 @@
error: Uncaught (in promise) ReferenceError: window is not defined
"TextEncoder" in window;
^
at [WILDCARD]window1.js:1:18
info: window global is not available in Deno 2.
hint: Replace `window` with `globalThis`.

View file

@ -0,0 +1 @@
window.atob;

View file

@ -0,0 +1,7 @@
error: Uncaught (in promise) ReferenceError: window is not defined
window.atob;
^
at [WILDCARD]window2.js:1:1
info: window global is not available in Deno 2.
hint: Replace `window` with `globalThis`.

View file

@ -0,0 +1 @@
window.navigator;

View file

@ -0,0 +1,7 @@
error: Uncaught (in promise) ReferenceError: window is not defined
window.navigator;
^
at [WILDCARD]window3.js:1:1
info: window global is not available in Deno 2.
hint: Replace `window` with `globalThis`.