@stateward/plugin-errors 1.2.2 → 1.3.1

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 (54) hide show
  1. package/README.md +9 -8
  2. package/dist/catch-hides-unexpected.d.ts +4 -1
  3. package/dist/catch-hides-unexpected.js +12 -5
  4. package/dist/catch-misses-error.d.ts +1 -1
  5. package/dist/catch-misses-error.js +7 -4
  6. package/dist/finally-can-throw.js +3 -3
  7. package/dist/hover.js +6 -9
  8. package/dist/index.d.ts +3 -1
  9. package/dist/index.js +1 -0
  10. package/dist/inference/analysis.d.ts +109 -0
  11. package/dist/inference/analysis.js +170 -0
  12. package/dist/inference/builtins.d.ts +0 -2
  13. package/dist/inference/builtins.js +0 -33
  14. package/dist/inference/deps.d.ts +13 -2
  15. package/dist/inference/deps.js +24 -13
  16. package/dist/inference/needs.d.ts +16 -0
  17. package/dist/inference/needs.js +27 -0
  18. package/dist/inference/packages.d.ts +24 -32
  19. package/dist/inference/packages.js +156 -680
  20. package/dist/inference/project.d.ts +4 -4
  21. package/dist/inference/project.js +6 -17
  22. package/dist/inference/solve.d.ts +29 -4
  23. package/dist/inference/solve.js +42 -12
  24. package/dist/inference/summarize.d.ts +27 -15
  25. package/dist/inference/summarize.js +247 -130
  26. package/dist/inference/summary.d.ts +41 -5
  27. package/dist/inference/summary.js +84 -12
  28. package/dist/inference/unreachable.d.ts +5 -0
  29. package/dist/inference/unreachable.js +160 -0
  30. package/dist/inlay.d.ts +1 -5
  31. package/dist/inlay.js +1 -12
  32. package/dist/must-handle-error.d.ts +4 -3
  33. package/dist/must-handle-error.js +10 -13
  34. package/dist/plugin.d.ts +12 -2
  35. package/dist/plugin.js +4 -2
  36. package/dist/react/boundaries.d.ts +9 -7
  37. package/dist/react/boundaries.js +16 -24
  38. package/dist/react/tree.js +8 -4
  39. package/dist/refactors.js +1 -1
  40. package/dist/render-throw-without-boundary.d.ts +13 -4
  41. package/dist/render-throw-without-boundary.js +4 -2
  42. package/dist/result-ignored.d.ts +4 -1
  43. package/dist/result-type.js +2 -2
  44. package/dist/result-unchecked.d.ts +4 -1
  45. package/dist/result-unchecked.js +139 -61
  46. package/dist/rules.meta.d.ts +26 -14
  47. package/dist/rules.meta.js +18 -14
  48. package/dist/syntax.d.ts +0 -13
  49. package/dist/syntax.js +0 -79
  50. package/dist/text.d.ts +5 -2
  51. package/dist/text.js +11 -5
  52. package/dist/throws-doc-mismatch.d.ts +2 -2
  53. package/dist/throws-doc-mismatch.js +13 -5
  54. package/package.json +2 -2
@@ -1,3 +1,11 @@
1
+ /** Why a package's function is not (fully) known: fixed strings, shown as they are. */
2
+ export const UNKNOWN_REASONS = [
3
+ // No `facts` line, in the config or a pack, states what the package's function throws (0041).
4
+ "its errors are not stated",
5
+ // A line states what the call throws, and not what the promise it returns rejects with: kinds
6
+ // are strict, so a `throws` line (1.2's style) leaves the promise not stated.
7
+ "its `facts` line states no `rejects`, the kind its promise needs",
8
+ ];
1
9
  function isList(value) {
2
10
  return Array.isArray(value);
3
11
  }
@@ -42,24 +50,52 @@ function readSide(value) {
42
50
  const f = value === undefined ? undefined : fieldsOf(value);
43
51
  const classes = readStrings(f?.classes);
44
52
  const unknown = readStrings(f?.unknown);
45
- return classes === undefined || unknown === undefined ? undefined : { classes, unknown };
53
+ if (classes === undefined || unknown === undefined)
54
+ return undefined;
55
+ return { classes, unknown };
46
56
  }
47
- const SOURCES = ["config", "declared", "inferred", "unknown"];
57
+ const SOURCES = ["config", "shipped", "unknown"];
48
58
  function readSource(value) {
49
59
  return SOURCES.find((source) => source === value);
50
60
  }
