mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(Deno.ppid): improve error message when --unstable is missing (#6717)
This commit is contained in:
parent
1a96a96e10
commit
4731f4800c
4 changed files with 49 additions and 9 deletions
|
@ -64,20 +64,43 @@ const unstableDenoGlobalProperties = [
|
|||
"Permissions",
|
||||
"PermissionStatus",
|
||||
"hostname",
|
||||
"ppid",
|
||||
];
|
||||
|
||||
function transformMessageText(messageText: string, code: number): string {
|
||||
if (code === 2339) {
|
||||
const property = messageText
|
||||
.replace(/^Property '/, "")
|
||||
.replace(/' does not exist on type 'typeof Deno'\.$/, "");
|
||||
if (
|
||||
messageText.endsWith("on type 'typeof Deno'.") &&
|
||||
unstableDenoGlobalProperties.includes(property)
|
||||
) {
|
||||
return `${messageText} 'Deno.${property}' is an unstable API. Did you forget to run with the '--unstable' flag?`;
|
||||
switch (code) {
|
||||
case 2339: {
|
||||
const property = messageText
|
||||
.replace(/^Property '/, "")
|
||||
.replace(/' does not exist on type 'typeof Deno'\./, "");
|
||||
|
||||
if (
|
||||
messageText.endsWith("on type 'typeof Deno'.") &&
|
||||
unstableDenoGlobalProperties.includes(property)
|
||||
) {
|
||||
return `${messageText} 'Deno.${property}' is an unstable API. Did you forget to run with the '--unstable' flag?`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2551: {
|
||||
const suggestionMessagePattern = / Did you mean '(.+)'\?$/;
|
||||
const property = messageText
|
||||
.replace(/^Property '/, "")
|
||||
.replace(/' does not exist on type 'typeof Deno'\./, "")
|
||||
.replace(suggestionMessagePattern, "");
|
||||
const suggestion = messageText.match(suggestionMessagePattern);
|
||||
const replacedMessageText = messageText.replace(
|
||||
suggestionMessagePattern,
|
||||
""
|
||||
);
|
||||
if (suggestion && unstableDenoGlobalProperties.includes(property)) {
|
||||
const suggestedProperty = suggestion[1];
|
||||
return `${replacedMessageText} 'Deno.${property}' is an unstable API. Did you forget to run with the '--unstable' flag, or did you mean '${suggestedProperty}'?`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return messageText;
|
||||
}
|
||||
|
||||
|
|
|
@ -2073,6 +2073,12 @@ itest!(unstable_enabled_js {
|
|||
output: "unstable_enabled_js.out",
|
||||
});
|
||||
|
||||
itest!(unstable_disabled_ts2551 {
|
||||
args: "run --reload unstable_ts2551.ts",
|
||||
exit_code: 1,
|
||||
output: "unstable_disabled_ts2551.out",
|
||||
});
|
||||
|
||||
itest!(_053_import_compression {
|
||||
args: "run --quiet --reload --allow-net 053_import_compression/main.ts",
|
||||
output: "053_import_compression.out",
|
||||
|
|
10
cli/tests/unstable_disabled_ts2551.out
Normal file
10
cli/tests/unstable_disabled_ts2551.out
Normal file
|
@ -0,0 +1,10 @@
|
|||
[WILDCARD]
|
||||
error: TS2551 [ERROR]: Property 'ppid' does not exist on type 'typeof Deno'. 'Deno.ppid' is an unstable API. Did you forget to run with the '--unstable' flag, or did you mean 'pid'?
|
||||
console.log(Deno.ppid);
|
||||
~~~~
|
||||
at [WILDCARD]cli/tests/unstable_ts2551.ts:1:18
|
||||
|
||||
'pid' is declared here.
|
||||
export const pid: number;
|
||||
~~~
|
||||
at asset:///lib.deno.ns.d.ts:[WILDCARD]
|
1
cli/tests/unstable_ts2551.ts
Normal file
1
cli/tests/unstable_ts2551.ts
Normal file
|
@ -0,0 +1 @@
|
|||
console.log(Deno.ppid);
|
Loading…
Add table
Reference in a new issue