@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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/dist/async-handler-unhandled.d.ts +7 -0
  4. package/dist/async-handler-unhandled.js +342 -0
  5. package/dist/catch-hides-unexpected.d.ts +6 -0
  6. package/dist/catch-hides-unexpected.js +260 -0
  7. package/dist/catch-misses-error.d.ts +6 -0
  8. package/dist/catch-misses-error.js +208 -0
  9. package/dist/catch-without-intent.d.ts +10 -0
  10. package/dist/catch-without-intent.js +590 -0
  11. package/dist/exhaustive-catch.d.ts +6 -0
  12. package/dist/exhaustive-catch.js +190 -0
  13. package/dist/exhaustive-fallback.d.ts +6 -0
  14. package/dist/exhaustive-fallback.js +157 -0
  15. package/dist/finally-can-throw.d.ts +6 -0
  16. package/dist/finally-can-throw.js +184 -0
  17. package/dist/finally-may-throw.d.ts +6 -0
  18. package/dist/finally-may-throw.js +184 -0
  19. package/dist/hover.d.ts +11 -0
  20. package/dist/hover.js +62 -0
  21. package/dist/index.d.ts +7 -0
  22. package/dist/index.js +2 -0
  23. package/dist/inference/builtins.d.ts +52 -0
  24. package/dist/inference/builtins.js +179 -0
  25. package/dist/inference/catches.d.ts +9 -0
  26. package/dist/inference/catches.js +33 -0
  27. package/dist/inference/deps.d.ts +12 -0
  28. package/dist/inference/deps.js +79 -0
  29. package/dist/inference/format.d.ts +25 -0
  30. package/dist/inference/format.js +72 -0
  31. package/dist/inference/packages.d.ts +40 -0
  32. package/dist/inference/packages.js +723 -0
  33. package/dist/inference/project.d.ts +8 -0
  34. package/dist/inference/project.js +22 -0
  35. package/dist/inference/solve.d.ts +128 -0
  36. package/dist/inference/solve.js +575 -0
  37. package/dist/inference/summarize.d.ts +50 -0
  38. package/dist/inference/summarize.js +1324 -0
  39. package/dist/inference/summary.d.ts +191 -0
  40. package/dist/inference/summary.js +237 -0
  41. package/dist/inlay.d.ts +19 -0
  42. package/dist/inlay.js +168 -0
  43. package/dist/must-handle-error.d.ts +55 -0
  44. package/dist/must-handle-error.js +794 -0
  45. package/dist/narrow-try.d.ts +52 -0
  46. package/dist/narrow-try.js +641 -0
  47. package/dist/no-swallow.d.ts +8 -0
  48. package/dist/no-swallow.js +320 -0
  49. package/dist/plugin.d.ts +116 -0
  50. package/dist/plugin.js +39 -0
  51. package/dist/react/boundaries.d.ts +83 -0
  52. package/dist/react/boundaries.js +371 -0
  53. package/dist/react/fallbacks.d.ts +12 -0
  54. package/dist/react/fallbacks.js +83 -0
  55. package/dist/react/render-guards.d.ts +24 -0
  56. package/dist/react/render-guards.js +271 -0
  57. package/dist/react/tree.d.ts +98 -0
  58. package/dist/react/tree.js +863 -0
  59. package/dist/refactors.d.ts +15 -0
  60. package/dist/refactors.js +69 -0
  61. package/dist/render-throw-without-boundary.d.ts +11 -0
  62. package/dist/render-throw-without-boundary.js +223 -0
  63. package/dist/render-throws-without-boundary.d.ts +6 -0
  64. package/dist/render-throws-without-boundary.js +151 -0
  65. package/dist/result-ignored.d.ts +6 -0
  66. package/dist/result-ignored.js +167 -0
  67. package/dist/result-type.d.ts +18 -0
  68. package/dist/result-type.js +55 -0
  69. package/dist/result-unchecked.d.ts +2 -0
  70. package/dist/result-unchecked.js +746 -0
  71. package/dist/rethrow-unknown.d.ts +6 -0
  72. package/dist/rethrow-unknown.js +260 -0
  73. package/dist/rules.meta.d.ts +214 -0
  74. package/dist/rules.meta.js +212 -0
  75. package/dist/syntax.d.ts +41 -0
  76. package/dist/syntax.js +171 -0
  77. package/dist/text.d.ts +22 -0
  78. package/dist/text.js +43 -0
  79. package/dist/throw-in-hook.d.ts +8 -0
  80. package/dist/throw-in-hook.js +510 -0
  81. package/dist/throws-doc-mismatch.d.ts +7 -0
  82. package/dist/throws-doc-mismatch.js +188 -0
  83. package/dist/throws-matches-doc.d.ts +7 -0
  84. package/dist/throws-matches-doc.js +188 -0
  85. package/package.json +34 -3