61
+ const FACT_SIDES = ["throws", "rejects"];
62
+ /** A `FactKey` as `PackageFacts.key` writes it; undefined for anything else. */
63
+ function readKey(value) {
64
+ const f = value === undefined ? undefined : fieldsOf(value);
65
+ if (f === undefined || !isString(f.name))
66
+ return undefined;
67
+ if (f.kind === "unnamed") {
68
+ return isString(f.reason) ? { kind: "unnamed", name: f.name, reason: f.reason } : undefined;
69
+ }
70
+ if (f.kind !== "named" || !isString(f.module))
71
+ return undefined;
72
+ if (f.version !== undefined && !isString(f.version))
73
+ return undefined;
74
+ return {
75
+ kind: "named",
76
+ module: f.module,
77
+ name: f.name,
78
+ ...(f.version === undefined ? {} : { version: f.version }),
79
+ };
80
+ }
51
81
  /** Package facts as `PackageFacts` writes them; undefined for anything else. */
52
82
  export function readPackageFacts(value) {
53
83
  const f = value === undefined ? undefined : fieldsOf(value);
54
- if (f === undefined || !isString(f.name) || !isString(f.version) || !isString(f.fn)) {
84
+ if (f === undefined || !isString(f.name) || !isString(f.version))
55
85
  return undefined;
56
- }
86
+ const key = readKey(f.key);
87
+ const side = FACT_SIDES.find((one) => one === f.side);
57
88
  const source = readSource(f.source);
58
89
  const throws = readSide(f.throws);
59
90
  const rejects = readSide(f.rejects);
60
- if (source === undefined || throws === undefined || rejects === undefined)
91
+ if (key === undefined ||
92
+ side === undefined ||
93
+ source === undefined ||
94
+ throws === undefined ||
95
+ rejects === undefined) {
61
96
  return undefined;
62
- return { name: f.name, version: f.version, fn: f.fn, source, throws, rejects };
97
+ }
98
+ return { name: f.name, version: f.version, key, side, source, throws, rejects };
63
99
  }
