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:
parent
0cb00a6e89
commit
ef3e4a8f74
8 changed files with 48 additions and 0 deletions
|
@ -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`."),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
19
tests/specs/run/window/__test__.jsonc
Normal file
19
tests/specs/run/window/__test__.jsonc
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
1
tests/specs/run/window/window1.js
Normal file
1
tests/specs/run/window/window1.js
Normal file
|
@ -0,0 +1 @@
|
|||
"TextEncoder" in window;
|
7
tests/specs/run/window/window1.out
Normal file
7
tests/specs/run/window/window1.out
Normal 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`.
|
1
tests/specs/run/window/window2.js
Normal file
1
tests/specs/run/window/window2.js
Normal file
|
@ -0,0 +1 @@
|
|||
window.atob;
|
7
tests/specs/run/window/window2.out
Normal file
7
tests/specs/run/window/window2.out
Normal 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`.
|
1
tests/specs/run/window/window3.js
Normal file
1
tests/specs/run/window/window3.js
Normal file
|
@ -0,0 +1 @@
|
|||
window.navigator;
|
7
tests/specs/run/window/window3.out
Normal file
7
tests/specs/run/window/window3.out
Normal 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`.
|
Loading…
Reference in a new issue