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,581 @@
1
+ import type { Realm, SerializedCatalog } from '../../../catalog.ts';
2
+ import { type AstNode } from './ast.ts';
3
+ import { type Key } from './keys.ts';
4
+ import { type Definitions } from './definitions.ts';
5
+ import type { ModuleLink, ModuleLinks } from './module-links.ts';
6
+ import { type GlobalBinding, type ScopeRules, type Taint } from './scope.ts';
7
+ import { type Binding, type CallGraph, type Frame } from './summaries.ts';
8
+ import type { Caps } from './budget.ts';
9
+ import type { GlobalForm, RealmInstance } from './types.ts';
10
+ /**
11
+ * How an expression reached a native holder (§14): where the global object was recognized, and in which form, or the
12
+ * step from another value that reached it (a singleton, or another window), after that value's own leaves.
13
+ */
14
+ export interface Leaf {
15
+ /**
16
+ * How the holder was reached: one of the global forms (§5), or `prototype-of`, `Object.getPrototypeOf(h)` of a native
17
+ * holder, which the unmutated catalog decides (§4).
18
+ */
19
+ form: GlobalForm | 'prototype-of';
20
+ /** The node recognized: an identifier, a `this`, or the `Function('return this')()` call. */
21
+ node: AstNode;
22
+ /** The name the form starts from: `window`, `global`, `this`, `Function`, `XMLHttpRequest`; `[0]` for an index read. */
23
+ name: string;
24
+ /** For a name, how it resolved: to no declaration, or to one that binds the global object's property (§5). */
25
+ binding?: GlobalBinding;
26
+ /** For a global property, the holder the catalog says its value is; for a singleton, the singleton. */
27
+ holds?: string;
28
+ /** For a singleton, the access path from the global object its alias group lists (`document.location`). */
29
+ path?: string;
30
+ /** For a `typeof`-guarded `global`, the test that guards it. */
31
+ guard?: AstNode;
32
+ /** The outermost `?:`, `||`, `&&` or `??` chain the leaf was selected through. */
33
+ chain?: AstNode;
34
+ /** The window the value belongs to: the artifact's own (`current`), another (`other`), or either (`unknown`). */
35
+ instance: RealmInstance;
36
+ /** For a step from another value (`window.parent`), the leaves that value was reached from. */
37
+ base?: Leaf[];
38
+ /**
39
+ * For another window, the window expression it is (§3 Undecidable outcomes), as a key: `~.parent`, `~[0]`,
40
+ * `(#x).contentWindow`. It is undefined when the analyzer can't show that two reads of it reach one window.
41
+ */
42
+ window?: string;
43
+ /** For a child window (an index read on a window), the window expression of the window it is a child of. */
44
+ childOf?: string;
45
+ /**
46
+ * Whether the window was read as the frames collection (§5 Other windows): a bare `frames`, `.frames`, or a constant
47
+ * `["frames"]`. The mark travels with the value, and reading any other member drops it. Only a window spelled so takes
48
+ * an unresolved key as a child window.
49
+ */
50
+ frames?: true;
51
+ /**
52
+ * For `Object.getPrototypeOf(h)`, the holder `h` whose prototype it is. Its `holds` is that prototype, and `base` the
53
+ * leaves `h` was reached from.
54
+ */
55
+ prototypeOf?: string;
56
+ /** For `Object.getPrototypeOf(h)`, the leaves the native `Object` it calls was reached from. */
57
+ callee?: Leaf[];
58
+ }
59
+ /**
60
+ * The window expression a value was reached through (§3 Undecidable outcomes): the window it belongs to, as a key that
61
+ * two reads of the same window expression share. It is undefined when its leaves disagree, or one reaches a window the
62
+ * analyzer can't name.
63
+ */
64
+ export declare function windowOf(leaves: readonly Leaf[]): string | undefined;
65
+ /**
66
+ * Whether two values were reached through the same window (§3 Undecidable outcomes): the same window expression, which
67
+ * the analyzer can show reaches one window both times. Only this window stays the same whatever the code does. Another
68
+ * window expression can reach another window once the program's state changes (`x`, `i` or the frames in
69
+ * `x.contentWindow` or `frames[i]`, or a replaced `parent`), so it is the same only when nothing `evaluated` around the
70
+ * two reads can change that state.
71
+ */
72
+ export declare function sameWindow(a: readonly Leaf[], b: readonly Leaf[], evaluated: readonly AstNode[]): boolean;
73
+ /** The name of the realm's global object holder, e.g. `Window`. */
74
+ export declare function globalHolder(catalog: SerializedCatalog, realm: Realm): string;
75
+ /** Leaves in document order, as a trace lists their binding steps. */
76
+ export declare const inDocumentOrder: (leaves: readonly Leaf[]) => Leaf[];
77
+ /** A primitive constant the analyzer knows: a well-known symbol is one too (§4 Property keys, `keys.ts`). */
78
+ export type Primitive = string | number | bigint | boolean | null | undefined | symbol;
79
+ /**
80
+ * A fold (§14): an expression the analyzer folded to a constant. It is a `+` or a template literal with constant parts,
81
+ * or a `const` read through its `name`, whose value comes from `node`: its initializer, the element or property it
82
+ * destructures, or a default. `taint` is what lies between the name and its declaration (§5 post-pass 3). The trace
83
+ * records a fold only when JSON can carry its value, but it records a fold's taint whatever the value.
84
+ */
85
+ export interface Fold {
86
+ node: AstNode;
87
+ name?: string;
88
+ value: Primitive;
89
+ taint?: Taint;
90
+ /** For a well-known symbol, the leaves of the `Symbol` holder it was read from, whose steps come before the fold's. */
91
+ via?: Leaf[];
92
+ /**
93
+ * For an alias (§5 Resolver capabilities 2): the value was read through the variable `name`, from its definition
94
+ * `node` (a declarator, an assignment, an update or a loop head). Its `value` is undefined, and the trace records it as
95
+ * an `alias` step.
96
+ */
97
+ alias?: true;
98
+ /**
99
+ * For a summarized call (§5 Resolver capabilities 3): the value was bound to a parameter, or returned, by the call
100
+ * `node`, whose site and frame this is. Its `name` is `()` and its `value` undefined, and the trace records it as a
101
+ * `call` step.
102
+ */
103
+ call?: Binding;
104
+ /** For a summarized call's parameter, the index of the argument the value came in through. */
105
+ argument?: number;
106
+ /** For a summarized call, that the value is the call's `this`: the receiver of a method, a `new`'s instance. */
107
+ receiver?: true;
108
+ /**
109
+ * For a value read from the heap (§5 Resolver capabilities 5): `node` is the expression that gave the field its value
110
+ * (a literal's property value, or the value a write assigns). A value that carries one never decides a test. Its
111
+ * `name` is `.` and its `value` undefined, and the trace records no step for it.
112
+ */
113
+ heap?: true;
114
+ /**
115
+ * For a heap fold: the value is a field of an object literal passed directly as a call argument, read inside that
116
+ * call's summary instance (§5 Resolver capabilities 5): the literal, `decides`, whose
117
+ * field it is. Such a value still decides no test until a test settles it (`settled`): an arm's test, or a `?:`,
118
+ * `&&`, `||` or `??` selection, once nothing writes to the literal.
119
+ */
120
+ decides?: Allocation;
121
+ /** For a heap fold with `decides`: a test settled it, so the value decides that test. */
122
+ settled?: true;
123
+ /**
124
+ * For a value read through a once-flag (§5 Resolver capabilities 6): `node` is the read. A value that carries one never
125
+ * decides a test. Its `name` is `?` and its `value` undefined, and the trace records no step for it.
126
+ */
127
+ flag?: true;
128
+ /**
129
+ * For an own-property test the unmutated catalog decided (§4 A holder chosen at runtime, §5 Resolver capabilities 8):
130
+ * `node` is the test, and `value` whether the holder owns the member. The trace records it as a `catalog-holder` step.
131
+ */
132
+ catalog?: OwnTest;
133
+ /**
134
+ * For a prototype walk the unmutated catalog simulated (§4 A holder chosen at runtime): `node` is the loop, and the
135
+ * walk's holders, in order, end in the one the value is. The trace records it as a `catalog-holder` step.
136
+ */
137
+ walked?: WalkChoice;
138
+ /**
139
+ * For a module link (§6): the value came through a require call or a module's export, which `node` is. Its `name` is
140
+ * `module-link` and its `value` undefined, and the trace records it as a `module-link` step.
141
+ */
142
+ link?: ModuleLink;
143
+ /**
144
+ * For a key a member sweep gave (§5 Resolver capabilities 9): `node` is the enumeration (the call, or the `for…in`
145
+ * loop's object), and the sweep says which holder, how, which member, and the filters the key went through. Its
146
+ * `name` is `#` and its `value` the key, and the trace records it as an `enumeration` step.
147
+ */
148
+ sweep?: Sweep;
149
+ }
150
+ /** How a member sweep enumerates a native holder's keys (§5 Resolver capabilities 9). */
151
+ export declare const sweepForms: readonly ["for-in", "Object.keys", "Object.getOwnPropertyNames", "Object.entries", "Object.getOwnPropertyDescriptors", "Reflect.ownKeys", "Object.getOwnPropertySymbols"];
152
+ export type SweepForm = (typeof sweepForms)[number];
153
+ /**
154
+ * A key a member sweep gave (§5 Resolver capabilities 9): the native `holder` swept, the enumeration `form`, the
155
+ * catalog `member` the key is, as the catalog spells it, and each filter the key went through, in order: `kept` when
156
+ * the filter keeps it, `undecided` when the analyzer can't tell, which makes reachability `conditional`.
157
+ */
158
+ export interface Sweep {
159
+ holder: string;
160
+ form: SweepForm;
161
+ member: string;
162
+ filters: readonly {
163
+ node: AstNode;
164
+ result: 'kept' | 'undecided';
165
+ }[];
166
+ }
167
+ /** The sweeps a value's key came from (§5 Resolver capabilities 9). */
168
+ export declare function sweepsOf(value: Value): Sweep[];
169
+ /** Whether a value carries a key a member sweep gave. */
170
+ export declare const isSwept: (value: Value) => boolean;
171
+ /** A prototype walk's holders from its start value, in order, the `holder` it stops at, and the `member` it looks for. */
172
+ export interface WalkChoice {
173
+ walk: string[];
174
+ holder: string;
175
+ member?: string;
176
+ }
177
+ /**
178
+ * An own-property test the unmutated catalog decided (§4): whether the native holder `tested` owns `member`, a catalog
179
+ * member spelt as the catalog spells it (`pushState`, `@@iterator`). With no `member`, the key didn't fold, and the
180
+ * holder owns no catalog member other than the structural `constructor`, `@@toStringTag` and `prototype`, so it owns
181
+ * none that counts.
182
+ */
183
+ export interface OwnTest {
184
+ tested: string;
185
+ member?: string;
186
+ owns: boolean;
187
+ }
188
+ /**
189
+ * An abstract value: a native holder reached from the global object, with every leaf it was reached from; a primitive
190
+ * constant; an object the analyzer knows is no native holder (a literal, a function, an instance); or unknown. A holder
191
+ * or constant carries the folds it comes from, in the order they were made: each after those it folds. A value a
192
+ * constant decided, such as the branch a `?:` with a constant test takes, carries that constant's folds too.
193
+ */
194
+ export type Value =
195
+ /**
196
+ * `absent`: a native holder read as a property of the global object (`window.EventTarget`, `self.document`), which
197
+ * may be missing, so a test on it may be falsy (§7). The global object, a bare global
198
+ * name and a holder read from any other holder are always present.
199
+ */
200
+ {
201
+ kind: 'holder';
202
+ holder: string;
203
+ leaves: Leaf[];
204
+ folds?: Fold[];
205
+ absent?: true;
206
+ }
207
+ /**
208
+ * `tested`: a heap-read or once-flag boolean, `null` or `undefined` that `&&`, `||` or `??` gives back from its
209
+ * undecided test operand. It is never a key (§5 Candidate sets).
210
+ */
211
+ | {
212
+ kind: 'constant';
213
+ value: Primitive;
214
+ folds?: Fold[];
215
+ tested?: true;
216
+ } | {
217
+ kind: 'native';
218
+ name: NativeName;
219
+ leaves: Leaf[];
220
+ folds?: Fold[];
221
+ sites?: AstNode[];
222
+ }
223
+ /**
224
+ * `assumed`: an object that is only a caller-less function's assumed `this` (§5 Resolver capabilities 3), the object
225
+ * it is held on, and whatever reached it only from there. A write through it makes no literal non-constant (§5
226
+ * Resolver capabilities 4).
227
+ */
228
+ | {
229
+ kind: 'object';
230
+ heap?: Allocation;
231
+ folds?: Fold[];
232
+ assumed?: true;
233
+ } | {
234
+ kind: 'member';
235
+ target: string;
236
+ holder: string;
237
+ sites: AstNode[];
238
+ leaves: Leaf[];
239
+ folds?: Fold[];
240
+ }
241
+ /**
242
+ * `prefix`: a string the analyzer can't fold whole, but whose start a `+` or a template folds to this non-empty
243
+ * constant (`'__zone_symbol__' + name`). Everything but a write's key takes it as unknown (§5 Pattern wildcards).
244
+ */
245
+ | {
246
+ kind: 'unknown';
247
+ prefix?: string;
248
+ };
249
+ export type HolderValue = Extract<Value, {
250
+ kind: 'holder';
251
+ }>;
252
+ /**
253
+ * A catalog function read from a native holder (§5 Resolver capabilities 10): `window.fetch`, a bare `fetch`,
254
+ * `EventTarget.prototype.addEventListener`, as the unmutated catalog has it. `target` is the catalog target the read
255
+ * reaches on `holder`'s chain, and `sites` the reads that gave it. Only wrap evidence tells it from an unknown value:
256
+ * everything else treats it as unknown (`opaque`), so it never decides a test.
257
+ */
258
+ export type MemberValue = Extract<Value, {
259
+ kind: 'member';
260
+ }>;
261
+ /** Whether a value is one the analyzer treats as unknown: unknown, or a catalog function (`MemberValue`). */
262
+ export declare const opaque: (value: Value) => boolean;
263
+ export type ObjectValue = Extract<Value, {
264
+ kind: 'object';
265
+ }>;
266
+ export type HeapValue = ObjectValue & {
267
+ heap: Allocation;
268
+ };
269
+ /**
270
+ * An allocation site (§5 Resolver capabilities 5): a syntactic site that makes an object, in one summary instantiation
271
+ * or unrolled loop iteration, `frame`. Its fields are evaluated where it is, at `at`.
272
+ * - `literal`: an object literal, or `Object.create(null)`, which is treated like `{}`
273
+ * - `array`: an array literal, whose elements are capability 4's (§5), so only its expandos are heap fields
274
+ * - `instance`: a `new` expression, whose constructor may give it fields the analyzer doesn't see
275
+ * - `returned`: an object a native returns (`Object.getOwnPropertyDescriptor`), with unseen base fields
276
+ * - `copy`: `Object.assign(literal, …sources)`, which copies each source's seen fields into the literal as a spread does
277
+ * - `function`: a function or class, created in the frame `at.frame`, whose free variables it reads there (its closure)
278
+ * - `prototype`: the object a function's or class's `prototype` holds, made with it
279
+ * - `bound`: what `f.bind(t, …args)` returns
280
+ *
281
+ * An `instance` whose node is a class is the class's generic instance: the one its members run with when no `new` of it
282
+ * was analyzed (§5 Resolver capabilities 3).
283
+ */
284
+ export interface Allocation {
285
+ id: string;
286
+ node: AstNode;
287
+ at: Position;
288
+ frame: string | undefined;
289
+ kind: 'literal' | 'array' | 'instance' | 'returned' | 'copy' | 'function' | 'prototype' | 'bound';
290
+ }
291
+ /** Whether a value is an object the heap holds. */
292
+ export declare const isHeap: (value: Value) => value is HeapValue;
293
+ /**
294
+ * A part of an object as a descriptor reads it (§3 Undecidable outcomes, §5 Resolver capabilities 5), in the order
295
+ * ToPropertyDescriptor's view of it is built:
296
+ * - `field`: a field the object has, with its key, the property or write that gives it, and whether that is a getter or
297
+ * setter. `sources` are the expressions that give its value, each where it is evaluated. `maybe` is the write that
298
+ * gives a field written after allocation, which may be absent.
299
+ * - `unseen`: a part that may give any field: a spread or key that doesn't fold, an object's unseen base fields.
300
+ * - `proto`: a literal's `__proto__: p`, whose object supplies the fields the literal lacks.
301
+ */
302
+ export type ObjectPart = {
303
+ kind: 'field';
304
+ key: Key;
305
+ site: AstNode;
306
+ accessor?: 'get' | 'set';
307
+ sources: {
308
+ node: AstNode;
309
+ at: Position;
310
+ }[];
311
+ values: Value[];
312
+ folds: Fold[];
313
+ maybe?: AstNode;
314
+ } | {
315
+ kind: 'unseen';
316
+ node: AstNode;
317
+ } | {
318
+ kind: 'proto';
319
+ site: AstNode;
320
+ values: Value[];
321
+ };
322
+ /** One object a descriptor can be: its allocation site and its parts. */
323
+ export interface ObjectParts {
324
+ node: AstNode;
325
+ parts: ObjectPart[];
326
+ }
327
+ export type NativeValue = Extract<Value, {
328
+ kind: 'native';
329
+ }>;
330
+ /**
331
+ * The native functions a value can be, so that an alias of one is followed (§5 Resolver capabilities 2): the writer
332
+ * functions (by catalog name, `Object.defineProperty`); the functions a route to a native that compiles code goes
333
+ * through (`Function.prototype.call`, `Reflect.apply`, `Object.getOwnPropertyDescriptor`, `code-routes.ts`), of which
334
+ * `Object.getPrototypeOf` also chooses a holder against the catalog; and the global object's functions that compile
335
+ * code from strings (`eval`, `setTimeout`, `setInterval`). The `Function` constructor is a holder.
336
+ */
337
+ declare const nativeReaderNames: readonly ["Object.hasOwn", "Object.prototype.hasOwnProperty", "Object.getPrototypeOf", "Reflect.getPrototypeOf", "Reflect.get", "Object.getOwnPropertyDescriptor", "Reflect.getOwnPropertyDescriptor", "Reflect.apply", "Reflect.construct", "Function.prototype.call", "Function.prototype.apply", "Function.prototype.bind"];
338
+ export declare const nativeWriterNames: readonly ["Object.defineProperty", "Reflect.defineProperty", "Object.defineProperties", "Object.assign", "Object.setPrototypeOf", "Reflect.setPrototypeOf", "Reflect.set", "Reflect.deleteProperty"];
339
+ declare const nativeCompilerNames: readonly ["eval", "setTimeout", "setInterval"];
340
+ export type NativeName = (typeof nativeWriterNames)[number] | (typeof nativeCompilerNames)[number] | (typeof nativeReaderNames)[number];
341
+ /** The realm instance of a value reached from several leaves: theirs when they agree, otherwise `unknown`. */
342
+ export declare function instanceOf(leaves: readonly Leaf[]): RealmInstance;
343
+ /** What is known at a position in the program. */
344
+ export interface Position {
345
+ /** The `typeof` test around the position that shows the free name is defined, if there is one. */
346
+ guard(name: string): AstNode | undefined;
347
+ /** Whether `this` at the position is the script's top-level `this` (no function, field or static block around it). */
348
+ topLevel: boolean;
349
+ /**
350
+ * The instantiation of the function the position is in (§5 Resolver capabilities 3): its parameters take the
351
+ * arguments of the frame's calls. None when the function runs with unknown arguments.
352
+ */
353
+ frame?: Frame | undefined;
354
+ }
355
+ export interface GlobalResolution {
356
+ /** The values an expression can have at a position. */
357
+ evaluate(node: AstNode, at: Position): Value[];
358
+ /**
359
+ * The object and key of an own-property test call, by any route (§4 A holder chosen at runtime): `Object.hasOwn(h,
360
+ * k)`, `h.hasOwnProperty(k)`, through `.call`, `.apply` or `Reflect.apply`. The key is `null` when the call passes
361
+ * none. Undefined for a call that is no such test.
362
+ */
363
+ ownTestParts(call: AstNode, at: Position): {
364
+ object: AstNode;
365
+ key: AstNode | null;
366
+ } | undefined;
367
+ /**
368
+ * Finds the calls whose callees the syntax doesn't name (§5 Resolver capabilities 3), before any other evaluation,
369
+ * so that it starts with nothing else on the stack.
370
+ */
371
+ prepare(): void;
372
+ /**
373
+ * The values a called name can have when it may be an alias of a native function or holder (§5 Resolver capabilities
374
+ * 2): a variable one of whose definitions reads a name or a member, or destructures one. None for any other name, so
375
+ * that the many calls of local functions cost nothing.
376
+ */
377
+ aliasCallee(id: AstNode, at: Position): Value[];
378
+ /**
379
+ * The free names a `typeof` guard shows are defined when control enters `child` of `parent`, each with the `typeof`
380
+ * test that shows it: in the consequent or alternate of an `if` or `?:`, or the right side of `&&` or `||`.
381
+ */
382
+ guards(parent: AstNode, child: AstNode): Guards;
383
+ /**
384
+ * Runs `run`, and gives with its result the folds that passed the `fold-length` cap in what it evaluated (§13
385
+ * `analysis-budget`), each once: those it hit, and those of the constants it read, whether their hits were counted
386
+ * then or before. They count for any `tracked` run around this one too, unless this one is `apart`.
387
+ */
388
+ tracked<T>(run: () => T, apart?: boolean): {
389
+ value: T;
390
+ capped: AstNode[];
391
+ };
392
+ /**
393
+ * Runs `run`, and gives with its result the functions whose parameters it read with no frame to bind them (§5
394
+ * Resolver capabilities 3): a write that reads them is instantiated in each frame of its function.
395
+ */
396
+ contextual<T>(run: () => T): {
397
+ value: T;
398
+ functions: ReadonlySet<AstNode>;
399
+ };
400
+ /**
401
+ * The frames a function is instantiated in for the writes in it (§5 Resolver capabilities 3), out along its calls:
402
+ * none when no call of it is known.
403
+ */
404
+ framesOf(fn: AstNode, deep?: boolean): Frame[];
405
+ /**
406
+ * The resolved calls of a function (§7 Where reachability is judged from), each with the frame of its caller when the
407
+ * resolver has one: the calls the syntax names, in document order, then those it doesn't (methods, callbacks,
408
+ * closures, the call natives), as the dynamic-call index found them. A module's factory is called by the require calls
409
+ * that link its module (§6). Finding them counts no cap hit: it reads only what the resolver has found.
410
+ */
411
+ callersOf(fn: AstNode): Binding[];
412
+ /**
413
+ * Whether a call argument literal may decide a test in `fn`'s own code (§5 Resolver capabilities 5): some call
414
+ * passes `fn` an object literal directly, and the test reads a field of one of `fn`'s parameters. Only such a test is
415
+ * evaluated in a call's frame for it.
416
+ */
417
+ argumentTest(test: AstNode, fn: AstNode): boolean;
418
+ /** A test's values, with each call argument literal's field that nothing writes to settled, to decide it. */
419
+ settled(values: Value[]): Value[];
420
+ /**
421
+ * Runs `run`, and gives with its result the tests a call argument literal's field decided in what it evaluated,
422
+ * each with that literal, once: those it settled, and those settled while finding the values it read.
423
+ */
424
+ decided<T>(run: () => T): {
425
+ value: T;
426
+ decisions: Decision[];
427
+ };
428
+ /**
429
+ * Runs `run` as the evaluation would be without some of the argument-literal rule's decisions: no test
430
+ * `unsettles` holds for is settled. What it evaluates is memoized apart, under `variant`, and its steps and cap hits
431
+ * count as any evaluation's do, so a caller that only compares results undoes them.
432
+ */
433
+ counterfactual<T>(variant: string, unsettles: (decision: Decision) => boolean, run: () => T): T;
434
+ /** The node a node is a child of. */
435
+ parentOf(node: AstNode): AstNode | undefined;
436
+ /** Whether a member sweep has given keys yet (§5 Resolver capabilities 9): no value is a swept key before one has. */
437
+ swept(): boolean;
438
+ /**
439
+ * Whether a read names a once-flag by use (§5 Resolver capabilities 6): a variable or parameter some function tests and
440
+ * then assigns on the path the test lets through, whatever it reads.
441
+ */
442
+ onceFlag(id: AstNode): boolean;
443
+ /**
444
+ * The frame a function or class runs in with no call known: the closure it was made in, with unknown parameters
445
+ * and no `this` of its own. A function object's body is read in it for wrap evidence (§5 Resolver capabilities 10).
446
+ */
447
+ closureFrame(fn: AstNode, closure: Frame | undefined): Frame;
448
+ /**
449
+ * The argument values a call site passes, evaluated in `caller`, one list per argument bound to a parameter (for the
450
+ * lookup of a write inside a helper, §10).
451
+ */
452
+ argumentValues(binding: Binding): Value[][];
453
+ /**
454
+ * Whether the argument `index` of a call carries the member `key` that came in through it (§10): it is the key,
455
+ * or holds it as an element of a constant collection, or is a string the helper splits into it (`member` has that
456
+ * split's fold), or an object the member was read out of through heap fields (`member` has a heap fold).
457
+ */
458
+ argumentCarries(binding: Binding, index: number, key: Key, member: readonly Fold[]): boolean;
459
+ /**
460
+ * The objects a descriptor expression can be, each with its parts as ToPropertyDescriptor reads them (§3, §5 Resolver
461
+ * capabilities 5): undefined unless every value it can have is an object the heap holds.
462
+ */
463
+ objectParts(node: AstNode, at: Position): ObjectParts[] | undefined;
464
+ /**
465
+ * The values a descriptor expression can be, as alternatives (§3 Undecidable outcomes, Principle 3): the
466
+ * objects the heap holds, each with its parts as ToPropertyDescriptor reads them; whether it can be a primitive,
467
+ * which ToPropertyDescriptor refuses; and whether it can be anything else, which the analyzer can't see.
468
+ */
469
+ descriptorValues(node: AstNode, at: Position): {
470
+ objects: ObjectParts[];
471
+ primitive: boolean;
472
+ unseen: boolean;
473
+ };
474
+ /**
475
+ * The expressions that give a member read's value when it reads a field of objects the heap holds, each where it is
476
+ * evaluated: undefined unless every value comes from one, with no part the analyzer can't see.
477
+ */
478
+ fieldSources(member: AstNode, at: Position): {
479
+ node: AstNode;
480
+ at: Position;
481
+ }[] | undefined;
482
+ /**
483
+ * The expression an iteration native's callback is passed as its parameter `index` by `binding` (§5 Resolver
484
+ * capabilities 4), where it is evaluated: an array literal's element. Undefined for any other binding or parameter.
485
+ */
486
+ givenSource(binding: Binding, index: number): {
487
+ node: AstNode;
488
+ at: Position;
489
+ } | undefined;
490
+ }
491
+ /** Free names a `typeof` test shows are defined, each with the test. */
492
+ export type Guards = ReadonlyMap<string, AstNode>;
493
+ export declare function globalResolution(context: {
494
+ /** The program analyzed, whose loops may be unrolled (§5 Resolver capabilities 4). */
495
+ program: AstNode;
496
+ catalog: SerializedCatalog;
497
+ realm: Realm;
498
+ /** The realm's global holder, e.g. `Window`. */
499
+ global: string;
500
+ sourceType: 'script' | 'module';
501
+ scope: ScopeRules;
502
+ /** The definitions of the program's variables, and those that reach each read (§5 Resolver capabilities 2). */
503
+ definitions: Definitions;
504
+ /**
505
+ * The window whose global object the code's free names are properties of: the artifact's own, or, for code another
506
+ * window's `eval`, `Function` or timer compiles, that window.
507
+ */
508
+ instance: RealmInstance;
509
+ /**
510
+ * Counts a cap that changed a value at `node` (§18 Context policy): `alternatives`, or `fold-length`. Whether a
511
+ * `fold-length` hit also raises `analysis-budget` depends on what it cuts (§13, `tracked`).
512
+ */
513
+ cap(name: CapHit['name'], node: AstNode): void;
514
+ /**
515
+ * Counts a hit of a cap that bounds no value, once for the node where it cut (§18): `flagDepth`, at a function
516
+ * a once-flag's assignment isn't followed into, and `nesting`, at a constant read too deep within others.
517
+ */
518
+ capHit(name: 'flagDepth' | 'nesting', node: AstNode): void;
519
+ /** The calls of the program's functions (§5 Resolver capabilities 3). */
520
+ calls: CallGraph;
521
+ /**
522
+ * Raises `analysis-budget` for the call `site`, which a recursion or context cap widened or merged while it carries
523
+ * the global object, a native holder or a native member (Principle 5).
524
+ */
525
+ budget(site: AstNode, cap: 'recursion' | 'contexts'): void;
526
+ /** The caps (§18 Context policy). */
527
+ caps: Caps;
528
+ /**
529
+ * Counts one step of the link group's step budget (§18): each value evaluated. It throws once the budget is
530
+ * exhausted, which abandons the group's analysis where it is.
531
+ */
532
+ step(): void;
533
+ /** The artifact's module links (§6): the definer's modeled defines, and the require calls. */
534
+ links: ModuleLinks;
535
+ }): GlobalResolution;
536
+ /**
537
+ * The values a `const` gives a name, with the expression they come from, for its fold (§14), and the folds that passed
538
+ * the `fold-length` cap while they were found.
539
+ */
540
+ /** A test a call argument literal's field decided, with that literal. */
541
+ export interface Decision {
542
+ test: AstNode;
543
+ literal: AstNode;
544
+ }
545
+ /**
546
+ * A cap that changed a value (§18), at the node where it applied: `alternatives`, a value with too many alternatives,
547
+ * or `fold-length`, a string fold too long.
548
+ */
549
+ export interface CapHit {
550
+ name: 'alternatives' | 'fold-length' | 'recursion' | 'contexts' | 'iterations';
551
+ node: AstNode;
552
+ }
553
+ /** Whether a fold's value can be recorded in the trace, which is JSON: a string, a finite number, a boolean or `null`. */
554
+ export declare const recordable: (value: Primitive) => value is string | number | boolean | null;
555
+ /** Whether a call's arguments include an object literal passed directly, whose fields may decide tests. */
556
+ export declare const passesLiteral: (args: readonly AstNode[]) => boolean;
557
+ /**
558
+ * Two lists of folds, each fold once, in order. A call's folds stay apart by what came through the call: each argument,
559
+ * its `this`, and what it returns, so that a lookup finds the argument a member came in through (§10).
560
+ */
561
+ export declare function mergedFolds(a: readonly Fold[], b: readonly Fold[]): Fold[];
562
+ /**
563
+ * How a test whose values a call argument literal's field decides comes out (§5 Resolver capabilities 5): every
564
+ * value a constant that decides, at least one read through such a field. Undefined for any other test, which this
565
+ * rule leaves as it was.
566
+ */
567
+ export declare function argumentDecided(values: readonly Value[]): boolean | undefined;
568
+ /**
569
+ * The call argument literals whose fields settled a test's values, in document order: what a `prune` step names
570
+ * as having settled the test.
571
+ */
572
+ export declare function settlingLiterals(values: readonly Value[]): AstNode[];
573
+ /** Whether a value is truthy whichever of `values` it is: `true` or `false` when every one agrees, else undefined. */
574
+ export declare function truthiness(values: readonly Value[]): boolean | undefined;
575
+ /**
576
+ * The leaves without a twin: a leaf of the same node as an earlier one, that differs from it only in the frames mark. A
577
+ * marked and an unmarked read of one node stay two leaves only while the mark tells them apart (`union`); once both
578
+ * carry it or neither does, or once a trace lists their steps, they are one read.
579
+ */
580
+ export declare const onePerNode: (leaves: readonly Leaf[]) => Leaf[];
581
+ export {};