@stateward/plugin-errors 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/async-handler-unhandled.d.ts +7 -0
- package/dist/async-handler-unhandled.js +342 -0
- package/dist/catch-hides-unexpected.d.ts +6 -0
- package/dist/catch-hides-unexpected.js +260 -0
- package/dist/catch-misses-error.d.ts +6 -0
- package/dist/catch-misses-error.js +208 -0
- package/dist/catch-without-intent.d.ts +10 -0
- package/dist/catch-without-intent.js +590 -0
- package/dist/exhaustive-catch.d.ts +6 -0
- package/dist/exhaustive-catch.js +190 -0
- package/dist/exhaustive-fallback.d.ts +6 -0
- package/dist/exhaustive-fallback.js +157 -0
- package/dist/finally-can-throw.d.ts +6 -0
- package/dist/finally-can-throw.js +184 -0
- package/dist/finally-may-throw.d.ts +6 -0
- package/dist/finally-may-throw.js +184 -0
- package/dist/hover.d.ts +11 -0
- package/dist/hover.js +62 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -0
- package/dist/inference/builtins.d.ts +52 -0
- package/dist/inference/builtins.js +179 -0
- package/dist/inference/catches.d.ts +9 -0
- package/dist/inference/catches.js +33 -0
- package/dist/inference/deps.d.ts +12 -0
- package/dist/inference/deps.js +79 -0
- package/dist/inference/format.d.ts +25 -0
- package/dist/inference/format.js +72 -0
- package/dist/inference/packages.d.ts +40 -0
- package/dist/inference/packages.js +723 -0
- package/dist/inference/project.d.ts +8 -0
- package/dist/inference/project.js +22 -0
- package/dist/inference/solve.d.ts +128 -0
- package/dist/inference/solve.js +575 -0
- package/dist/inference/summarize.d.ts +50 -0
- package/dist/inference/summarize.js +1324 -0
- package/dist/inference/summary.d.ts +191 -0
- package/dist/inference/summary.js +237 -0
- package/dist/inlay.d.ts +19 -0
- package/dist/inlay.js +168 -0
- package/dist/must-handle-error.d.ts +55 -0
- package/dist/must-handle-error.js +794 -0
- package/dist/narrow-try.d.ts +52 -0
- package/dist/narrow-try.js +641 -0
- package/dist/no-swallow.d.ts +8 -0
- package/dist/no-swallow.js +320 -0
- package/dist/plugin.d.ts +116 -0
- package/dist/plugin.js +39 -0
- package/dist/react/boundaries.d.ts +83 -0
- package/dist/react/boundaries.js +371 -0
- package/dist/react/fallbacks.d.ts +12 -0
- package/dist/react/fallbacks.js +83 -0
- package/dist/react/render-guards.d.ts +24 -0
- package/dist/react/render-guards.js +271 -0
- package/dist/react/tree.d.ts +98 -0
- package/dist/react/tree.js +863 -0
- package/dist/refactors.d.ts +15 -0
- package/dist/refactors.js +69 -0
- package/dist/render-throw-without-boundary.d.ts +11 -0
- package/dist/render-throw-without-boundary.js +223 -0
- package/dist/render-throws-without-boundary.d.ts +6 -0
- package/dist/render-throws-without-boundary.js +151 -0
- package/dist/result-ignored.d.ts +6 -0
- package/dist/result-ignored.js +167 -0
- package/dist/result-type.d.ts +18 -0
- package/dist/result-type.js +55 -0
- package/dist/result-unchecked.d.ts +2 -0
- package/dist/result-unchecked.js +746 -0
- package/dist/rethrow-unknown.d.ts +6 -0
- package/dist/rethrow-unknown.js +260 -0
- package/dist/rules.meta.d.ts +214 -0
- package/dist/rules.meta.js +212 -0
- package/dist/syntax.d.ts +41 -0
- package/dist/syntax.js +171 -0
- package/dist/text.d.ts +22 -0
- package/dist/text.js +43 -0
- package/dist/throw-in-hook.d.ts +8 -0
- package/dist/throw-in-hook.js +510 -0
- package/dist/throws-doc-mismatch.d.ts +7 -0
- package/dist/throws-doc-mismatch.js +188 -0
- package/dist/throws-matches-doc.d.ts +7 -0
- package/dist/throws-matches-doc.js +188 -0
- package/package.json +34 -3
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { builtinCatchName, builtinName, isBuiltin } from "./builtins.js";
|
|
2
|
+
/** At most this many unknown sources are listed; the rest are counted. */
|
|
3
|
+
const MAX_LISTED_SOURCES = 5;
|
|
4
|
+
const PACKAGE_CLASS = /^package:.+#(?<name>[^#]+)$/;
|
|
5
|
+
/** A class's name from its id when no facts are known about it (`package:zod#ZodError`). */
|
|
6
|
+
function nameOfId(id) {
|
|
7
|
+
return PACKAGE_CLASS.exec(id)?.groups?.name ?? id;
|
|
8
|
+
}
|
|
9
|
+
/** How a class is shown: its name, `AbortError (DOMException)` for a named DOMException. */
|
|
10
|
+
export function className(id, classes) {
|
|
11
|
+
return isBuiltin(id) ? builtinName(id) : (classes.get(id)?.name ?? nameOfId(id));
|
|
12
|
+
}
|
|
13
|
+
/** The name an `instanceof` test or a `@throws` tag uses for the class. */
|
|
14
|
+
export function catchName(id, classes) {
|
|
15
|
+
return isBuiltin(id) ? builtinCatchName(id) : (classes.get(id)?.name ?? nameOfId(id));
|
|
16
|
+
}
|
|
17
|
+
function sourceKey(source) {
|
|
18
|
+
return `${source.file}:${String(source.start)}:${source.reason}`;
|
|
19
|
+
}
|
|
20
|
+
/** `api.get: no declaration`. */
|
|
21
|
+
function sourceText(source) {
|
|
22
|
+
return `${source.text}: ${source.reason}`;
|
|
23
|
+
}
|
|
24
|
+
/** `others stateward cannot see (from a: why; b: why; and 3 more)`. */
|
|
25
|
+
export function unknownText(sources, more) {
|
|
26
|
+
const listed = sources.slice(0, MAX_LISTED_SOURCES).map(sourceText);
|
|
27
|
+
const rest = sources.length - listed.length;
|
|
28
|
+
const tail = rest > 0 || more ? [`and ${String(rest)}${more ? "+" : ""} more`] : [];
|
|
29
|
+
return `others stateward cannot see (from ${[...listed, ...tail].join("; ")})`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `ParseError | ZodError (zod 3.23.8: declared) | others stateward cannot see (from …)`, or "" for an empty set: a class
|
|
33
|
+
* known from a package's facts names where they come from.
|
|
34
|
+
*/
|
|
35
|
+
export function thrownText(thrown, classes) {
|
|
36
|
+
const shown = (id) => {
|
|
37
|
+
const origin = thrown.origins.get(id);
|
|
38
|
+
const name = className(id, classes);
|
|
39
|
+
return origin === undefined ? name : `${name} (${origin})`;
|
|
40
|
+
};
|
|
41
|
+
const names = [...new Set([...thrown.classes.keys()].map(shown))].sort();
|
|
42
|
+
const parts = thrown.unknowns.length > 0 || thrown.more
|
|
43
|
+
? [...names, unknownText(thrown.unknowns, thrown.more)]
|
|
44
|
+
: names;
|
|
45
|
+
return parts.join(" | ");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* What a call's promise rejects with, without the unknown parts already listed as thrown: an
|
|
49
|
+
* unknown call is both thrown and returned when stateward cannot tell whether it gives a promise,
|
|
50
|
+
* and is shown once, where it is thrown.
|
|
51
|
+
*/
|
|
52
|
+
export function rejectsShown(result) {
|
|
53
|
+
const shown = new Set(result.throws.unknowns.map(sourceKey));
|
|
54
|
+
return {
|
|
55
|
+
...result.rejects,
|
|
56
|
+
unknowns: result.rejects.unknowns.filter((s) => !shown.has(sourceKey(s))),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The hover's lines: `throws: …` for what a call throws, `rejects: …` for what its promise
|
|
61
|
+
* rejects with, `throws nothing stateward can see` when both are empty.
|
|
62
|
+
*/
|
|
63
|
+
export function resultLines(result, classes) {
|
|
64
|
+
const throws = thrownText(result.throws, classes);
|
|
65
|
+
const rejects = thrownText(rejectsShown(result), classes);
|
|
66
|
+
const lines = [
|
|
67
|
+
...(throws === "" ? [] : [`throws: ${throws}`]),
|
|
68
|
+
...(rejects === "" ? [] : [`rejects: ${rejects}`]),
|
|
69
|
+
];
|
|
70
|
+
return lines.length === 0 ? ["throws nothing stateward can see"] : lines;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ts from "@stateward/core/typescript";
|
|
2
|
+
import type { FileContext } from "@stateward/core";
|
|
3
|
+
import type { PackageResolver } from "./summarize.js";
|
|
4
|
+
/**
|
|
5
|
+
* Library facts for the Errors pack: what a call into a
|
|
6
|
+
* package throws, from the first source that answers:
|
|
7
|
+
*
|
|
8
|
+
* 1. the project's config (`facts`);
|
|
9
|
+
* 2. curated fact files shipped with stateward (`curatedFacts` answers nothing yet);
|
|
10
|
+
* 3. `@throws {X}` on the called declaration in the package's `.d.ts`;
|
|
11
|
+
* 4. inferred from the package's JavaScript, with the summarizer of the project's own code, from
|
|
12
|
+
* the called function to what it calls in the package (bounded), cached globally;
|
|
13
|
+
* 5. unknown, with one of the reasons below.
|
|
14
|
+
*/
|
|
15
|
+
/** Why a package's function is not (fully) known: fixed strings, shown as they are. */
|
|
16
|
+
export declare const UNKNOWN_REASONS: readonly ["no readable source", "not found in its source", "native addon", "minified", "eval", "dynamic require", "too large to follow", "untyped @throws", "calls a callback", "calls code it cannot see", "dynamic call", "throws a value of unknown class", "awaits a promise it cannot follow"];
|
|
17
|
+
export type UnknownReason = (typeof UNKNOWN_REASONS)[number];
|
|
18
|
+
/**
|
|
19
|
+
* At most this many functions are read per package function asked for.
|
|
20
|
+
* The bounds count, never time: a verdict by time would differ between machines.
|
|
21
|
+
*/
|
|
22
|
+
export declare const MAX_FUNCTIONS = 200;
|
|
23
|
+
/** The declaration's path in the package's types: `["Client", "get"]`. */
|
|
24
|
+
export declare function pathOf(node: ts.Node): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Curated fact files shipped with stateward: none ship yet, so nothing answers between the config
|
|
27
|
+
* and the declarations. Reading `facts/<package>@<major>.json` here would add the `curated`
|
|
28
|
+
* source, and the resolver would ask it after the config.
|
|
29
|
+
*/
|
|
30
|
+
export declare function curatedFacts(): undefined;
|
|
31
|
+
/** What this process computed and read back, for tests: inference runs and global-cache hits. */
|
|
32
|
+
export declare function packageFactsStats(): {
|
|
33
|
+
inferences: number;
|
|
34
|
+
cacheHits: number;
|
|
35
|
+
};
|
|
36
|
+
/** Forgets what this process knows about packages (tests: the next run reads the global cache). */
|
|
37
|
+
export declare function forgetPackageFacts(): void;
|
|
38
|
+
/** Finds the facts of the calls into packages of the file `ctx` summarizes. */
|
|
39
|
+
export declare function packageResolver(ctx: Pick<FileContext, "file" | "facts">): PackageResolver;
|
|
40
|
+
//# sourceMappingURL=packages.d.ts.map
|