@@ -0,0 +1,8 @@
1
+ import type { FileContext } from "@stateward/core";
2
+ import type { ThrowsSummary } from "./summary.js";
3
+ /**
4
+ * `summarizeThrows` with the facts of the packages the file calls (packages.ts), computed once
5
+ * per file when its rules run one after the other.
6
+ */
7
+ export declare function summarizeOnce(ctx: FileContext): ThrowsSummary;
8
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { packageResolver } from "./packages.js";
2
+ import { summarizeThrows } from "./summarize.js";
3
+ /**
4
+ * The last file's summary, by program: `catch-misses-error`, `throws-doc-mismatch` and the React
5
+ * rules all summarize the same facts, and the engine runs a file's rules one after the other.
6
+ * Only the last file is kept: kept for every file, the summaries stayed in memory for the whole
7
+ * run next to the engine's own copies.
8
+ */
9
+ const last = new WeakMap();
10
+ /**
11
+ * `summarizeThrows` with the facts of the packages the file calls (packages.ts), computed once
12
+ * per file when its rules run one after the other.
13
+ */
14
+ export function summarizeOnce(ctx) {
15
+ const known = last.get(ctx.types);
16
+ if (known?.sourceFile === ctx.sourceFile)
17
+ return known.summary;
18
+ const summary = summarizeThrows(ctx, packageResolver(ctx));
19
+ last.set(ctx.types, { sourceFile: ctx.sourceFile, summary });
20
+ return summary;
21
+ }
22
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1,128 @@
1
+ import type { Json, Location } from "@stateward/core";
2
+ import type { ClassFact, Effect, FunctionFact, Handler, PackageFacts } from "./summary.js";
3
+ /** `zod 3.23.8`, or `zod` when its version is not known. */
4
+ export declare function packageLabel(facts: Pick<PackageFacts, "name" | "version">): string;
5
+ /** Something that cannot be followed, where it is and why: shown as `api.get: no declaration`. */
6
+ export type Source = {
7
+ readonly file: string;
8
+ readonly start: number;
9
+ readonly end: number;
10
+ readonly text: string;
11
+ readonly reason: string;
12
+ /** The package whose facts this unknown comes from, when it does. */
13
+ readonly package?: string;
14
+ };
15
+ /**
16
+ * A set of errors: known classes by id (true when the class surely reaches here, false when it
17
+ * may have been handled by a test this analysis does not read), and the unknown sources.
18
+ */
19
+ export type Thrown = {
20
+ readonly classes: ReadonlyMap<string, boolean>;
21
+ /**
22
+ * Where a class known from a package's facts comes from, by id: `zod 3.23.8: declared`
23
+ *. Classes of the project have none.
24
+ */
25
+ readonly origins: ReadonlyMap<string, string>;
26
+ readonly unknowns: readonly Source[];
27
+ readonly more: boolean;
28
+ };
29
+ /** What calling a function throws, and what the promise it returns rejects with. */
30
+ export type Result = {
31
+ readonly throws: Thrown;
32
+ readonly rejects: Thrown;
33
+ };
34
+ /** Where a class first comes into a set: the call that brings it, null for a `throw`. */
35
+ export type Via = Location & {
36
+ readonly text: string;
37
+ };
38
+ /** The set while it is being computed, with where each class comes from. */
39
+ export type Collected = {
40
+ readonly classes: Map<string, {
41
+ certain: boolean;
42
+ via: Via | null;
43
+ from: string | null;
44
+ }>;
45
+ readonly unknowns: Map<string, Source>;
46
+ more: boolean;
47
+ };
48
+ export type FunctionEntry = {
49
+ readonly file: string;
50
+ readonly fact: FunctionFact;
51
+ };
52
+ export type Analysis = {
53
+ readonly functions: ReadonlyMap<string, FunctionEntry>;
54
+ readonly classes: ReadonlyMap<string, ClassFact>;
55
+ readonly results: ReadonlyMap<string, Result>;
56
+ /** Every class's facts as one text: equal texts, equal `instanceof` answers. */
57
+ readonly classesKey: string;
58
+ /** The top-level code of each file. */
59
+ readonly modules: readonly {
60
+ file: string;
61
+ effects: readonly Effect[];
62
+ }[];
63
+ /** Functions computed by this solve (not reused from the last one): early cut-off at work. */
64
+ readonly computed: number;
65
+ };
66
+ /** A catch as the evaluation met it: what its `try` throws, and what no branch handles. */
67
+ export type CatchSeen = {
68
+ readonly file: string;
69
+ readonly handler: Handler;
70
+ readonly thrown: Collected;
71
+ readonly unhandled: ReadonlyMap<string, {
72
+ certain: boolean;
73
+ via: Via | null;
74
+ from: string | null;
75
+ }>;
76
+ };
77
+ export declare function collected(): Collected;
78
+ /** The set as a result: classes sorted by id, unknown sources sorted and capped. */
79
+ export declare function toThrown(from: Collected): Thrown;
80
+ export declare function sameResult(a: Result, b: Result): boolean;
81
+ /**
82
+ * Whether `instanceof <handler>` is true for an error of class `cls`: "yes" when `handler` is the
83
+ * class or one it extends, "no" when the chain is known and does not reach it, "undecided" when
84
+ * the chain cannot be followed.
85
+ */
86
+ export declare function relation(handler: string, cls: string, classes: ReadonlyMap<string, ClassFact>): "yes" | "no" | "undecided";
87
+ /** What evaluating a function body needs. */
88
+ type Context = {
89
+ readonly file: string;
90
+ readonly classes: ReadonlyMap<string, ClassFact>;
91
+ resultOf(id: string): Result | undefined;
92
+ /** Told about every catch the evaluation passes, for `catch-misses-error`. */
93
+ onCatch?: (seen: CatchSeen) => void;
94
+ };
95
+ /** Adds what `effects` throw to `into`; `caught` holds, by catch, what reaches its variable. */
96
+ export declare function evaluate(effects: readonly Effect[], context: Context, caught: ReadonlyMap<number, Collected>, into: Collected): void;
97
+ /** What the body of a function throws and rejects with, ignoring its `@throws`. */
98
+ export declare function inferred(entry: FunctionEntry, analysis: Pick<Analysis, "classes" | "results">, onCatch?: (seen: CatchSeen) => void): {
99
+ throws: Collected;
100
+ rejects: Collected;
101
+ };
102
+ /** Solves what every function of the project throws. */
103
+ export declare function analyse(summaries: ReadonlyMap<string, Json>): Analysis;
104
+ /**
105
+ * Solves a closed set of functions on its own, without the project's memo: a package's functions
106
+ * read from its source. Calls outside the set are unknown.
107
+ */
108
+ export declare function solveFunctions(functions: ReadonlyMap<string, FunctionEntry>, classes: ReadonlyMap<string, ClassFact>): ReadonlyMap<string, Result>;
109
+ /**
110
+ * What a function's own evaluation gives the rules (its catches, what its body throws), kept per
111
+ * facts object while its callees' results and the classes are the same objects: a full pass
112
+ * after an edit evaluates only the functions whose facts or callees changed.
113
+ */
114
+ type Evaluated = {
115
+ readonly callees: readonly (Result | undefined)[];
116
+ readonly classesKey: string;
117
+ readonly catches: readonly CatchSeen[];
118
+ readonly body: {
119
+ throws: Collected;
120
+ rejects: Collected;
121
+ };
122
+ };
123
+ /** The function's catches and inferred result, evaluated with the analysis's callee results. */
124
+ export declare function evaluated(entry: FunctionEntry, analysis: Analysis): Evaluated;
125
+ /** Every catch of the project, with what reaches it, for `catch-misses-error`. */
126
+ export declare function everyCatch(analysis: Analysis): readonly CatchSeen[];
127
+ export {};
128
+ //# sourceMappingURL=solve.d.ts.map