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,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A property key the analyzer knows: a string, or one of the well-known symbols, which are real symbols here so that
|
|
3
|
+
* they compare, convert and test as JavaScript's own do (`typeof`, `===`, truthiness).
|
|
4
|
+
*/
|
|
5
|
+
export type Key = string | symbol;
|
|
6
|
+
/** The well-known symbol ECMA-262 names `Symbol.<name>` (`%Symbol.iterator%`), e.g. `iterator`. */
|
|
7
|
+
export declare function wellKnownSymbol(name: string): symbol;
|
|
8
|
+
/** How the catalog spells a well-known symbol as a member: `@@iterator`. */
|
|
9
|
+
export declare function symbolMember(symbol: symbol): string;
|
|
10
|
+
/** ECMA-262 ToPropertyKey of a primitive constant: a well-known symbol is itself, and anything else its string. */
|
|
11
|
+
export declare function toPropertyKey(value: string | number | bigint | boolean | null | undefined | symbol): Key;
|
|
12
|
+
/**
|
|
13
|
+
* The key a literal property name gives in an object literal or pattern (`{ "a": x }`, `{ 1e21: x }`, `{ 1n: x }`), as
|
|
14
|
+
* ECMA-262 PropertyDefinitionEvaluation converts it: a string, or a number's or BigInt's string. Undefined for any
|
|
15
|
+
* other node.
|
|
16
|
+
*/
|
|
17
|
+
export declare function literalKey(node: {
|
|
18
|
+
type: string;
|
|
19
|
+
[field: string]: unknown;
|
|
20
|
+
}): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the member `key` of `holder`: `Array.prototype.map`, `Array.prototype.0`, `Array.prototype.@@iterator`,
|
|
23
|
+
* `Array["prototype.map"]`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function memberName(holder: string, key: Key): string;
|
|
26
|
+
/**
|
|
27
|
+
* The name of a pattern wildcard (§5 Pattern wildcards): the members of `holder` whose key starts with `prefix`,
|
|
28
|
+
* `EventTarget.prototype.__zone_symbol__*`. A prefix holding a character §4 writes in brackets (`.`, `[`, `]`, `"`,
|
|
29
|
+
* `\`, a control character, a leading `@@`, or a `*` anywhere) is JSON-quoted in brackets with the star outside,
|
|
30
|
+
* `Object.prototype["__core.hidden."]*`, so it never spells a named member (`Object.prototype["__core.hidden.*"]`) or a
|
|
31
|
+
* nested name.
|
|
32
|
+
*/
|
|
33
|
+
export declare function patternName(holder: string, prefix: string): string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Property keys (§4 Property keys): what a constant key names, as ECMA-262 ToPropertyKey converts it, and how a target
|
|
2
|
+
// name spells a member.
|
|
3
|
+
//
|
|
4
|
+
// - A number, boolean, null or undefined key names its string, so `0` and `"0"` both name `Array.prototype.0`, and a
|
|
5
|
+
// numeric member uses its canonical string (`1e21` names `1e+21`).
|
|
6
|
+
// - A well-known symbol (`Symbol.iterator`) is a constant of its own, and names the catalog's `@@` member
|
|
7
|
+
// (`Array.prototype.@@iterator`). The analyzer knows no other symbol.
|
|
8
|
+
// - A string key never spells another target's name: one that could is written in JSON-quoted brackets
|
|
9
|
+
// (`X.prototype["@@toStringTag"]`, `Array["prototype.map"]`, `console["*"]`).
|
|
10
|
+
/** The well-known symbols, one per name, so that the same symbol is the same value wherever it is read. */
|
|
11
|
+
const symbols = new Map();
|
|
12
|
+
/** Each well-known symbol's member spelling in the catalog: `@@iterator`. */
|
|
13
|
+
const spellings = new Map();
|
|
14
|
+
/** The well-known symbol ECMA-262 names `Symbol.<name>` (`%Symbol.iterator%`), e.g. `iterator`. */
|
|
15
|
+
export function wellKnownSymbol(name) {
|
|
16
|
+
let symbol = symbols.get(name);
|
|
17
|
+
if (symbol === undefined) {
|
|
18
|
+
symbol = Symbol(`Symbol.${name}`);
|
|
19
|
+
symbols.set(name, symbol);
|
|
20
|
+
spellings.set(symbol, `@@${name}`);
|
|
21
|
+
}
|
|
22
|
+
return symbol;
|
|
23
|
+
}
|
|
24
|
+
/** How the catalog spells a well-known symbol as a member: `@@iterator`. */
|
|
25
|
+
export function symbolMember(symbol) {
|
|
26
|
+
const spelling = spellings.get(symbol);
|
|
27
|
+
if (spelling === undefined)
|
|
28
|
+
throw new Error(`${String(symbol)} is no well-known symbol`);
|
|
29
|
+
return spelling;
|
|
30
|
+
}
|
|
31
|
+
/** ECMA-262 ToPropertyKey of a primitive constant: a well-known symbol is itself, and anything else its string. */
|
|
32
|
+
export function toPropertyKey(value) {
|
|
33
|
+
return typeof value === 'symbol' ? value : String(value);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The key a literal property name gives in an object literal or pattern (`{ "a": x }`, `{ 1e21: x }`, `{ 1n: x }`), as
|
|
37
|
+
* ECMA-262 PropertyDefinitionEvaluation converts it: a string, or a number's or BigInt's string. Undefined for any
|
|
38
|
+
* other node.
|
|
39
|
+
*/
|
|
40
|
+
export function literalKey(node) {
|
|
41
|
+
if (node.type !== 'Literal')
|
|
42
|
+
return undefined;
|
|
43
|
+
if (typeof node['bigint'] === 'string')
|
|
44
|
+
return String(BigInt(node['bigint']));
|
|
45
|
+
const value = node['value'];
|
|
46
|
+
return typeof value === 'string' || typeof value === 'number' ? String(value) : undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The name of the member `key` of `holder`: `Array.prototype.map`, `Array.prototype.0`, `Array.prototype.@@iterator`,
|
|
50
|
+
* `Array["prototype.map"]`.
|
|
51
|
+
*/
|
|
52
|
+
export function memberName(holder, key) {
|
|
53
|
+
if (typeof key === 'symbol')
|
|
54
|
+
return `${holder}.${symbolMember(key)}`;
|
|
55
|
+
return escaped(key) ? `${holder}[${JSON.stringify(key)}]` : `${holder}.${key}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether a string key is written in brackets (§4): one that starts with `@@` (a symbol member's spelling), contains
|
|
59
|
+
* `.`, `[`, `]`, `"`, `\` or a control character (Unicode's `Cc`), or ends with `*` (a wildcard's spelling). A
|
|
60
|
+
* canonical numeric key keeps the dot form (`Array.prototype.1.5`), and so do the catalog's names, none of which is one
|
|
61
|
+
* of these.
|
|
62
|
+
*/
|
|
63
|
+
function escaped(key) {
|
|
64
|
+
if (isCanonicalNumeric(key))
|
|
65
|
+
return false;
|
|
66
|
+
return key.startsWith('@@') || key.endsWith('*') || /[.[\]"\\\p{Cc}]/u.test(key);
|
|
67
|
+
}
|
|
68
|
+
/** ECMA-262 CanonicalNumericIndexString: a key that is the string of a number, as `"1.5"` is and `"1.50"` is not. */
|
|
69
|
+
function isCanonicalNumeric(key) {
|
|
70
|
+
return key === '-0' || String(Number(key)) === key;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The name of a pattern wildcard (§5 Pattern wildcards): the members of `holder` whose key starts with `prefix`,
|
|
74
|
+
* `EventTarget.prototype.__zone_symbol__*`. A prefix holding a character §4 writes in brackets (`.`, `[`, `]`, `"`,
|
|
75
|
+
* `\`, a control character, a leading `@@`, or a `*` anywhere) is JSON-quoted in brackets with the star outside,
|
|
76
|
+
* `Object.prototype["__core.hidden."]*`, so it never spells a named member (`Object.prototype["__core.hidden.*"]`) or a
|
|
77
|
+
* nested name.
|
|
78
|
+
*/
|
|
79
|
+
export function patternName(holder, prefix) {
|
|
80
|
+
const bracketed = prefix.startsWith('@@') || prefix.includes('*') || /[.[\]"\\\p{Cc}]/u.test(prefix);
|
|
81
|
+
return bracketed ? `${holder}[${JSON.stringify(prefix)}]*` : `${holder}.${prefix}*`;
|
|
82
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ArtifactSource, GeneratedLocation } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* An artifact's line-start table (§5): the UTF-16 offset where each line starts. Lines end at an ECMAScript
|
|
4
|
+
* LineTerminatorSequence: LF, CR, CRLF, U+2028 or U+2029.
|
|
5
|
+
*/
|
|
6
|
+
export declare function lineStarts(text: string): number[];
|
|
7
|
+
/**
|
|
8
|
+
* A member of a link group's text (§6 Link groups): the artifact whose code sits at `base` in the group's text, and its
|
|
9
|
+
* own line-start table.
|
|
10
|
+
*/
|
|
11
|
+
export interface LinesMember {
|
|
12
|
+
url: string;
|
|
13
|
+
hash: string;
|
|
14
|
+
origin?: ArtifactSource['origin'];
|
|
15
|
+
base: number;
|
|
16
|
+
length: number;
|
|
17
|
+
starts: readonly number[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The line-start tables of a link group's members, whose texts the group's text holds one after another. A location is
|
|
21
|
+
* given in the coordinates of the artifact it is in, and the artifact each location was made for is remembered, so a
|
|
22
|
+
* trace step can name the artifact its location is in.
|
|
23
|
+
*/
|
|
24
|
+
export declare class GroupLines {
|
|
25
|
+
#private;
|
|
26
|
+
readonly members: readonly LinesMember[];
|
|
27
|
+
constructor(members: readonly LinesMember[]);
|
|
28
|
+
/** The member whose text holds the group offset `offset`. */
|
|
29
|
+
memberAt(offset: number): LinesMember;
|
|
30
|
+
/**
|
|
31
|
+
* The location of the group range `[start, end)`. One range is located once: the analysis locates the same nodes
|
|
32
|
+
* again and again, and each location it gives is one the table remembers the member of.
|
|
33
|
+
*/
|
|
34
|
+
locate(start: number, end: number): GeneratedLocation;
|
|
35
|
+
/** The member a location this table made is in. */
|
|
36
|
+
artifactOf(location: GeneratedLocation): LinesMember | undefined;
|
|
37
|
+
}
|
|
38
|
+
/** A line-start table: an artifact's own, or a link group's (`GroupLines`). */
|
|
39
|
+
export type Starts = readonly number[] | GroupLines;
|
|
40
|
+
/** The generated location of the UTF-16 range `[start, end)`: its start as a 1-based line and a 0-based column. */
|
|
41
|
+
export declare function locate(starts: Starts, start: number, end: number): GeneratedLocation;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An artifact's line-start table (§5): the UTF-16 offset where each line starts. Lines end at an ECMAScript
|
|
3
|
+
* LineTerminatorSequence: LF, CR, CRLF, U+2028 or U+2029.
|
|
4
|
+
*/
|
|
5
|
+
export function lineStarts(text) {
|
|
6
|
+
const starts = [0];
|
|
7
|
+
for (let i = 0; i < text.length; i++) {
|
|
8
|
+
const code = text.charCodeAt(i);
|
|
9
|
+
if (code === 0x0d && text.charCodeAt(i + 1) === 0x0a)
|
|
10
|
+
i++;
|
|
11
|
+
if (code === 0x0a || code === 0x0d || code === 0x2028 || code === 0x2029)
|
|
12
|
+
starts.push(i + 1);
|
|
13
|
+
}
|
|
14
|
+
return starts;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The line-start tables of a link group's members, whose texts the group's text holds one after another. A location is
|
|
18
|
+
* given in the coordinates of the artifact it is in, and the artifact each location was made for is remembered, so a
|
|
19
|
+
* trace step can name the artifact its location is in.
|
|
20
|
+
*/
|
|
21
|
+
export class GroupLines {
|
|
22
|
+
members;
|
|
23
|
+
#artifacts = new WeakMap();
|
|
24
|
+
#located = new Map();
|
|
25
|
+
constructor(members) {
|
|
26
|
+
this.members = members;
|
|
27
|
+
}
|
|
28
|
+
/** The member whose text holds the group offset `offset`. */
|
|
29
|
+
memberAt(offset) {
|
|
30
|
+
const { members } = this;
|
|
31
|
+
let low = 0;
|
|
32
|
+
let high = members.length - 1;
|
|
33
|
+
while (low < high) {
|
|
34
|
+
const middle = (low + high + 1) >> 1;
|
|
35
|
+
if (members[middle].base <= offset)
|
|
36
|
+
low = middle;
|
|
37
|
+
else
|
|
38
|
+
high = middle - 1;
|
|
39
|
+
}
|
|
40
|
+
return members[low];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The location of the group range `[start, end)`. One range is located once: the analysis locates the same nodes
|
|
44
|
+
* again and again, and each location it gives is one the table remembers the member of.
|
|
45
|
+
*/
|
|
46
|
+
locate(start, end) {
|
|
47
|
+
let byEnd = this.#located.get(start);
|
|
48
|
+
if (byEnd === undefined)
|
|
49
|
+
this.#located.set(start, (byEnd = new Map()));
|
|
50
|
+
const known = byEnd.get(end);
|
|
51
|
+
if (known !== undefined)
|
|
52
|
+
return known;
|
|
53
|
+
const member = this.memberAt(start);
|
|
54
|
+
const location = locateIn(member.starts, start - member.base, end - member.base);
|
|
55
|
+
this.#artifacts.set(location, member);
|
|
56
|
+
byEnd.set(end, location);
|
|
57
|
+
return location;
|
|
58
|
+
}
|
|
59
|
+
/** The member a location this table made is in. */
|
|
60
|
+
artifactOf(location) {
|
|
61
|
+
return this.#artifacts.get(location);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The generated location of the UTF-16 range `[start, end)`: its start as a 1-based line and a 0-based column. */
|
|
65
|
+
export function locate(starts, start, end) {
|
|
66
|
+
return starts instanceof GroupLines ? starts.locate(start, end) : locateIn(starts, start, end);
|
|
67
|
+
}
|
|
68
|
+
function locateIn(starts, start, end) {
|
|
69
|
+
let low = 0;
|
|
70
|
+
let high = starts.length - 1;
|
|
71
|
+
while (low < high) {
|
|
72
|
+
const middle = (low + high + 1) >> 1;
|
|
73
|
+
if (starts[middle] <= start)
|
|
74
|
+
low = middle;
|
|
75
|
+
else
|
|
76
|
+
high = middle - 1;
|
|
77
|
+
}
|
|
78
|
+
return { start, end, line: low + 1, column: start - starts[low] };
|
|
79
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type AstNode } from './ast.ts';
|
|
2
|
+
import { GroupLines } from './line-starts.ts';
|
|
3
|
+
import type { AnalyzeGroupInput, ArtifactSource } from './types.ts';
|
|
4
|
+
/** The variable an import binding is (`LinkGroup.bound`): its declaration, and the name it declares. */
|
|
5
|
+
export interface Bound {
|
|
6
|
+
declaration: AstNode;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LinkGroup {
|
|
10
|
+
/** The group's text: its members' texts, one after another. */
|
|
11
|
+
text: string;
|
|
12
|
+
/** The group's program. */
|
|
13
|
+
program: AstNode;
|
|
14
|
+
sourceType: 'script' | 'module';
|
|
15
|
+
lines: GroupLines;
|
|
16
|
+
/** The group's members, entry first, then in the order their code sits in the group's text. */
|
|
17
|
+
members: ArtifactSource[];
|
|
18
|
+
/** The members that don't parse, with the parser's error. */
|
|
19
|
+
failures: {
|
|
20
|
+
source: ArtifactSource;
|
|
21
|
+
error: string;
|
|
22
|
+
}[];
|
|
23
|
+
/** The variable the import binding `name` of a declaration is, when the declaration is an import. */
|
|
24
|
+
bound(declaration: AstNode, name: string): Bound | undefined;
|
|
25
|
+
/** The function each member other than the entry runs in, and the member. */
|
|
26
|
+
wrappers: ReadonlyMap<AstNode, ArtifactSource>;
|
|
27
|
+
/** The `import(…)` calls that run each member only dynamic imports reach, by its function (§6). */
|
|
28
|
+
loadedBy: ReadonlyMap<AstNode, readonly AstNode[]>;
|
|
29
|
+
/** The members a chunk registry links (§6 idiom 6), by URL: lazy chunks, whose code is always `deferred`. */
|
|
30
|
+
chunks: ReadonlySet<string>;
|
|
31
|
+
/** How many module requests of each member's code name no member of the group (§6 Degradation), by URL. */
|
|
32
|
+
unlinked: ReadonlyMap<string, number>;
|
|
33
|
+
/**
|
|
34
|
+
* The import bindings whose module isn't in the group, by their import declaration, which a reference to one resolves
|
|
35
|
+
* to, and name, each with the import declaration.
|
|
36
|
+
*/
|
|
37
|
+
unlinkedBindings: ReadonlyMap<AstNode, ReadonlyMap<string, AstNode>>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The link group of `entry`: its members, pulled in through the module requests `resolveImport` resolves, and joined
|
|
41
|
+
* into one program. A group of one artifact is that artifact's program, unchanged. Undefined when the entry's own
|
|
42
|
+
* module graph fails; `failures` then says why.
|
|
43
|
+
*/
|
|
44
|
+
export declare function linkGroup(entry: ArtifactSource, { artifact, resolveImport, chunks, initialChunks }: Pick<AnalyzeGroupInput, 'artifact' | 'resolveImport' | 'chunks' | 'initialChunks'>): {
|
|
45
|
+
group?: LinkGroup;
|
|
46
|
+
failures: {
|
|
47
|
+
source: ArtifactSource;
|
|
48
|
+
error: string;
|
|
49
|
+
}[];
|
|
50
|
+
pulled: ArtifactSource[];
|
|
51
|
+
};
|