mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
Improved typechecking error for unstable props (#5503)
This commit is contained in:
parent
2668637e9b
commit
02a6720527
2 changed files with 78 additions and 4 deletions
|
@ -10,6 +10,79 @@ import {
|
||||||
DiagnosticItem,
|
DiagnosticItem,
|
||||||
} from "./diagnostics.ts";
|
} from "./diagnostics.ts";
|
||||||
|
|
||||||
|
const unstableDenoGlobalProperties = [
|
||||||
|
"umask",
|
||||||
|
"linkSync",
|
||||||
|
"link",
|
||||||
|
"symlinkSync",
|
||||||
|
"symlink",
|
||||||
|
"DirKind",
|
||||||
|
"dir",
|
||||||
|
"loadavg",
|
||||||
|
"osRelease",
|
||||||
|
"openPlugin",
|
||||||
|
"DiagnosticCategory",
|
||||||
|
"DiagnosticMessageChain",
|
||||||
|
"DiagnosticItem",
|
||||||
|
"Diagnostic",
|
||||||
|
"formatDiagnostics",
|
||||||
|
"CompilerOptions",
|
||||||
|
"TranspileOnlyResult",
|
||||||
|
"transpileOnly",
|
||||||
|
"compile",
|
||||||
|
"bundle",
|
||||||
|
"Location",
|
||||||
|
"applySourceMap",
|
||||||
|
"LinuxSignal",
|
||||||
|
"MacOSSignal",
|
||||||
|
"Signal",
|
||||||
|
"SignalStream",
|
||||||
|
"signal",
|
||||||
|
"signals",
|
||||||
|
"setRaw",
|
||||||
|
"utimeSync",
|
||||||
|
"utime",
|
||||||
|
"ShutdownMode",
|
||||||
|
"shutdown",
|
||||||
|
"DatagramConn",
|
||||||
|
"UnixListenOptions",
|
||||||
|
"listen",
|
||||||
|
"listenDatagram",
|
||||||
|
"UnixConnectOptions",
|
||||||
|
"connect",
|
||||||
|
"StartTlsOptions",
|
||||||
|
"startTls",
|
||||||
|
"kill",
|
||||||
|
"PermissionName",
|
||||||
|
"PermissionState",
|
||||||
|
"RunPermissionDescriptor",
|
||||||
|
"ReadPermissionDescriptor",
|
||||||
|
"WritePermissionDescriptor",
|
||||||
|
"NetPermissionDescriptor",
|
||||||
|
"EnvPermissionDescriptor",
|
||||||
|
"PluginPermissionDescriptor",
|
||||||
|
"HrtimePermissionDescriptor",
|
||||||
|
"PermissionDescriptor",
|
||||||
|
"Permissions",
|
||||||
|
"PermissionStatus",
|
||||||
|
"hostname",
|
||||||
|
];
|
||||||
|
|
||||||
|
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?`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messageText;
|
||||||
|
}
|
||||||
|
|
||||||
interface SourceInformation {
|
interface SourceInformation {
|
||||||
sourceLine: string;
|
sourceLine: string;
|
||||||
lineNumber: number;
|
lineNumber: number;
|
||||||
|
@ -78,7 +151,8 @@ function fromDiagnosticMessageChain(
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageChain.map(({ messageText: message, code, category, next }) => {
|
return messageChain.map(({ messageText, code, category, next }) => {
|
||||||
|
const message = transformMessageText(messageText, code);
|
||||||
return {
|
return {
|
||||||
message,
|
message,
|
||||||
code,
|
code,
|
||||||
|
@ -110,9 +184,9 @@ function parseDiagnostic(
|
||||||
let message: string;
|
let message: string;
|
||||||
let messageChain: DiagnosticMessageChain | undefined;
|
let messageChain: DiagnosticMessageChain | undefined;
|
||||||
if (typeof messageText === "string") {
|
if (typeof messageText === "string") {
|
||||||
message = messageText;
|
message = transformMessageText(messageText, code);
|
||||||
} else {
|
} else {
|
||||||
message = messageText.messageText;
|
message = transformMessageText(messageText.messageText, messageText.code);
|
||||||
messageChain = fromDiagnosticMessageChain([messageText])![0];
|
messageChain = fromDiagnosticMessageChain([messageText])![0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
error: TS2339 [ERROR]: Property 'loadavg' does not exist on type 'typeof Deno'.
|
error: TS2339 [ERROR]: Property 'loadavg' does not exist on type 'typeof Deno'. 'Deno.loadavg' is an unstable API. Did you forget to run with the '--unstable' flag?
|
||||||
console.log(Deno.loadavg);
|
console.log(Deno.loadavg);
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
at [WILDCARD]/cli/tests/unstable.ts:1:18
|
at [WILDCARD]/cli/tests/unstable.ts:1:18
|
||||||
|
|
Loading…
Add table
Reference in a new issue