64
100
  function readEffect(value) {
65
101
  const f = fieldsOf(value);
@@ -67,10 +103,19 @@ function readEffect(value) {
67
103
  if (f === undefined || at === undefined || !isString(f.k))
68
104
  return undefined;
69
105
  switch (f.k) {
70
- case "class":
71
- return isString(f.id) && (f.text === null || isString(f.text))
72
- ? { k: "class", id: f.id, text: f.text, at }
106
+ case "class": {
107
+ return isString(f.id) &&
108
+ (f.text === null || isString(f.text)) &&
109
+ (f.platform === undefined || f.platform === true)
110
+ ? {
111
+ k: "class",
112
+ id: f.id,
113
+ text: f.text,
114
+ at,
115
+ ...(f.platform === true ? { platform: true } : {}),
116
+ }
73
117
  : undefined;
118
+ }
74
119
  case "unknown":
75
120
  return isString(f.reason) && isString(f.text)
76
121
  ? { k: "unknown", reason: f.reason, text: f.text, at }
@@ -85,8 +130,16 @@ function readEffect(value) {
85
130
  const facts = readPackageFacts(f.facts);
86
131
  return facts !== undefined &&
87
132
  isString(f.text) &&
88
- (f.part === "throws" || f.part === "rejects")
89
- ? { k: "package", facts, part: f.part, text: f.text, at }
133
+ (f.part === "throws" || f.part === "rejects") &&
134
+ (f.platform === undefined || f.platform === true)
135
+ ? {
136
+ k: "package",
137
+ facts,
138
+ part: f.part,
139
+ text: f.text,
140
+ at,
141
+ ...(f.platform === true ? { platform: true } : {}),
142
+ }
90
143
  : undefined;
91
144
  }
92
145
  case "maybe": {
@@ -214,7 +267,26 @@ export function readClass(value) {
214
267
  return undefined;
215
268
  if ((f.parent !== null && !isString(f.parent)) || typeof f.open !== "boolean")
216
269
  return undefined;
217
- return { id: f.id, name: f.name, parent: f.parent, open: f.open };
270
+ const fields = each(f.fields, (item) => (isString(item) ? item : undefined));
271
+ if (fields === undefined)
272
+ return undefined;
273
+ if (f.declared !== undefined && !isString(f.declared))
274
+ return undefined;
275
+ if (f.version !== undefined && !isString(f.version))
276
+ return undefined;
277
+ const key = f.key === undefined ? undefined : readKey(f.key);
278
+ if (f.key !== undefined && key === undefined)
279
+ return undefined;
280
+ return {
281
+ id: f.id,
282
+ name: f.name,
283
+ parent: f.parent,
284
+ open: f.open,
285
+ fields,
286
+ ...(f.declared === undefined ? {} : { declared: f.declared }),
287
+ ...(f.version === undefined ? {} : { version: f.version }),
288
+ ...(key === undefined ? {} : { key }),
289
+ };
218
290
  }
219
291
  /** Read once per summary object: the engine hands out the same frozen object while it is unchanged. */
220
292
  const read = new WeakMap();
@@ -0,0 +1,5 @@
1
+ import ts from "@stateward/core/typescript";
2
+ import type { TypeQueries } from "@stateward/core";
3
+ /** Whether a `throw` cannot run while the types hold (see above). */
4
+ export declare function cannotRun(types: TypeQueries, node: ts.ThrowStatement): boolean;
5
+ //# sourceMappingURL=unreachable.d.ts.map
@@ -0,0 +1,160 @@
1
+ import ts from "@stateward/core/typescript";
2
+ import { stripParentheses } from "../syntax.js";
3
+ /*
4
+ * A `throw` that cannot run because the value it is about has no case left: the `default` of a
5
+ * `switch` whose cases cover every value of its type, a `throw` after an `if` chain that returns
6
+ * for every value, or a `throw` that names a value TypeScript has narrowed to `never`. Code
7
+ * written to fail loudly if the type ever grows (`default: throw new Error("unknown kind")`) is not
8
+ * an error a caller can get while the types hold.
9
+ */
10
+ function keyOf(literal) {
11
+ return `${typeof literal.value}:${String(literal.value)}`;
12
+ }
13
+ /** The values of `node`'s type, or undefined when they are not a finite set of literals. */
14
+ function valuesOf(types, node) {
15
+ const literals = types.literalsOf(node);
16
+ return literals === "not-finite" ? undefined : new Set(literals.map(keyOf));
17
+ }
18
+ /** Whether every value of `all` is in `covered`. */
19
+ function covers(covered, all) {
20
+ return [...all].every((value) => covered.has(value));
21
+ }
22
+ /** The `default` clause the statement sits in directly (in its statements, or a block of them). */
23
+ function defaultClauseOf(node) {
24
+ let at = node.parent;
25
+ while (ts.isBlock(at))
26
+ at = at.parent;
27
+ return ts.isDefaultClause(at) ? at : undefined;
28
+ }
29
+ /** A `default` that no value of the switched expression reaches: the cases cover its type. */
30
+ function unreachableDefault(types, clause) {
31
+ const clauses = clause.parent.clauses;
32
+ const index = clauses.indexOf(clause);
33
+ // A case with no statements just before it falls through into the default.
34
+ const before = index > 0 ? clauses[index - 1] : undefined;
35
+ if (before?.statements.length === 0)
36
+ return false;
37
+ const all = valuesOf(types, clause.parent.parent.expression);
38
+ if (all === undefined)
39
+ return false;
40
+ if (all.size === 0)
41
+ return false;
42
+ const covered = new Set();
43
+ for (const one of clauses) {
44
+ if (!ts.isCaseClause(one))
45
+ continue;
46
+ const values = valuesOf(types, one.expression);
47
+ if (values?.size !== 1)
48
+ return false;
49
+ for (const value of values)
50
+ covered.add(value);
51
+ }
52
+ return covers(covered, all);
53
+ }
54
+ /** `x === A`, `A === x`, or several joined by `||`: the reference's text and the tested values. */
55
+ function testedValues(types, condition) {
56
+ const node = stripParentheses(condition);
57
+ if (!ts.isBinaryExpression(node))
58
+ return undefined;
59
+ if (node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
60
+ const left = testedValues(types, node.left);
61
+ const right = testedValues(types, node.right);
62
+ if (left === undefined || left.text !== right?.text)
63
+ return undefined;
64
+ return { ...left, values: new Set([...left.values, ...right.values]) };
65
+ }
66
+ if (node.operatorToken.kind !== ts.SyntaxKind.EqualsEqualsEqualsToken &&
67
+ node.operatorToken.kind !== ts.SyntaxKind.EqualsEqualsToken) {
68
+ return undefined;
69
+ }
70
+ for (const [reference, literal] of [
71
+ [node.left, node.right],
72
+ [node.right, node.left],
73
+ ]) {
74
+ if (!ts.isIdentifier(reference) && !ts.isPropertyAccessExpression(reference))
75
+ continue;
76
+ const values = valuesOf(types, literal);
77
+ if (values?.size !== 1)
78
+ continue;
79
+ return { reference, text: reference.getText(), values };
80
+ }
81
+ return undefined;
82
+ }
83
+ function alwaysExits(node) {
84
+ if (ts.isBlock(node)) {
85
+ const last = node.statements.at(-1);
86
+ return last !== undefined && alwaysExits(last);
87
+ }
88
+ return ts.isReturnStatement(node) || ts.isThrowStatement(node);
89
+ }
90
+ /**
91
+ * A `throw` after `if` statements of its block that test one value against literals and exit,
92
+ * covering every value of its type: `if (k === "a") return 1; if (k === "b") return 2; throw …`.
93
+ */
94
+ function afterCoveringChain(types, node) {
95
+ const block = node.parent;
96
+ if (!ts.isBlock(block) && !ts.isSourceFile(block))
97
+ return false;
98
+ const index = block.statements.indexOf(node);
99
+ let first;
100
+ let text;
101
+ const covered = new Set();
102
+ for (let at = index - 1; at >= 0; at -= 1) {
103
+ const statement = block.statements[at];
104
+ if (statement === undefined || !ts.isIfStatement(statement))
105
+ break;
106
+ let chain = statement;
107
+ const ifs = [];
108
+ // `if … else if …` with every branch exiting, and no final `else`.
109
+ while (chain !== undefined) {
110
+ ifs.push(chain);
111
+ const next = chain.elseStatement;
112
+ chain = next !== undefined && ts.isIfStatement(next) ? next : undefined;
113
+ if (next !== undefined && !ts.isIfStatement(next))
114
+ return false;
115
+ }
116
+ for (const one of ifs) {
117
+ if (!alwaysExits(one.thenStatement))
118
+ return false;
119
+ const tested = testedValues(types, one.expression);
120
+ if (tested === undefined)
121
+ return false;
122
+ if (text !== undefined && tested.text !== text)
123
+ return false;
124
+ text = tested.text;
125
+ first = tested.reference;
126
+ for (const value of tested.values)
127
+ covered.add(value);
128
+ }
129
+ }
130
+ if (first === undefined)
131
+ return false;
132
+ const all = valuesOf(types, first);
133
+ return all !== undefined && all.size > 0 && covers(covered, all);
134
+ }
135
+ /** A reference in the thrown expression whose type TypeScript has narrowed to `never`. */
136
+ function namesNever(types, node) {
137
+ let found = false;
138
+ const visit = (inner) => {
139
+ if (found || ts.isFunctionLike(inner))
140
+ return;
141
+ if ((ts.isIdentifier(inner) && !ts.isPropertyAccessExpression(inner.parent)) ||
142
+ ts.isPropertyAccessExpression(inner)) {
143
+ if (types.typeTextOf(inner) === "never") {
144
+ found = true;
145
+ return;
146
+ }
147
+ }
148
+ ts.forEachChild(inner, visit);
149
+ };
150
+ visit(node.expression);
151
+ return found;
152
+ }
153
+ /** Whether a `throw` cannot run while the types hold (see above). */
154
+ export function cannotRun(types, node) {
155
+ const clause = defaultClauseOf(node);
156
+ if (clause !== undefined && unreachableDefault(types, clause))
157
+ return true;
158
+ return afterCoveringChain(types, node) || namesNever(types, node);
159
+ }
160
+ //# sourceMappingURL=unreachable.js.map
package/dist/inlay.d.ts CHANGED
@@ -1,14 +1,10 @@
1
- import type { EditorContributions, Json } from "@stateward/core";
1
+ import type { EditorContributions } from "@stateward/core";
2
2
  type InlayHints = NonNullable<EditorContributions["inlayHints"]>;
3
3
  /** The two kinds of hint, as the `stateward.inlayHints.<kind>` settings name them. */
4
4
  export declare const HINT_KINDS: {
5
5
  readonly throws: "throws";
6
6
  readonly catchVariable: "catchVariable";
7
7
  };
8
- /** The summaries that hold the throws facts, from the rules that ran (as the hover reads them). */
9
- export declare function factSummaries(input: {
10
- projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
11
- }): ReadonlyMap<string, Json> | undefined;
12
8
  /**
13
9
  * Two kinds of hint, from the last full check's solve (no recomputation, as the hover):
14
10
  * `throws A | B` or `throws (unknown from \`fetchAvatar\`)` after a named function's signature (the hover's facts, `rejects` for what its
package/dist/inlay.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import ts from "@stateward/core/typescript";
2
- import { FACT_RULES } from "./inference/deps.js";
2
+ import { factSummaries } from "./inference/deps.js";
3
3
  import { catchesOf } from "./inference/catches.js";
4
4
  import { className, rejectsShown, resultLines, thrownText } from "./inference/format.js";
5
5
  import { analyse, toThrown } from "./inference/solve.js";
6
- import { TREE_RULES, throwsOf } from "./react/boundaries.js";
7
6
  /** The two kinds of hint, as the `stateward.inlayHints.<kind>` settings name them. */
8
7
  export const HINT_KINDS = { throws: "throws", catchVariable: "catchVariable" };
9
8
  /** At most this many class names are listed in a hint; the rest are counted (`+2`). */
@@ -94,16 +93,6 @@ function isFunctionWithBody(node) {
94
93
  ts.isFunctionExpression(node)) &&
95
94
  node.body !== undefined);
96
95
  }
97
- /** The summaries that hold the throws facts, from the rules that ran (as the hover reads them). */
98
- export function factSummaries(input) {
99
- let summaries;
100
- for (const ruleId of FACT_RULES)
101
- summaries ??= input.projectSummaries(ruleId);
102
- let trees;
103
- for (const ruleId of TREE_RULES)
104
- trees ??= input.projectSummaries(ruleId);
105
- return summaries ?? (trees === undefined ? undefined : throwsOf(trees));
106
- }
107
96
  /**
108
97
  * Two kinds of hint, from the last full check's solve (no recomputation, as the hover):
109
98
  * `throws A | B` or `throws (unknown from \`fetchAvatar\`)` after a named function's signature (the hover's facts, `rejects` for what its
@@ -1,4 +1,5 @@
1
- import type { Span, ThrowsSummary } from "./inference/summary.js";
1
+ import type { Json } from "@stateward/core";
2
+ import type { Span } from "./inference/summary.js";
2
3
  /** The group the rule belongs to in the docs and in `stateward status`. */
3
4
  export declare const GROUP = "callers";
4
5
  /** A class marked `@mustHandle`: its id, its name, the author's sentence and the tag's span. */
@@ -46,10 +47,10 @@ type MustHandleFacts = {
46
47
  readonly helpers: readonly ErrorHelper[];
47
48
  readonly passes: readonly Pass[];
48
49
  };
50
+ /** The rule's summary of one file; the throws facts it solves with are `errors/throws`'s summaries. */
49
51
  export type MustHandleSummary = {
50
- readonly throws: ThrowsSummary;
51
52
  readonly mustHandle: MustHandleFacts;
52
53
  };
53
- export declare const mustHandleError: import("@stateward/core").ProjectRule<MustHandleSummary, Readonly<Record<string, never>>, "callers">;
54
+ export declare const mustHandleError: import("@stateward/core").ProjectRule<MustHandleSummary, Readonly<Record<string, never>>, "callers", Readonly<Record<string, Json>>>;
54
55
  export {};
55
56
  //# sourceMappingURL=must-handle-error.d.ts.map
@@ -1,13 +1,12 @@
1
1
  import ts from "@stateward/core/typescript";
2
2
  import { defineRule } from "@stateward/core";
3
3
  import { catchName, className } from "./inference/format.js";
4
- import { summarizeOnce } from "./inference/project.js";
4
+ import { THROWS_ANALYSIS } from "./inference/deps.js";
5
5
  import { analyse, evaluated, relation } from "./inference/solve.js";
6
- import { ANONYMOUS, classIdOf } from "./inference/summarize.js";
6
+ import { ANONYMOUS, errorClassIdOf } from "./inference/summarize.js";
7
7
  import { each, fieldsOf, isString, spanOf } from "./inference/summary.js";
8
- import { throwsOf } from "./react/boundaries.js";
9
8
  import { stripParentheses } from "./syntax.js";
10
- import { fitted, oneLine, shorten, withExample } from "./text.js";
9
+ import { fitted, shorten, withExample } from "./text.js";
11
10
  /** The group the rule belongs to in the docs and in `stateward status`. */
12
11
  export const GROUP = "callers";
13
12
  const EXPLAIN = `# errors/must-handle-error
@@ -170,7 +169,7 @@ function errorHelperOf(fn, id, types) {
170
169
  const named = instanceofNames(first.expression, variable);
171
170
  if (named === undefined || throwsVariable(first.thenStatement, variable))
172
171
  continue;
173
- const classes = named.map((one) => classIdOf(types, one));
172
+ const classes = named.map((one) => errorClassIdOf(types, one));
174
173
  if (classes.some((one) => one === undefined))
175
174
  return undefined;
176
175
  return { id, parameter, classes: classes.filter((one) => one !== undefined) };
@@ -226,7 +225,7 @@ function summarizeMustHandle(ctx) {
226
225
  tags.push({
227
226
  id: symbol.id,
228
227
  name: symbol.name,
229
- how: oneLine(ts.getTextOfJSDocComment(tag.comment) ?? ""),
228
+ how: (ts.getTextOfJSDocComment(tag.comment) ?? "").replace(/\s+/g, " ").trim(),
230
229
  at: spanOfNode(tag),
231
230
  });
232
231
  }
@@ -677,8 +676,8 @@ function report(met, model, out) {
677
676
  }
678
677
  }
679
678
  }
680
- function modelOf(summaries) {
681
- const analysis = analyse(throwsOf(summaries));
679
+ function modelOf(summaries, throws) {
680
+ const analysis = analyse(throws);
682
681
  const tags = new Map();
683
682
  const anchors = new Map();
684
683
  const helpers = new Map();
@@ -714,12 +713,10 @@ export const mustHandleError = defineRule({
714
713
  listUnknowns: true,
715
714
  explain: EXPLAIN,
716
715
  },
717
- summarize: (ctx) => ({
718
- throws: summarizeOnce(ctx),
719
- mustHandle: summarizeMustHandle(ctx),
720
- }),
716
+ reads: [THROWS_ANALYSIS],
717
+ summarize: (ctx) => ({ mustHandle: summarizeMustHandle(ctx) }),
721
718
  check(summaries, ctx) {
722
- const { model, untracked } = modelOf(summaries);
719
+ const { model, untracked } = modelOf(summaries, ctx.analysisSummaries(THROWS_ANALYSIS));
723
720
  for (const location of untracked) {
724
721
  ctx.unknown({
725
722
  message: "not checked: the calls that meet `@mustHandle` on a type: only an error class is followed",
package/dist/plugin.d.ts CHANGED
@@ -66,7 +66,6 @@ export declare function errors(): import("@stateward/core").PluginOf<"errors", {
66
66
  };
67
67
  }, "render">;
68
68
  readonly "must-handle-error": import("@stateward/core").LazyRule<Readonly<Record<string, import("@stateward/core").OptionSpec>>, "callers">;
69
- readonly "narrow-try": import("@stateward/core").LazyRule<Readonly<Record<string, import("@stateward/core").OptionSpec>>, "catch">;
70
69
  readonly "result-ignored": import("@stateward/core").LazyRule<{
71
70
  readonly allowVoid: {
72
71
  readonly kind: "boolean";
@@ -84,6 +83,17 @@ export declare function errors(): import("@stateward/core").PluginOf<"errors", {
84
83
  readonly description: "Functions whose Result may be dropped, by the name they are called with (`logEvent`, `*.track`; globs allowed).";
85
84
  };
86
85
  }, "callers">;
87
- readonly "result-unchecked": import("@stateward/core").LazyRule<Readonly<Record<string, import("@stateward/core").OptionSpec>>, "callers">;
86
+ readonly "result-unchecked": import("@stateward/core").LazyRule<{
87
+ readonly failureNames: {
88
+ readonly kind: "strings";
89
+ readonly default: readonly [];
90
+ readonly description: "Names (or globs like isErr*) that are true when the call failed, besides the result's own `error`: a property of the result (`isError`), or a function called with it (`isFailure(result)`). Its type does not say what such a name means.";
91
+ };
92
+ readonly successNames: {
93
+ readonly kind: "strings";
94
+ readonly default: readonly [];
95
+ readonly description: "Names (or globs) that are true when the call worked, besides the result's own `data`, `ok` and `success`: a property of the result (`isSuccess`, `value`), or a function called with it (`isOk(result)`).";
96
+ };
97
+ }, "callers">;
88
98
  }>;
89
99
  //# sourceMappingURL=plugin.d.ts.map
package/dist/plugin.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { definePlugin, lazyRule, moduleLoader } from "@stateward/core";
2
2
  import { codeActions } from "./refactors.js";
3
3
  import { hover } from "./hover.js";
4
+ import { throws } from "./inference/analysis.js";
4
5
  import { libraryFacts } from "./inference/deps.js";
5
6
  import { inlayHints } from "./inlay.js";
6
7
  import { RULES } from "./rules.meta.js";
@@ -12,7 +13,6 @@ const load = {
12
13
  throwsDocMismatch: moduleLoader(() => import("./throws-doc-mismatch.js")),
13
14
  renderThrowWithoutBoundary: moduleLoader(() => import("./render-throw-without-boundary.js")),
14
15
  mustHandleError: moduleLoader(() => import("./must-handle-error.js")),
15
- narrowTry: moduleLoader(() => import("./narrow-try.js")),
16
16
  resultIgnored: moduleLoader(() => import("./result-ignored.js")),
17
17
  resultUnchecked: moduleLoader(() => import("./result-unchecked.js")),
18
18
  };
@@ -27,11 +27,13 @@ export function errors() {
27
27
  "throws-doc-mismatch": lazyRule(RULES["throws-doc-mismatch"], load.throwsDocMismatch, (module) => module.throwsDocMismatch),
28
28
  "render-throw-without-boundary": lazyRule(RULES["render-throw-without-boundary"], load.renderThrowWithoutBoundary, (module) => module.renderThrowWithoutBoundary),
29
29
  "must-handle-error": lazyRule(RULES["must-handle-error"], load.mustHandleError, (module) => module.mustHandleError),
30
- "narrow-try": lazyRule(RULES["narrow-try"], load.narrowTry, (module) => module.narrowTry),
31
30
  "result-ignored": lazyRule(RULES["result-ignored"], load.resultIgnored, (module) => module.resultIgnored),
32
31
  "result-unchecked": lazyRule(RULES["result-unchecked"], load.resultUnchecked, (module) => module.resultUnchecked),
33
32
  },
34
33
  editor: { hover, inlayHints, codeActions, libraryFacts },
34
+ analyses: { throws },
35
+ // Removed in R129: its precision followed the codebase's style (26% to 96%), not the rule.
36
+ removed: ["errors/narrow-try"],
35
37
  });
36
38
  }
37
39
  //# sourceMappingURL=plugin.js.map
@@ -1,6 +1,5 @@
1
1
  import type { FileContext, Json, Location, StringListRecord } from "@stateward/core";
2
2
  import type { Analysis, Source } from "../inference/solve.js";
3
- import type { ThrowsSummary } from "../inference/summary.js";
4
3
  import { type GuardSkips } from "./render-guards.js";
5
4
  import type { BoundaryElement, TreeFunction, TreeRender, TreeSummary } from "./tree.js";
6
5
  /**
@@ -9,9 +8,11 @@ import type { BoundaryElement, TreeFunction, TreeRender, TreeSummary } from "./t
9
8
  * each boundary can catch. Handlers, timers and async code are left out: a boundary never sees
10
9
  * their errors.
11
10
  */
12
- /** The summary of the pack's React rules: the throws facts and the render tree of one file. */
11
+ /**
12
+ * The summary of the pack's React rules: the render tree of one file. The throws facts they solve
13
+ * with it are the `errors/throws` analysis's summaries (`ProjectContext.analysisSummaries`).
14
+ */
13
15
  export type ReactSummary = {
14
- readonly throws: ThrowsSummary;
15
16
  readonly tree: TreeSummary;
16
17
  };
17
18
  /** The rules whose summaries hold a render tree; the first that ran is read. */
@@ -69,10 +70,11 @@ export type Model = {
69
70
  readonly labels: ReadonlyMap<string, string>;
70
71
  };
71
72
  };
72
- /** The throws part of each summary: the same facts `catch-misses-error` solves. */
73
- export declare function throwsOf(summaries: ReadonlyMap<string, Json>): ReadonlyMap<string, Json>;
74
- /** The pack's view of the app's render tree, built once per summaries map. */
75
- export declare function modelOf(summaries: ReadonlyMap<string, Json>): Model;
73
+ /**
74
+ * The pack's view of the app's render tree, built once per pair of summaries maps: the React
75
+ * rule's trees, and the throws facts (`errors/throws`'s summaries).
76
+ */
77
+ export declare function modelOf(summaries: ReadonlyMap<string, Json>, throws: ReadonlyMap<string, Json>): Model;
76
78
  /** The line every boundary hover ends with: what no boundary ever catches. */
77
79
  export declare const NOT_CAUGHT = "not caught by a boundary: errors in event handlers and async code";
78
80
  /**
@@ -1,5 +1,4 @@
1
1
  import { propagate } from "@stateward/core";
2
- import { summarizeOnce } from "../inference/project.js";
3
2
  import { analyse, evaluated } from "../inference/solve.js";
4
3
  import { className, unknownText } from "../inference/format.js";
5
4
  import { fieldsOf } from "../inference/summary.js";
@@ -13,7 +12,7 @@ export const TREE_RULES = [
13
12
  /**
14
13
  * The last file's trees by program, then by the boundaries the rule's config adds (as JSON): the
15
14
  * pack's two React rules summarize the same file one after the other. Only the last file is
16
- * kept, as in `summarizeOnce`.
15
+ * kept.
17
16
  */
18
17
  const last = new WeakMap();
19
18
  export function summarizeReact(ctx, libraryBoundaries = LIBRARY_BOUNDARIES, skips = ALL_GUARDS) {
@@ -28,27 +27,12 @@ export function summarizeReact(ctx, libraryBoundaries = LIBRARY_BOUNDARIES, skip
28
27
  tree = summarizeTree(ctx, libraryBoundaries, skips);
29
28
  known.trees.set(key, tree);
30
29
  }
31
- return { throws: summarizeOnce(ctx), tree };
30
+ return { tree };
32
31
  }
33
32
  /** What `nearest` answers for a render stateward cannot follow to where it is placed. */
34
33
  const UNFOLLOWED = "?";
34
+ /** By the trees' summaries map, then the throws summaries map. */
35
35
  const models = new WeakMap();
36
- const throwsMaps = new WeakMap();
37
- /** The throws part of each summary: the same facts `catch-misses-error` solves. */
38
- export function throwsOf(summaries) {
39
- let known = throwsMaps.get(summaries);
40
- if (known === undefined) {
41
- const made = new Map();
42
- for (const [file, value] of summaries) {
43
- const throws = fieldsOf(value)?.throws;
44
- if (throws !== undefined)
45
- made.set(file, throws);
46
- }
47
- known = made;
48
- throwsMaps.set(summaries, known);
49
- }
50
- return known;
51
- }
52
36
  function compareSites(a, b) {
53
37
  if (a.file !== b.file)
54
38
  return a.file < b.file ? -1 : 1;
@@ -57,12 +41,20 @@ function compareSites(a, b) {
57
41
  function stepOf(text) {
58
42
  return text.endsWith("(…)") ? text.slice(0, -"(…)".length) : text;
59
43
  }
60
- /** The pack's view of the app's render tree, built once per summaries map. */
61
- export function modelOf(summaries) {
62
- const known = models.get(summaries);
44
+ /**
45
+ * The pack's view of the app's render tree, built once per pair of summaries maps: the React
46
+ * rule's trees, and the throws facts (`errors/throws`'s summaries).
47
+ */
48
+ export function modelOf(summaries, throws) {
49
+ let byThrows = models.get(summaries);
50
+ if (byThrows === undefined) {
51
+ byThrows = new WeakMap();
52
+ models.set(summaries, byThrows);
53
+ }
54
+ const known = byThrows.get(throws);
63
55
  if (known !== undefined)
64
56
  return known;
65
- const analysis = analyse(throwsOf(summaries));
57
+ const analysis = analyse(throws);
66
58
  const functions = new Map();
67
59
  const boundaries = new Map();
68
60
  const byFile = new Map();
@@ -339,7 +331,7 @@ export function modelOf(summaries) {
339
331
  needs,
340
332
  catches,
341
333
  };
342
- models.set(summaries, model);
334
+ byThrows.set(throws, model);
343
335
  return model;
344
336
  }
345
337
  /** The line every boundary hover ends with: what no boundary ever catches. */
@@ -1,5 +1,6 @@
1
1
  import ts from "@stateward/core/typescript";
2
- import { classIdOf, packageNameOf } from "../inference/summarize.js";
2
+ import { packageNameOf } from "@stateward/core";
3
+ import { errorClassIdOf } from "../inference/summarize.js";
3
4
  import { each, fieldsOf, isString, readStrings, spanOf } from "../inference/summary.js";
4
5
  import { scanRunning, stripParentheses } from "../syntax.js";
5
6
  import { ALL_GUARDS, guardThrows } from "./render-guards.js";
@@ -110,7 +111,7 @@ function classifyTag(types, tag, libraryBoundaries) {
110
111
  }
111
112
  if (!types.isOwnFile(declaration.file)) {
112
113
  const library = packageNameOf(types, declaration.file);
113
- const isLibraryBoundary = (libraryBoundaries[library] ?? []).includes(symbol.name);
114
+ const isLibraryBoundary = library !== undefined && (libraryBoundaries[library] ?? []).includes(symbol.name);
114
115
  return { target: undefined, boundary: isLibraryBoundary ? { own: null } : undefined };
115
116
  }
116
117
  return {
@@ -370,7 +371,7 @@ function chainOf(types, fn, ref) {
370
371
  return null;
371
372
  const { classes, ...rest } = found;
372
373
  const branches = classes.map((names) => {
373
- const ids = names.map((name) => classIdOf(types, ts.isPropertyAccessExpression(name) ? name.name : name));
374
+ const ids = names.map((name) => errorClassIdOf(types, ts.isPropertyAccessExpression(name) ? name.name : name));
374
375
  return ids.every((id) => id !== undefined) ? ids : null;
375
376
  });
376
377
  return { ...rest, file: fn.getSourceFile().fileName, branches };
@@ -634,7 +635,10 @@ export function summarizeTree(ctx, libraryBoundaries = LIBRARY_BOUNDARIES, skips
634
635
  continue;
635
636
  if (types.isOwnFile(declaration.file) || !BOUNDARY_NAME.test(symbol.name))
636
637
  continue;
637
- return { tag: symbol.name, package: packageNameOf(types, declaration.file) };
638
+ const library = packageNameOf(types, declaration.file);
639
+ if (library === undefined)
640
+ continue;
641
+ return { tag: symbol.name, package: library };
638
642
  }
639
643
  return undefined;
640
644
  };
package/dist/refactors.js CHANGED
@@ -2,7 +2,7 @@ import ts from "@stateward/core/typescript";
2
2
  import { catchesOf } from "./inference/catches.js";
3
3
  import { catchName } from "./inference/format.js";
4
4
  import { analyse } from "./inference/solve.js";
5
- import { factSummaries } from "./inlay.js";
5
+ import { factSummaries } from "./inference/deps.js";
6
6
  /** The title of the refactoring that wraps a catch-all for the errors its `try` can throw. */
7
7
  export const HANDLE_KNOWN_TITLE = "Handle the known errors, rethrow the rest";
8
8
  /**