monkeypatchlist 0.0.0-stage → 0.1.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 (221) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +61 -0
  3. package/README.md +183 -2
  4. package/catalog/catalog.json +552211 -0
  5. package/catalog/catalog.schema.json +787 -0
  6. package/catalog/changelog.json +3 -0
  7. package/dist/bin/monkeypatchlist.d.ts +2 -0
  8. package/dist/bin/monkeypatchlist.js +3 -0
  9. package/dist/catalog.d.ts +561 -0
  10. package/dist/catalog.js +58 -0
  11. package/dist/cli.d.ts +84 -0
  12. package/dist/cli.js +470 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +1 -0
  15. package/dist/lockfile-input.d.ts +9 -0
  16. package/dist/lockfile-input.js +91 -0
  17. package/dist/packages/analysis/binding.d.ts +2 -0
  18. package/dist/packages/analysis/binding.js +5 -0
  19. package/dist/packages/analysis/index.d.ts +10 -0
  20. package/dist/packages/analysis/index.js +13 -0
  21. package/dist/packages/analysis/job.d.ts +33 -0
  22. package/dist/packages/analysis/job.js +85 -0
  23. package/dist/packages/analysis/lib/absence-tags.d.ts +34 -0
  24. package/dist/packages/analysis/lib/absence-tags.js +340 -0
  25. package/dist/packages/analysis/lib/ast.d.ts +28 -0
  26. package/dist/packages/analysis/lib/ast.js +64 -0
  27. package/dist/packages/analysis/lib/binding.d.ts +36 -0
  28. package/dist/packages/analysis/lib/binding.js +66 -0
  29. package/dist/packages/analysis/lib/budget.d.ts +80 -0
  30. package/dist/packages/analysis/lib/budget.js +31 -0
  31. package/dist/packages/analysis/lib/catch-arms.d.ts +19 -0
  32. package/dist/packages/analysis/lib/catch-arms.js +351 -0
  33. package/dist/packages/analysis/lib/chunk-loads.d.ts +160 -0
  34. package/dist/packages/analysis/lib/chunk-loads.js +882 -0
  35. package/dist/packages/analysis/lib/chunk-registry.d.ts +45 -0
  36. package/dist/packages/analysis/lib/chunk-registry.js +334 -0
  37. package/dist/packages/analysis/lib/code-routes.d.ts +52 -0
  38. package/dist/packages/analysis/lib/code-routes.js +921 -0
  39. package/dist/packages/analysis/lib/collisions.d.ts +22 -0
  40. package/dist/packages/analysis/lib/collisions.js +103 -0
  41. package/dist/packages/analysis/lib/definitions.d.ts +76 -0
  42. package/dist/packages/analysis/lib/definitions.js +782 -0
  43. package/dist/packages/analysis/lib/early-exits.d.ts +39 -0
  44. package/dist/packages/analysis/lib/early-exits.js +161 -0
  45. package/dist/packages/analysis/lib/effect.d.ts +138 -0
  46. package/dist/packages/analysis/lib/effect.js +800 -0
  47. package/dist/packages/analysis/lib/global-object.d.ts +581 -0
  48. package/dist/packages/analysis/lib/global-object.js +8240 -0
  49. package/dist/packages/analysis/lib/keys.d.ts +33 -0
  50. package/dist/packages/analysis/lib/keys.js +82 -0
  51. package/dist/packages/analysis/lib/line-starts.d.ts +41 -0
  52. package/dist/packages/analysis/lib/line-starts.js +79 -0
  53. package/dist/packages/analysis/lib/link-group.d.ts +51 -0
  54. package/dist/packages/analysis/lib/link-group.js +487 -0
  55. package/dist/packages/analysis/lib/module-links.d.ts +117 -0
  56. package/dist/packages/analysis/lib/module-links.js +1060 -0
  57. package/dist/packages/analysis/lib/nested-code.d.ts +38 -0
  58. package/dist/packages/analysis/lib/nested-code.js +200 -0
  59. package/dist/packages/analysis/lib/numeric.d.ts +16 -0
  60. package/dist/packages/analysis/lib/numeric.js +216 -0
  61. package/dist/packages/analysis/lib/once-flags.d.ts +12 -0
  62. package/dist/packages/analysis/lib/once-flags.js +190 -0
  63. package/dist/packages/analysis/lib/parameter-arguments.d.ts +12 -0
  64. package/dist/packages/analysis/lib/parameter-arguments.js +34 -0
  65. package/dist/packages/analysis/lib/parse.d.ts +10 -0
  66. package/dist/packages/analysis/lib/parse.js +39 -0
  67. package/dist/packages/analysis/lib/partial.d.ts +60 -0
  68. package/dist/packages/analysis/lib/partial.js +518 -0
  69. package/dist/packages/analysis/lib/print.d.ts +3 -0
  70. package/dist/packages/analysis/lib/print.js +150 -0
  71. package/dist/packages/analysis/lib/reachability.d.ts +137 -0
  72. package/dist/packages/analysis/lib/reachability.js +1295 -0
  73. package/dist/packages/analysis/lib/resolver.d.ts +13 -0
  74. package/dist/packages/analysis/lib/resolver.js +2886 -0
  75. package/dist/packages/analysis/lib/restores.d.ts +42 -0
  76. package/dist/packages/analysis/lib/restores.js +482 -0
  77. package/dist/packages/analysis/lib/rewritten-deletes.d.ts +6 -0
  78. package/dist/packages/analysis/lib/rewritten-deletes.js +142 -0
  79. package/dist/packages/analysis/lib/scope.d.ts +110 -0
  80. package/dist/packages/analysis/lib/scope.js +443 -0
  81. package/dist/packages/analysis/lib/script-loads.d.ts +56 -0
  82. package/dist/packages/analysis/lib/script-loads.js +359 -0
  83. package/dist/packages/analysis/lib/summaries.d.ts +177 -0
  84. package/dist/packages/analysis/lib/summaries.js +498 -0
  85. package/dist/packages/analysis/lib/types.d.ts +632 -0
  86. package/dist/packages/analysis/lib/types.js +128 -0
  87. package/dist/packages/analysis/lib/wrap.d.ts +34 -0
  88. package/dist/packages/analysis/lib/wrap.js +407 -0
  89. package/dist/packages/analysis/lib/writes.d.ts +358 -0
  90. package/dist/packages/analysis/lib/writes.js +1612 -0
  91. package/dist/packages/analysis/visit-order.d.ts +3 -0
  92. package/dist/packages/analysis/visit-order.js +23 -0
  93. package/dist/packages/attribution/index.d.ts +233 -0
  94. package/dist/packages/attribution/index.js +444 -0
  95. package/dist/packages/attribution/lib/containing-package.d.ts +76 -0
  96. package/dist/packages/attribution/lib/containing-package.js +304 -0
  97. package/dist/packages/attribution/lib/first-party.d.ts +37 -0
  98. package/dist/packages/attribution/lib/first-party.js +153 -0
  99. package/dist/packages/attribution/lib/lockfile-graph.d.ts +99 -0
  100. package/dist/packages/attribution/lib/lockfile-graph.js +158 -0
  101. package/dist/packages/attribution/lib/lockfile.d.ts +33 -0
  102. package/dist/packages/attribution/lib/lockfile.js +330 -0
  103. package/dist/packages/attribution/lib/path-rules.d.ts +29 -0
  104. package/dist/packages/attribution/lib/path-rules.js +84 -0
  105. package/dist/packages/attribution/lib/pnpm.d.ts +4 -0
  106. package/dist/packages/attribution/lib/pnpm.js +133 -0
  107. package/dist/packages/attribution/lib/remote-url.d.ts +7 -0
  108. package/dist/packages/attribution/lib/remote-url.js +24 -0
  109. package/dist/packages/attribution/lib/source-map.d.ts +51 -0
  110. package/dist/packages/attribution/lib/source-map.js +125 -0
  111. package/dist/packages/attribution/lib/yaml.d.ts +9 -0
  112. package/dist/packages/attribution/lib/yaml.js +277 -0
  113. package/dist/packages/attribution/lib/yarn.d.ts +7 -0
  114. package/dist/packages/attribution/lib/yarn.js +227 -0
  115. package/dist/packages/baseline/index.d.ts +45 -0
  116. package/dist/packages/baseline/index.js +41 -0
  117. package/dist/packages/baseline/lib/error.d.ts +15 -0
  118. package/dist/packages/baseline/lib/error.js +25 -0
  119. package/dist/packages/baseline/lib/format.d.ts +49 -0
  120. package/dist/packages/baseline/lib/format.js +22 -0
  121. package/dist/packages/baseline/lib/migrations.d.ts +19 -0
  122. package/dist/packages/baseline/lib/migrations.js +7 -0
  123. package/dist/packages/baseline/lib/previous.d.ts +23 -0
  124. package/dist/packages/baseline/lib/previous.js +64 -0
  125. package/dist/packages/baseline/lib/read.d.ts +39 -0
  126. package/dist/packages/baseline/lib/read.js +219 -0
  127. package/dist/packages/baseline/lib/report.d.ts +25 -0
  128. package/dist/packages/baseline/lib/report.js +104 -0
  129. package/dist/packages/baseline/lib/skew.d.ts +51 -0
  130. package/dist/packages/baseline/lib/skew.js +75 -0
  131. package/dist/packages/compare/index.d.ts +120 -0
  132. package/dist/packages/compare/index.js +274 -0
  133. package/dist/packages/compare/lib/catalog-notes.d.ts +73 -0
  134. package/dist/packages/compare/lib/catalog-notes.js +224 -0
  135. package/dist/packages/completeness/index.d.ts +246 -0
  136. package/dist/packages/completeness/index.js +249 -0
  137. package/dist/packages/confidence/index.d.ts +54 -0
  138. package/dist/packages/confidence/index.js +71 -0
  139. package/dist/packages/config/index.d.ts +107 -0
  140. package/dist/packages/config/index.js +95 -0
  141. package/dist/packages/config/lib/command-line.d.ts +23 -0
  142. package/dist/packages/config/lib/command-line.js +239 -0
  143. package/dist/packages/config/lib/config-file.d.ts +11 -0
  144. package/dist/packages/config/lib/config-file.js +119 -0
  145. package/dist/packages/config/lib/scan-config-id.d.ts +28 -0
  146. package/dist/packages/config/lib/scan-config-id.js +54 -0
  147. package/dist/packages/config/lib/schema.d.ts +2 -0
  148. package/dist/packages/config/lib/schema.js +31 -0
  149. package/dist/packages/config/lib/types.d.ts +64 -0
  150. package/dist/packages/config/lib/types.js +6 -0
  151. package/dist/packages/config/lib/urls.d.ts +6 -0
  152. package/dist/packages/config/lib/urls.js +9 -0
  153. package/dist/packages/discovery/index.d.ts +277 -0
  154. package/dist/packages/discovery/index.js +1950 -0
  155. package/dist/packages/discovery/lib/import-map.d.ts +68 -0
  156. package/dist/packages/discovery/lib/import-map.js +180 -0
  157. package/dist/packages/discovery/lib/requests.d.ts +58 -0
  158. package/dist/packages/discovery/lib/requests.js +591 -0
  159. package/dist/packages/discovery/lib/scopes.d.ts +6 -0
  160. package/dist/packages/discovery/lib/scopes.js +286 -0
  161. package/dist/packages/discovery/lib/source-maps.d.ts +56 -0
  162. package/dist/packages/discovery/lib/source-maps.js +209 -0
  163. package/dist/packages/discovery/lib/swept-code.d.ts +27 -0
  164. package/dist/packages/discovery/lib/swept-code.js +107 -0
  165. package/dist/packages/discovery/lib/syntax.d.ts +17 -0
  166. package/dist/packages/discovery/lib/syntax.js +39 -0
  167. package/dist/packages/findings/index.d.ts +106 -0
  168. package/dist/packages/findings/index.js +254 -0
  169. package/dist/packages/findings/lib/scope.d.ts +38 -0
  170. package/dist/packages/findings/lib/scope.js +110 -0
  171. package/dist/packages/parallel/index.d.ts +2 -0
  172. package/dist/packages/parallel/index.js +5 -0
  173. package/dist/packages/parallel/lib/protocol.d.ts +15 -0
  174. package/dist/packages/parallel/lib/protocol.js +2 -0
  175. package/dist/packages/parallel/lib/runner.d.ts +36 -0
  176. package/dist/packages/parallel/lib/runner.js +96 -0
  177. package/dist/packages/parallel/lib/schedule.d.ts +16 -0
  178. package/dist/packages/parallel/lib/schedule.js +52 -0
  179. package/dist/packages/parallel/lib/worker.d.ts +1 -0
  180. package/dist/packages/parallel/lib/worker.js +18 -0
  181. package/dist/packages/policy/index.d.ts +36 -0
  182. package/dist/packages/policy/index.js +22 -0
  183. package/dist/packages/report/explain.d.ts +26 -0
  184. package/dist/packages/report/explain.js +99 -0
  185. package/dist/packages/report/index.d.ts +210 -0
  186. package/dist/packages/report/index.js +388 -0
  187. package/dist/packages/report/terminal.d.ts +11 -0
  188. package/dist/packages/report/terminal.js +331 -0
  189. package/dist/packages/source-store/fixture.d.ts +22 -0
  190. package/dist/packages/source-store/fixture.js +58 -0
  191. package/dist/packages/source-store/index.d.ts +278 -0
  192. package/dist/packages/source-store/index.js +322 -0
  193. package/dist/packages/source-store/lib/addresses.d.ts +6 -0
  194. package/dist/packages/source-store/lib/addresses.js +91 -0
  195. package/dist/packages/source-store/lib/connection.d.ts +15 -0
  196. package/dist/packages/source-store/lib/connection.js +135 -0
  197. package/dist/packages/source-store/lib/content-types.d.ts +16 -0
  198. package/dist/packages/source-store/lib/content-types.js +75 -0
  199. package/dist/packages/source-store/lib/data-urls.d.ts +10 -0
  200. package/dist/packages/source-store/lib/data-urls.js +85 -0
  201. package/dist/packages/source-store/lib/deadline.d.ts +18 -0
  202. package/dist/packages/source-store/lib/deadline.js +44 -0
  203. package/dist/packages/source-store/lib/exchange.d.ts +29 -0
  204. package/dist/packages/source-store/lib/exchange.js +112 -0
  205. package/dist/packages/source-store/lib/integrity.d.ts +19 -0
  206. package/dist/packages/source-store/lib/integrity.js +86 -0
  207. package/dist/packages/source-store/lib/outcomes.d.ts +12 -0
  208. package/dist/packages/source-store/lib/outcomes.js +22 -0
  209. package/dist/packages/source-store/lib/proxy.d.ts +11 -0
  210. package/dist/packages/source-store/lib/proxy.js +53 -0
  211. package/dist/packages/source-store/lib/session.d.ts +12 -0
  212. package/dist/packages/source-store/lib/session.js +139 -0
  213. package/dist/packages/source-store/lib/urls.d.ts +6 -0
  214. package/dist/packages/source-store/lib/urls.js +15 -0
  215. package/dist/packages/source-store/resolve.d.ts +59 -0
  216. package/dist/packages/source-store/resolve.js +45 -0
  217. package/dist/scan.d.ts +65 -0
  218. package/dist/scan.js +592 -0
  219. package/package.json +95 -4
  220. package/schema/config.schema.json +133 -0
  221. package/schema/report.schema.json +1905 -0
