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.
- package/LICENSE +202 -0
- package/NOTICE +61 -0
- package/README.md +183 -2
- package/catalog/catalog.json +552211 -0
- package/catalog/catalog.schema.json +787 -0
- package/catalog/changelog.json +3 -0
- package/dist/bin/monkeypatchlist.d.ts +2 -0
- package/dist/bin/monkeypatchlist.js +3 -0
- package/dist/catalog.d.ts +561 -0
- package/dist/catalog.js +58 -0
- package/dist/cli.d.ts +84 -0
- package/dist/cli.js +470 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/lockfile-input.d.ts +9 -0
- package/dist/lockfile-input.js +91 -0
- package/dist/packages/analysis/binding.d.ts +2 -0
- package/dist/packages/analysis/binding.js +5 -0
- package/dist/packages/analysis/index.d.ts +10 -0
- package/dist/packages/analysis/index.js +13 -0
- package/dist/packages/analysis/job.d.ts +33 -0
- package/dist/packages/analysis/job.js +85 -0
- package/dist/packages/analysis/lib/absence-tags.d.ts +34 -0
- package/dist/packages/analysis/lib/absence-tags.js +340 -0
- package/dist/packages/analysis/lib/ast.d.ts +28 -0
- package/dist/packages/analysis/lib/ast.js +64 -0
- package/dist/packages/analysis/lib/binding.d.ts +36 -0
- package/dist/packages/analysis/lib/binding.js +66 -0
- package/dist/packages/analysis/lib/budget.d.ts +80 -0
- package/dist/packages/analysis/lib/budget.js +31 -0
- package/dist/packages/analysis/lib/catch-arms.d.ts +19 -0
- package/dist/packages/analysis/lib/catch-arms.js +351 -0
- package/dist/packages/analysis/lib/chunk-loads.d.ts +160 -0
- package/dist/packages/analysis/lib/chunk-loads.js +882 -0
- package/dist/packages/analysis/lib/chunk-registry.d.ts +45 -0
- package/dist/packages/analysis/lib/chunk-registry.js +334 -0
- package/dist/packages/analysis/lib/code-routes.d.ts +52 -0
- package/dist/packages/analysis/lib/code-routes.js +921 -0
- package/dist/packages/analysis/lib/collisions.d.ts +22 -0
- package/dist/packages/analysis/lib/collisions.js +103 -0
- package/dist/packages/analysis/lib/definitions.d.ts +76 -0
- package/dist/packages/analysis/lib/definitions.js +782 -0
- package/dist/packages/analysis/lib/early-exits.d.ts +39 -0
- package/dist/packages/analysis/lib/early-exits.js +161 -0
- package/dist/packages/analysis/lib/effect.d.ts +138 -0
- package/dist/packages/analysis/lib/effect.js +800 -0
- package/dist/packages/analysis/lib/global-object.d.ts +581 -0
- package/dist/packages/analysis/lib/global-object.js +8240 -0
- package/dist/packages/analysis/lib/keys.d.ts +33 -0
- package/dist/packages/analysis/lib/keys.js +82 -0
- package/dist/packages/analysis/lib/line-starts.d.ts +41 -0
- package/dist/packages/analysis/lib/line-starts.js +79 -0
- package/dist/packages/analysis/lib/link-group.d.ts +51 -0
- package/dist/packages/analysis/lib/link-group.js +487 -0
- package/dist/packages/analysis/lib/module-links.d.ts +117 -0
- package/dist/packages/analysis/lib/module-links.js +1060 -0
- package/dist/packages/analysis/lib/nested-code.d.ts +38 -0
- package/dist/packages/analysis/lib/nested-code.js +200 -0
- package/dist/packages/analysis/lib/numeric.d.ts +16 -0
- package/dist/packages/analysis/lib/numeric.js +216 -0
- package/dist/packages/analysis/lib/once-flags.d.ts +12 -0
- package/dist/packages/analysis/lib/once-flags.js +190 -0
- package/dist/packages/analysis/lib/parameter-arguments.d.ts +12 -0
- package/dist/packages/analysis/lib/parameter-arguments.js +34 -0
- package/dist/packages/analysis/lib/parse.d.ts +10 -0
- package/dist/packages/analysis/lib/parse.js +39 -0
- package/dist/packages/analysis/lib/partial.d.ts +60 -0
- package/dist/packages/analysis/lib/partial.js +518 -0
- package/dist/packages/analysis/lib/print.d.ts +3 -0
- package/dist/packages/analysis/lib/print.js +150 -0
- package/dist/packages/analysis/lib/reachability.d.ts +137 -0
- package/dist/packages/analysis/lib/reachability.js +1295 -0
- package/dist/packages/analysis/lib/resolver.d.ts +13 -0
- package/dist/packages/analysis/lib/resolver.js +2886 -0
- package/dist/packages/analysis/lib/restores.d.ts +42 -0
- package/dist/packages/analysis/lib/restores.js +482 -0
- package/dist/packages/analysis/lib/rewritten-deletes.d.ts +6 -0
- package/dist/packages/analysis/lib/rewritten-deletes.js +142 -0
- package/dist/packages/analysis/lib/scope.d.ts +110 -0
- package/dist/packages/analysis/lib/scope.js +443 -0
- package/dist/packages/analysis/lib/script-loads.d.ts +56 -0
- package/dist/packages/analysis/lib/script-loads.js +359 -0
- package/dist/packages/analysis/lib/summaries.d.ts +177 -0
- package/dist/packages/analysis/lib/summaries.js +498 -0
- package/dist/packages/analysis/lib/types.d.ts +632 -0
- package/dist/packages/analysis/lib/types.js +128 -0
- package/dist/packages/analysis/lib/wrap.d.ts +34 -0
- package/dist/packages/analysis/lib/wrap.js +407 -0
- package/dist/packages/analysis/lib/writes.d.ts +358 -0
- package/dist/packages/analysis/lib/writes.js +1612 -0
- package/dist/packages/analysis/visit-order.d.ts +3 -0
- package/dist/packages/analysis/visit-order.js +23 -0
- package/dist/packages/attribution/index.d.ts +233 -0
- package/dist/packages/attribution/index.js +444 -0
- package/dist/packages/attribution/lib/containing-package.d.ts +76 -0
- package/dist/packages/attribution/lib/containing-package.js +304 -0
- package/dist/packages/attribution/lib/first-party.d.ts +37 -0
- package/dist/packages/attribution/lib/first-party.js +153 -0
- package/dist/packages/attribution/lib/lockfile-graph.d.ts +99 -0
- package/dist/packages/attribution/lib/lockfile-graph.js +158 -0
- package/dist/packages/attribution/lib/lockfile.d.ts +33 -0
- package/dist/packages/attribution/lib/lockfile.js +330 -0
- package/dist/packages/attribution/lib/path-rules.d.ts +29 -0
- package/dist/packages/attribution/lib/path-rules.js +84 -0
- package/dist/packages/attribution/lib/pnpm.d.ts +4 -0
- package/dist/packages/attribution/lib/pnpm.js +133 -0
- package/dist/packages/attribution/lib/remote-url.d.ts +7 -0
- package/dist/packages/attribution/lib/remote-url.js +24 -0
- package/dist/packages/attribution/lib/source-map.d.ts +51 -0
- package/dist/packages/attribution/lib/source-map.js +125 -0
- package/dist/packages/attribution/lib/yaml.d.ts +9 -0
- package/dist/packages/attribution/lib/yaml.js +277 -0
- package/dist/packages/attribution/lib/yarn.d.ts +7 -0
- package/dist/packages/attribution/lib/yarn.js +227 -0
- package/dist/packages/baseline/index.d.ts +45 -0
- package/dist/packages/baseline/index.js +41 -0
- package/dist/packages/baseline/lib/error.d.ts +15 -0
- package/dist/packages/baseline/lib/error.js +25 -0
- package/dist/packages/baseline/lib/format.d.ts +49 -0
- package/dist/packages/baseline/lib/format.js +22 -0
- package/dist/packages/baseline/lib/migrations.d.ts +19 -0
- package/dist/packages/baseline/lib/migrations.js +7 -0
- package/dist/packages/baseline/lib/previous.d.ts +23 -0
- package/dist/packages/baseline/lib/previous.js +64 -0
- package/dist/packages/baseline/lib/read.d.ts +39 -0
- package/dist/packages/baseline/lib/read.js +219 -0
- package/dist/packages/baseline/lib/report.d.ts +25 -0
- package/dist/packages/baseline/lib/report.js +104 -0
- package/dist/packages/baseline/lib/skew.d.ts +51 -0
- package/dist/packages/baseline/lib/skew.js +75 -0
- package/dist/packages/compare/index.d.ts +120 -0
- package/dist/packages/compare/index.js +274 -0
- package/dist/packages/compare/lib/catalog-notes.d.ts +73 -0
- package/dist/packages/compare/lib/catalog-notes.js +224 -0
- package/dist/packages/completeness/index.d.ts +246 -0
- package/dist/packages/completeness/index.js +249 -0
- package/dist/packages/confidence/index.d.ts +54 -0
- package/dist/packages/confidence/index.js +71 -0
- package/dist/packages/config/index.d.ts +107 -0
- package/dist/packages/config/index.js +95 -0
- package/dist/packages/config/lib/command-line.d.ts +23 -0
- package/dist/packages/config/lib/command-line.js +239 -0
- package/dist/packages/config/lib/config-file.d.ts +11 -0
- package/dist/packages/config/lib/config-file.js +119 -0
- package/dist/packages/config/lib/scan-config-id.d.ts +28 -0
- package/dist/packages/config/lib/scan-config-id.js +54 -0
- package/dist/packages/config/lib/schema.d.ts +2 -0
- package/dist/packages/config/lib/schema.js +31 -0
- package/dist/packages/config/lib/types.d.ts +64 -0
- package/dist/packages/config/lib/types.js +6 -0
- package/dist/packages/config/lib/urls.d.ts +6 -0
- package/dist/packages/config/lib/urls.js +9 -0
- package/dist/packages/discovery/index.d.ts +277 -0
- package/dist/packages/discovery/index.js +1950 -0
- package/dist/packages/discovery/lib/import-map.d.ts +68 -0
- package/dist/packages/discovery/lib/import-map.js +180 -0
- package/dist/packages/discovery/lib/requests.d.ts +58 -0
- package/dist/packages/discovery/lib/requests.js +591 -0
- package/dist/packages/discovery/lib/scopes.d.ts +6 -0
- package/dist/packages/discovery/lib/scopes.js +286 -0
- package/dist/packages/discovery/lib/source-maps.d.ts +56 -0
- package/dist/packages/discovery/lib/source-maps.js +209 -0
- package/dist/packages/discovery/lib/swept-code.d.ts +27 -0
- package/dist/packages/discovery/lib/swept-code.js +107 -0
- package/dist/packages/discovery/lib/syntax.d.ts +17 -0
- package/dist/packages/discovery/lib/syntax.js +39 -0
- package/dist/packages/findings/index.d.ts +106 -0
- package/dist/packages/findings/index.js +254 -0
- package/dist/packages/findings/lib/scope.d.ts +38 -0
- package/dist/packages/findings/lib/scope.js +110 -0
- package/dist/packages/parallel/index.d.ts +2 -0
- package/dist/packages/parallel/index.js +5 -0
- package/dist/packages/parallel/lib/protocol.d.ts +15 -0
- package/dist/packages/parallel/lib/protocol.js +2 -0
- package/dist/packages/parallel/lib/runner.d.ts +36 -0
- package/dist/packages/parallel/lib/runner.js +96 -0
- package/dist/packages/parallel/lib/schedule.d.ts +16 -0
- package/dist/packages/parallel/lib/schedule.js +52 -0
- package/dist/packages/parallel/lib/worker.d.ts +1 -0
- package/dist/packages/parallel/lib/worker.js +18 -0
- package/dist/packages/policy/index.d.ts +36 -0
- package/dist/packages/policy/index.js +22 -0
- package/dist/packages/report/explain.d.ts +26 -0
- package/dist/packages/report/explain.js +99 -0
- package/dist/packages/report/index.d.ts +210 -0
- package/dist/packages/report/index.js +388 -0
- package/dist/packages/report/terminal.d.ts +11 -0
- package/dist/packages/report/terminal.js +331 -0
- package/dist/packages/source-store/fixture.d.ts +22 -0
- package/dist/packages/source-store/fixture.js +58 -0
- package/dist/packages/source-store/index.d.ts +278 -0
- package/dist/packages/source-store/index.js +322 -0
- package/dist/packages/source-store/lib/addresses.d.ts +6 -0
- package/dist/packages/source-store/lib/addresses.js +91 -0
- package/dist/packages/source-store/lib/connection.d.ts +15 -0
- package/dist/packages/source-store/lib/connection.js +135 -0
- package/dist/packages/source-store/lib/content-types.d.ts +16 -0
- package/dist/packages/source-store/lib/content-types.js +75 -0
- package/dist/packages/source-store/lib/data-urls.d.ts +10 -0
- package/dist/packages/source-store/lib/data-urls.js +85 -0
- package/dist/packages/source-store/lib/deadline.d.ts +18 -0
- package/dist/packages/source-store/lib/deadline.js +44 -0
- package/dist/packages/source-store/lib/exchange.d.ts +29 -0
- package/dist/packages/source-store/lib/exchange.js +112 -0
- package/dist/packages/source-store/lib/integrity.d.ts +19 -0
- package/dist/packages/source-store/lib/integrity.js +86 -0
- package/dist/packages/source-store/lib/outcomes.d.ts +12 -0
- package/dist/packages/source-store/lib/outcomes.js +22 -0
- package/dist/packages/source-store/lib/proxy.d.ts +11 -0
- package/dist/packages/source-store/lib/proxy.js +53 -0
- package/dist/packages/source-store/lib/session.d.ts +12 -0
- package/dist/packages/source-store/lib/session.js +139 -0
- package/dist/packages/source-store/lib/urls.d.ts +6 -0
- package/dist/packages/source-store/lib/urls.js +15 -0
- package/dist/packages/source-store/resolve.d.ts +59 -0
- package/dist/packages/source-store/resolve.js +45 -0
- package/dist/scan.d.ts +65 -0
- package/dist/scan.js +592 -0
- package/package.json +95 -4
- package/schema/config.schema.json +133 -0
- package/schema/report.schema.json +1905 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// A delete that is always rewritten (§3). A delete that the same function follows, on every path, with a define or
|
|
2
|
+
// assign of the same slot gives no finding of its own: the later write's finding stands, and the delete leaves only a
|
|
3
|
+
// trace `note`. So core-js's `defineBuiltIn(Array.prototype, wellKnownSymbol('iterator'), …)`, which runs
|
|
4
|
+
// `try { if (!options.unsafe) delete O[key] } catch {}` and then `O[key] = value` or `definePropertyModule.f(O, key, …)`,
|
|
5
|
+
// gives one `Array.prototype.@@iterator` `replace`. A delete that isn't always rewritten stays a `delete` finding.
|
|
6
|
+
//
|
|
7
|
+
// This module decides "on every path", from the syntax of the function the delete is in: which nodes write the slot
|
|
8
|
+
// (an assignment, or a call whose instantiation writes it) is the caller's to say.
|
|
9
|
+
import { walkTree } from "./ast.js";
|
|
10
|
+
import { isFunction } from "./summaries.js";
|
|
11
|
+
/** Statements that may leave the code after them: control leaves before it runs. */
|
|
12
|
+
const leaving = new Set(['ReturnStatement', 'ThrowStatement', 'BreakStatement', 'ContinueStatement']);
|
|
13
|
+
/**
|
|
14
|
+
* Whether every path from the delete `site` to the end of its function, `fn`, runs one of the nodes `writes` accepts,
|
|
15
|
+
* in `fn`'s own code, before control can leave. `parentOf` gives each node's parent.
|
|
16
|
+
*/
|
|
17
|
+
export function alwaysRewritten(site, fn, writes, parentOf) {
|
|
18
|
+
/** Whether evaluating `expression` always runs a write, before anything that could skip it. */
|
|
19
|
+
const expressionWrites = (expression) => {
|
|
20
|
+
if (writes(expression))
|
|
21
|
+
return true;
|
|
22
|
+
switch (expression.type) {
|
|
23
|
+
case 'SequenceExpression':
|
|
24
|
+
return expression['expressions'].some(expressionWrites);
|
|
25
|
+
case 'ConditionalExpression':
|
|
26
|
+
return (expressionWrites(expression['test']) ||
|
|
27
|
+
(expressionWrites(expression['consequent']) && expressionWrites(expression['alternate'])));
|
|
28
|
+
case 'LogicalExpression':
|
|
29
|
+
return expressionWrites(expression['left']);
|
|
30
|
+
case 'AssignmentExpression':
|
|
31
|
+
return expression['operator'] === '=' && expressionWrites(expression['right']);
|
|
32
|
+
case 'ParenthesizedExpression':
|
|
33
|
+
case 'ChainExpression':
|
|
34
|
+
return expressionWrites(expression['expression']);
|
|
35
|
+
default:
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/** Whether running `statement` always runs a write before control can leave it. */
|
|
40
|
+
const statementWrites = (statement) => {
|
|
41
|
+
switch (statement.type) {
|
|
42
|
+
case 'ExpressionStatement':
|
|
43
|
+
return expressionWrites(statement['expression']);
|
|
44
|
+
case 'ReturnStatement':
|
|
45
|
+
case 'ThrowStatement': {
|
|
46
|
+
const argument = statement['argument'];
|
|
47
|
+
return argument !== null && expressionWrites(argument);
|
|
48
|
+
}
|
|
49
|
+
case 'VariableDeclaration':
|
|
50
|
+
return statement['declarations'].some((declarator) => {
|
|
51
|
+
const init = declarator['init'];
|
|
52
|
+
return init !== null && expressionWrites(init);
|
|
53
|
+
});
|
|
54
|
+
case 'BlockStatement':
|
|
55
|
+
return listWrites(statement['body'], 0);
|
|
56
|
+
case 'IfStatement': {
|
|
57
|
+
const alternate = statement['alternate'];
|
|
58
|
+
return (expressionWrites(statement['test']) ||
|
|
59
|
+
(alternate !== null && statementWrites(statement['consequent']) && statementWrites(alternate)));
|
|
60
|
+
}
|
|
61
|
+
case 'TryStatement': {
|
|
62
|
+
// A write that throws writes nothing, so the handler must write too; a finalizer that writes always does.
|
|
63
|
+
const handler = statement['handler'];
|
|
64
|
+
const finalizer = statement['finalizer'];
|
|
65
|
+
if (finalizer !== null && statementWrites(finalizer))
|
|
66
|
+
return true;
|
|
67
|
+
const block = statementWrites(statement['block']);
|
|
68
|
+
return block && (handler === null || statementWrites(handler['body']));
|
|
69
|
+
}
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
/** Whether running `list` from `from` always runs a write before control can leave it. */
|
|
75
|
+
const listWrites = (list, from) => {
|
|
76
|
+
for (let index = from; index < list.length; index++) {
|
|
77
|
+
const statement = list[index];
|
|
78
|
+
if (statementWrites(statement))
|
|
79
|
+
return true;
|
|
80
|
+
if (mayLeave(statement))
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
};
|
|
85
|
+
// Out from the delete: what runs after each node around it, until the function's end.
|
|
86
|
+
for (let child = site, parent = parentOf(site); parent !== undefined; child = parent, parent = parentOf(parent)) {
|
|
87
|
+
if (child === fn || isFunction(child))
|
|
88
|
+
return false;
|
|
89
|
+
switch (parent.type) {
|
|
90
|
+
case 'SequenceExpression': {
|
|
91
|
+
const expressions = parent['expressions'];
|
|
92
|
+
if (expressions.slice(expressions.indexOf(child) + 1).some(expressionWrites))
|
|
93
|
+
return true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'BlockStatement':
|
|
97
|
+
case 'StaticBlock':
|
|
98
|
+
case 'Program': {
|
|
99
|
+
const list = parent['body'];
|
|
100
|
+
if (listWrites(list, list.indexOf(child) + 1))
|
|
101
|
+
return true;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case 'SwitchCase':
|
|
105
|
+
case 'SwitchStatement':
|
|
106
|
+
case 'LabeledStatement':
|
|
107
|
+
case 'ForStatement':
|
|
108
|
+
case 'ForInStatement':
|
|
109
|
+
case 'ForOfStatement':
|
|
110
|
+
case 'WhileStatement':
|
|
111
|
+
case 'DoWhileStatement':
|
|
112
|
+
// What runs after these the walk doesn't follow.
|
|
113
|
+
return false;
|
|
114
|
+
case 'TryStatement':
|
|
115
|
+
// A delete in the `try` block that throws goes to the handler, which must not leave; one in the finalizer or
|
|
116
|
+
// handler goes on after the statement.
|
|
117
|
+
if (child === parent['block']) {
|
|
118
|
+
const handler = parent['handler'];
|
|
119
|
+
if (handler !== null && mayLeave(handler['body']))
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
if (isFunction(parent))
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
/** Whether control may leave a statement other than by reaching its end: a `return`, `throw`, `break` or `continue`. */
|
|
131
|
+
function mayLeave(statement) {
|
|
132
|
+
let found = false;
|
|
133
|
+
walkTree(statement, {
|
|
134
|
+
enter(node) {
|
|
135
|
+
if (found || (node !== statement && isFunction(node)))
|
|
136
|
+
return false;
|
|
137
|
+
if (leaving.has(node.type))
|
|
138
|
+
found = true;
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
return found;
|
|
142
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type AstNode } from './ast.ts';
|
|
2
|
+
import type { BindingResolver } from './binding.ts';
|
|
3
|
+
import type { GlobalDeclarationKind } from './types.ts';
|
|
4
|
+
/** A declaration that binds a property of the global object (§5). */
|
|
5
|
+
export interface GlobalDeclaration {
|
|
6
|
+
kind: GlobalDeclarationKind;
|
|
7
|
+
node: AstNode;
|
|
8
|
+
}
|
|
9
|
+
/** What lies on a name's resolution path that could make it resolve elsewhere (§5 post-pass 3). */
|
|
10
|
+
export interface Taint {
|
|
11
|
+
/** The `with` statements on the resolution path, in document order. */
|
|
12
|
+
withs: AstNode[];
|
|
13
|
+
/** The direct `eval` calls in sloppy functions on the resolution path, in document order. */
|
|
14
|
+
evals: AstNode[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A name that resolves to a property of the global object (§5 Global resolution): either to no declaration at all, or
|
|
18
|
+
* to a declaration that binds the global object's property.
|
|
19
|
+
*/
|
|
20
|
+
export interface GlobalBinding extends Taint {
|
|
21
|
+
declaration?: GlobalDeclaration;
|
|
22
|
+
}
|
|
23
|
+
/** A name that resolves to a `const` declaration (§5 Resolver capabilities 1), with the taint between the two. */
|
|
24
|
+
export interface ConstantBinding extends Taint {
|
|
25
|
+
/** The `const` declaration: a `VariableDeclaration` whose `kind` is `const`. */
|
|
26
|
+
declaration: AstNode;
|
|
27
|
+
}
|
|
28
|
+
/** How the program relates to the code around it, when it is nested code (§2) or holds some. */
|
|
29
|
+
export interface ScopeOptions {
|
|
30
|
+
/** The arrow functions grafted in place of literal direct-eval code, whose code runs in its caller's scope. */
|
|
31
|
+
directEvals?: ReadonlySet<AstNode>;
|
|
32
|
+
/** For global code: the names the host classic script declares with `let`, `const` or `class` at its top level. */
|
|
33
|
+
lexicalGlobals?: ReadonlySet<string>;
|
|
34
|
+
/** Whether the program is eval code, whose top-level `var`s and functions stay its own when it is strict. */
|
|
35
|
+
evalCode?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* For a link group's program (§6 Link groups): the variable an import binding is, by the declaration the seam gives
|
|
38
|
+
* the binding and its name. A reference to a linked import resolves to that variable.
|
|
39
|
+
*/
|
|
40
|
+
imports?: (declaration: AstNode, name: string) => {
|
|
41
|
+
declaration: AstNode;
|
|
42
|
+
name: string;
|
|
43
|
+
} | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface ScopeRules {
|
|
46
|
+
/** What a reference resolves to after the post-passes: a property of the global object, or else a local binding. */
|
|
47
|
+
resolve(id: AstNode): GlobalBinding | 'local';
|
|
48
|
+
/**
|
|
49
|
+
* The `const` declaration a reference resolves to after the post-passes, if it resolves to one, with the `with`
|
|
50
|
+
* statements and the direct evals in sloppy functions between the reference and the declaration (post-pass 3).
|
|
51
|
+
*/
|
|
52
|
+
constant(id: AstNode): ConstantBinding | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* The declaration a reference resolves to after the post-passes, as the seam gives it (§19), or none: a free name, a
|
|
55
|
+
* name global code sees among the host's top-level lexical declarations, or a name an Annex B var binding hides.
|
|
56
|
+
*/
|
|
57
|
+
declaration(id: AstNode): AstNode | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* The name of the variable a reference resolves to: its own, or for an import binding of a link group, the name the
|
|
60
|
+
* variable it is has where it is declared (§6 Link groups).
|
|
61
|
+
*/
|
|
62
|
+
nameOf(id: AstNode): string;
|
|
63
|
+
/** Whether the code at a UTF-16 offset is strict mode code. */
|
|
64
|
+
isStrict(offset: number): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* For a `VariableDeclaration`, `FunctionDeclaration` or `ClassDeclaration`, how it declares the global object's
|
|
67
|
+
* members (§3 Declarations in classic scripts), if it does: see `Declared`.
|
|
68
|
+
*/
|
|
69
|
+
declared(node: AstNode): Declared | undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* How a declaration binds a name of the global object's (§3 Declarations in classic scripts), as ECMA-262's global and
|
|
73
|
+
* eval declaration instantiation give it:
|
|
74
|
+
* - `var`: a `var` whose binding is the global object's property, in a classic script or in eval code (direct or
|
|
75
|
+
* indirect) that declares its vars there
|
|
76
|
+
* - `function`: a function declared at the top level of such code
|
|
77
|
+
* - `block-function`: a block-level function that Annex B gives such a var binding (B.3.2.2, B.3.2.3)
|
|
78
|
+
* - `let`, `const` and `class`: a lexical declaration at the top level of a classic script, which hides the global
|
|
79
|
+
* object's property from bare-name callers. Eval code's are its own.
|
|
80
|
+
*
|
|
81
|
+
* `configurable` is the `D` those steps pass: true for eval code, whose bindings can be deleted, and false for a
|
|
82
|
+
* script. `loop` says a `var` is the head of a `for`-`in` or `for`-`of` loop, which assigns it each iteration.
|
|
83
|
+
*/
|
|
84
|
+
export interface Declared {
|
|
85
|
+
kind: GlobalDeclarationKind;
|
|
86
|
+
configurable: boolean;
|
|
87
|
+
loop?: boolean;
|
|
88
|
+
}
|
|
89
|
+
export declare function scopeRules(program: AstNode, sourceType: 'script' | 'module', bindings: BindingResolver, options?: ScopeOptions): ScopeRules;
|
|
90
|
+
/**
|
|
91
|
+
* The names a classic script declares lexically at its top level (`let`, `const`, `using`, `class`). They are global
|
|
92
|
+
* bindings that are not properties of the global object, and global code sees them. A module's are its own.
|
|
93
|
+
*/
|
|
94
|
+
export declare function globalLexicalNames(program: AstNode, sourceType: 'script' | 'module'): ReadonlySet<string>;
|
|
95
|
+
interface LexicalGlobal {
|
|
96
|
+
name: string;
|
|
97
|
+
kind: 'let' | 'const' | 'class';
|
|
98
|
+
id: AstNode;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A classic script's top-level `let`, `const` and `class` declarations, in document order, each with the identifier it
|
|
102
|
+
* binds: the names the scan-wide lexical-name check collects (§3 Declarations in classic scripts). A module's are its
|
|
103
|
+
* own, so it has none.
|
|
104
|
+
*/
|
|
105
|
+
export declare function globalLexicalDeclarations(program: AstNode, sourceType: 'script' | 'module'): LexicalGlobal[];
|
|
106
|
+
/** The names a binding pattern binds. */
|
|
107
|
+
export declare function boundNames(pattern: AstNode): string[];
|
|
108
|
+
/** The identifiers a binding pattern binds, in document order. */
|
|
109
|
+
export declare function boundIdentifiers(pattern: AstNode): AstNode[];
|
|
110
|
+
export {};
|