@@ -0,0 +1,39 @@
1
+ import type { AstNode } from './ast.ts';
2
+ /** A guard an early exit makes: the code after it runs when `test` is `outcome`. */
3
+ export interface ExitGuard {
4
+ test: AstNode;
5
+ outcome: boolean;
6
+ }
7
+ /** The statement lists whose earlier `if (…) return` or `throw` guards the statements after it (§5, §7). */
8
+ export declare const statementLists: Readonly<Record<string, string>>;
9
+ export declare function earlyExits(list: AstNode): {
10
+ index: number;
11
+ guard: ExitGuard;
12
+ }[];
13
+ /** Whether a statement always leaves its function: a `return` or `throw`, a block with one, or an `if` both arms do. */
14
+ export declare function alwaysExits(statement: AstNode): boolean;
15
+ /** The guards of the early exits before `child` in the statement list `list`, first first. None for any other edge. */
16
+ export declare function exitsBefore(list: AstNode, child: AstNode): ExitGuard[];
17
+ /**
18
+ * A condition on a statement's tests, under which control reaches a point: `true`, `false` (it never does), a test
19
+ * with the outcome it takes, or all or any of several conditions.
20
+ */
21
+ export type Condition = boolean | ExitGuard | {
22
+ all: Condition[];
23
+ } | {
24
+ any: Condition[];
25
+ };
26
+ /**
27
+ * When control leaves a statement at its end rather than by a `return` or `throw` in it (§7 early returns): `if (t)
28
+ * return` falls through when `t` is false, and `if (p) { …; if (q) return }` when `p` is false or `q` is. A `continue`
29
+ * leaves too: it ends its loop's iteration, and the loop holds every statement list this walks into, so `if (typeof
30
+ * proto[k] !== 'function') continue` filters a swept key (§5 Resolver capabilities 9). Loops,
31
+ * `switch`, `try` and labelled statements are taken to fall through, and the functions a statement creates are not
32
+ * entered.
33
+ */
34
+ export declare function fallsThrough(statement: AstNode): Condition;
35
+ /**
36
+ * The condition under which control reaches `child` from the start of the statement list `list`: every statement before
37
+ * it fell through. `true` for any other edge.
38
+ */
39
+ export declare function reachedAfter(list: AstNode, child: AstNode): Condition;
@@ -0,0 +1,161 @@
1
+ // Early exits (§5 Global resolution, §7): an `if` whose one arm always returns or throws guards every statement after
2
+ // it in its statement list, nested blocks and the functions created there included, with its test's other outcome. A
3
+ // script's or module's top-level body counts like a function body.
4
+ /** The statement lists whose earlier `if (…) return` or `throw` guards the statements after it (§5, §7). */
5
+ export const statementLists = {
6
+ Program: 'body',
7
+ BlockStatement: 'body',
8
+ StaticBlock: 'body',
9
+ SwitchCase: 'consequent',
10
+ };
11
+ /**
12
+ * The early exits of each statement list, by the index of the statement they guard from: an `if` whose one arm always
13
+ * returns or throws guards every statement after it in its list with its test's other outcome (§7 early returns).
14
+ */
15
+ const exitsOf = new WeakMap();
16
+ export function earlyExits(list) {
17
+ let found = exitsOf.get(list);
18
+ if (found !== undefined)
19
+ return found;
20
+ found = [];
21
+ const key = statementLists[list.type];
22
+ const body = key === undefined ? [] : (list[key] ?? []);
23
+ body.forEach((statement, index) => {
24
+ if (statement.type !== 'IfStatement')
25
+ return;
26
+ const consequent = statement['consequent'];
27
+ const alternate = statement['alternate'];
28
+ const test = statement['test'];
29
+ if (alwaysExits(consequent) && (alternate === null || !alwaysExits(alternate))) {
30
+ found.push({ index, guard: { test, outcome: false } });
31
+ }
32
+ else if (alternate !== null && alwaysExits(alternate) && !alwaysExits(consequent)) {
33
+ found.push({ index, guard: { test, outcome: true } });
34
+ }
35
+ });
36
+ exitsOf.set(list, found);
37
+ return found;
38
+ }
39
+ /** Whether a statement always leaves its function: a `return` or `throw`, a block with one, or an `if` both arms do. */
40
+ export function alwaysExits(statement) {
41
+ switch (statement.type) {
42
+ case 'ReturnStatement':
43
+ case 'ThrowStatement':
44
+ return true;
45
+ case 'BlockStatement':
46
+ return statement['body'].some(alwaysExits);
47
+ case 'IfStatement': {
48
+ const alternate = statement['alternate'];
49
+ return alternate !== null && alwaysExits(statement['consequent']) && alwaysExits(alternate);
50
+ }
51
+ default:
52
+ return false;
53
+ }
54
+ }
55
+ /** The positions of each statement list's statements, for `exitsBefore` and `reachedAfter`. */
56
+ const positionsOf = new WeakMap();
57
+ /** The index of `child` in the statement list `list[key]`, or undefined when it is not one of its statements. */
58
+ function positionIn(list, key, child) {
59
+ let positions = positionsOf.get(list);
60
+ if (positions === undefined) {
61
+ positions = new Map((list[key] ?? []).map((statement, index) => [statement, index]));
62
+ positionsOf.set(list, positions);
63
+ }
64
+ return positions.get(child);
65
+ }
66
+ /** The guards of the early exits before `child` in the statement list `list`, first first. None for any other edge. */
67
+ export function exitsBefore(list, child) {
68
+ const key = statementLists[list.type];
69
+ if (key === undefined)
70
+ return [];
71
+ const exits = earlyExits(list);
72
+ if (exits.length === 0)
73
+ return [];
74
+ const index = positionIn(list, key, child);
75
+ if (index === undefined)
76
+ return [];
77
+ return exits.filter((exit) => exit.index < index).map((exit) => exit.guard);
78
+ }
79
+ function all(conditions) {
80
+ const kept = [];
81
+ for (const each of conditions) {
82
+ if (each === false)
83
+ return false;
84
+ if (each !== true)
85
+ kept.push(each);
86
+ }
87
+ return kept.length === 0 ? true : kept.length === 1 ? kept[0] : { all: kept };
88
+ }
89
+ function any(conditions) {
90
+ const kept = [];
91
+ for (const each of conditions) {
92
+ if (each === true)
93
+ return true;
94
+ if (each !== false)
95
+ kept.push(each);
96
+ }
97
+ return kept.length === 0 ? false : kept.length === 1 ? kept[0] : { any: kept };
98
+ }
99
+ const fallsThroughWhen = new WeakMap();
100
+ /**
101
+ * When control leaves a statement at its end rather than by a `return` or `throw` in it (§7 early returns): `if (t)
102
+ * return` falls through when `t` is false, and `if (p) { …; if (q) return }` when `p` is false or `q` is. A `continue`
103
+ * leaves too: it ends its loop's iteration, and the loop holds every statement list this walks into, so `if (typeof
104
+ * proto[k] !== 'function') continue` filters a swept key (§5 Resolver capabilities 9). Loops,
105
+ * `switch`, `try` and labelled statements are taken to fall through, and the functions a statement creates are not
106
+ * entered.
107
+ */
108
+ export function fallsThrough(statement) {
109
+ let found = fallsThroughWhen.get(statement);
110
+ if (found !== undefined)
111
+ return found;
112
+ switch (statement.type) {
113
+ case 'ReturnStatement':
114
+ case 'ThrowStatement':
115
+ case 'ContinueStatement':
116
+ found = false;
117
+ break;
118
+ case 'BlockStatement':
119
+ found = all(statement['body'].map(fallsThrough));
120
+ break;
121
+ case 'IfStatement': {
122
+ const test = statement['test'];
123
+ const alternate = statement['alternate'];
124
+ const consequent = fallsThrough(statement['consequent']);
125
+ const otherwise = alternate === null ? true : fallsThrough(alternate);
126
+ // When both arms fall through, the test decides nothing: `t || !t` always holds.
127
+ found =
128
+ consequent === true && otherwise === true
129
+ ? true
130
+ : any([all([{ test, outcome: true }, consequent]), all([{ test, outcome: false }, otherwise])]);
131
+ break;
132
+ }
133
+ default:
134
+ found = true;
135
+ }
136
+ fallsThroughWhen.set(statement, found);
137
+ return found;
138
+ }
139
+ /** The conditions under which each statement of a list is reached from the list's start, by index. */
140
+ const reachedWhen = new WeakMap();
141
+ /**
142
+ * The condition under which control reaches `child` from the start of the statement list `list`: every statement before
143
+ * it fell through. `true` for any other edge.
144
+ */
145
+ export function reachedAfter(list, child) {
146
+ const key = statementLists[list.type];
147
+ if (key === undefined)
148
+ return true;
149
+ let conditions = reachedWhen.get(list);
150
+ if (conditions === undefined) {
151
+ conditions = [];
152
+ let sofar = true;
153
+ for (const statement of list[key] ?? []) {
154
+ conditions.push(sofar);
155
+ sofar = all([sofar, fallsThrough(statement)]);
156
+ }
157
+ reachedWhen.set(list, conditions);
158
+ }
159
+ const index = positionIn(list, key, child);
160
+ return index === undefined ? true : conditions[index];
161
+ }
@@ -0,0 +1,138 @@
1
+ import { type Holder, type Realm, type SerializedCatalog } from '../../../catalog.ts';
2
+ import type { AstNode } from './ast.ts';
3
+ import { type Key as MemberKey } from './keys.ts';
4
+ import type { Effect, IneffectiveReason, Locks, Throws } from './types.ts';
5
+ import { type Change, type DescriptorFields, type Write } from './writes.ts';
6
+ /** A write that is a platform mutation: the target it names, its effect, and what the outcome table decides of it. */
7
+ export interface Mutation extends Outcome {
8
+ /** The target's name, e.g. `Window.fetch`. */
9
+ name: string;
10
+ /** The kind of holder the target is on. */
11
+ holder: Holder;
12
+ /** For a shadowing write, the inherited member it shadows (§4): derived, and not identity. */
13
+ shadows?: string;
14
+ }
15
+ /**
16
+ * A write that can't change its target (§3 Ineffective writes): the target it would have changed, the effect it
17
+ * intended, why it can't, and whether it throws. `mayChangeNothing` says that on a value the analyzer can't see the
18
+ * write could instead change nothing (§3 No-op or ineffective).
19
+ */
20
+ export interface Ineffective {
21
+ name: string;
22
+ holder: Holder;
23
+ shadows?: string;
24
+ effect: Effect;
25
+ reason: IneffectiveReason;
26
+ throws: Throws;
27
+ mayChangeNothing: boolean;
28
+ }
29
+ /** Whether an outcome is an ineffective write. */
30
+ export declare const isIneffective: (outcome: Mutation | Ineffective) => outcome is Ineffective;
31
+ /** What a write does to a member it plainly mutates. */
32
+ interface Outcome {
33
+ effect: Effect;
34
+ /**
35
+ * Whether the mutation leaves the target non-configurable or non-writable (§8): `unknown` when that depends on what
36
+ * the analyzer can't see or decide.
37
+ */
38
+ locks: Locks;
39
+ /**
40
+ * When the outcome table can't decide whether the write takes effect (§3 Undecidable outcomes), what the outcome
41
+ * depends on and the analyzer can't see or decide, in source order: the evidence for the mutation-confidence reason
42
+ * `outcome-undecidable` (§9). For a `descriptor`, the parts of a define's descriptor. For a `lookup`, the object a
43
+ * `Reflect.set` looks its member up on, which denotes no native holder. For a `value`, the value an assign of
44
+ * `Window.opener` writes, which may be `null`.
45
+ */
46
+ undecidable?: {
47
+ on: 'descriptor' | 'lookup' | 'value';
48
+ sites: AstNode[];
49
+ };
50
+ }
51
+ /**
52
+ * The descriptor fields (`value`, `get`, `set`, `writable`, `enumerable`, `configurable`) a native holder supplies when
53
+ * it is a descriptor's prototype, as ECMA-262 ToPropertyDescriptor reads them through its chain in the unmutated catalog
54
+ * (§3 Undecidable outcomes). `functions` are the fields whose value is a function. `throwing` are the fields that are a
55
+ * Web IDL attribute: its getter runs on the descriptor, which implements no interface, so it throws a TypeError.
56
+ * `Object.prototype` supplies none. Undefined when the analyzer can't read them: a field that is any other accessor, or
57
+ * a data property that isn't a function.
58
+ */
59
+ export declare function descriptorFieldsOf(holder: string, catalog: SerializedCatalog, realm: Realm): DescriptorFields | undefined;
60
+ /**
61
+ * The outcomes of a write (§3): the platform mutations it makes, or the ineffective writes it is. A define whose
62
+ * descriptor can be several descriptors (several objects the heap holds, or fields that may be absent, §5 Resolver
63
+ * capabilities 5) is judged per descriptor:
64
+ * - When some can change the target, the write can, so it is no ineffective write (§3): it gives one mutation per
65
+ * effect they give. When they don't all give the same effect, or some give none or are ineffective, each has
66
+ * `outcome-undecidable`, with what the outcome depends on as its evidence, and `locks` from the descriptors that give
67
+ * its effect.
68
+ * - When none can, and some are ineffective, the write is ineffective (§3 No-op or ineffective): one ineffective
69
+ * outcome per effect they intend, which may change nothing when any descriptor changes nothing.
70
+ */
71
+ export declare function outcomesOf(write: Write, catalog: SerializedCatalog, realm: Realm): (Mutation | Ineffective)[];
72
+ /**
73
+ * The outcome of a write with one descriptor (§3): the platform mutation it makes, if §3 plainly makes it one, or the
74
+ * ineffective write it is, when it can't change its target. Undefined when it is neither.
75
+ */
76
+ export declare function mutationOf(write: Write, catalog: SerializedCatalog, realm: Realm): Mutation | Ineffective | undefined;
77
+ /**
78
+ * The catalog targets a write of a member on an object the analyzer can't resolve could mutate (§5 Partially resolved
79
+ * writes): every target of the realm with that member whose outcome §3's table could make a mutation, taking the object
80
+ * written to be one that implements the member's interface. API use, a constant member, a define that changes
81
+ * nothing and an ineffective write are left out. Sorted by name.
82
+ */
83
+ export declare function candidateTargets(change: Exclude<Change, {
84
+ kind: 'prototype';
85
+ }>, catalog: SerializedCatalog, realm: Realm): string[];
86
+ /**
87
+ * The outcome of a wildcard write (§3, §5 Partially resolved writes) with the effect its value gives, judged
88
+ * over every catalog member it matches (`wildcardMembers`) as a write of that member would be:
89
+ * - `finding`: some member it matches is changed. `mixed` says others are ineffective (`wildcard-outcome-mixed`, §9).
90
+ * An `add` changes only members the holder lacks, so it is one whenever the holder takes an add.
91
+ * - `ineffective`: every member it matches that the write could change is ineffective, one outcome per reason.
92
+ *
93
+ * Undefined when the write changes none: every member is API use, or changes nothing (a delete through an object that
94
+ * only inherits it), or an `add` on a holder that takes none.
95
+ */
96
+ export type WildcardOutcome = {
97
+ kind: 'finding';
98
+ holder: Holder;
99
+ locks: Locks;
100
+ mixed: boolean;
101
+ undecidable?: Mutation['undecidable'];
102
+ } | {
103
+ kind: 'ineffective';
104
+ holder: Holder;
105
+ refused: Ineffective[];
106
+ };
107
+ export declare function wildcardOutcome(write: Write, effect: Effect, catalog: SerializedCatalog, realm: Realm, members?: readonly MemberKey[], prefixes?: readonly string[]): WildcardOutcome | undefined;
108
+ /**
109
+ * The catalog members a wildcard over `holder` matches (§3): the holder's own members. A singleton instance also
110
+ * matches its interface's members, those of its interface prototype object (`History.prototype` for `history`,
111
+ * `Storage.prototype` for `localStorage`, `Navigator.prototype` with its mixins for `navigator`), without the structural
112
+ * `constructor` and `@@toStringTag`, which are no members of the interface, and not those of shared ancestors.
113
+ */
114
+ export declare function wildcardMembers(holder: string, catalog: SerializedCatalog, realm: Realm): MemberKey[];
115
+ /**
116
+ * The catalog targets a wildcard over `holder` matches among `members` (§5), by name: the holder's own, and for a
117
+ * singleton instance, its interface prototype's.
118
+ */
119
+ export declare function wildcardTargets(holder: string, members: readonly MemberKey[], catalog: SerializedCatalog, realm: Realm): string[];
120
+ /**
121
+ * The catalog members a wildcard over `holder` narrowed to a candidate set matches (§5), each once with its
122
+ * target: those among `members` (`wildcardTargets`), and those of the holder and its chain that start with one of
123
+ * `prefixes` (`prefixMembers`).
124
+ */
125
+ export declare function narrowedMatches(holder: string, members: readonly MemberKey[] | undefined, prefixes: readonly string[], catalog: SerializedCatalog, realm: Realm): {
126
+ member: MemberKey;
127
+ target: string;
128
+ }[];
129
+ /**
130
+ * The catalog members of `holder` and its catalog prototype chain whose key is a string that starts with `prefix`, each
131
+ * once, on its nearest owner, with the target that owner has: what a write there whose key starts with the prefix could
132
+ * name or shadow (§5 Pattern wildcards, ADR 0002). A well-known symbol member starts with no string.
133
+ */
134
+ export declare function prefixMembers(holder: string, prefix: string, catalog: SerializedCatalog, realm: Realm): {
135
+ member: string;
136
+ target: string;
137
+ }[];
138
+ export {};