@cplieger/deadset-ts 8.0.0-dev.16 → 8.0.0-dev.18
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/dist/src/alias-chain.js +0 -5
- package/dist/src/amd.js +81 -0
- package/dist/src/analysis.js +82 -91
- package/dist/src/augmentations.js +24 -25
- package/dist/src/bindings.js +382 -0
- package/dist/src/calls.js +279 -43
- package/dist/src/commands/tools.js +5 -9
- package/dist/src/component-files.js +3 -2
- package/dist/src/conformance-record.js +1 -1
- package/dist/src/consumers.js +6 -9
- package/dist/src/contextual-uses.js +1 -17
- package/dist/src/contract/config.generated.js +4 -1
- package/dist/src/contract/contract.generated.js +2 -2
- package/dist/src/contract/report.generated.js +6 -2
- package/dist/src/dependencies.js +25 -29
- package/dist/src/destructuring.js +1 -19
- package/dist/src/element-access.js +179 -164
- package/dist/src/entries/build-scripts.js +2 -2
- package/dist/src/entries/configuration-files.js +3 -7
- package/dist/src/entries/conventions.js +2 -2
- package/dist/src/entries/html-entries.js +7 -10
- package/dist/src/entries/mdx-entries.js +2 -2
- package/dist/src/entries/static-module.js +2 -1
- package/dist/src/exempt.js +0 -26
- package/dist/src/exposure.js +400 -0
- package/dist/src/facts.js +4 -4
- package/dist/src/findings/completion.js +44 -21
- package/dist/src/findings/emitters.js +22 -33
- package/dist/src/{implementations.js → findings/implementations.js} +3 -3
- package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
- package/dist/src/findings/intra-function.js +3 -3
- package/dist/src/findings/reads-and-writes.js +71 -15
- package/dist/src/findings/unused-declarations.js +2 -22
- package/dist/src/findings/visibility-narrowing.js +14 -20
- package/dist/src/framework-lifecycle.js +41 -14
- package/dist/src/import-bindings.js +73 -28
- package/dist/src/index/sites.js +557 -0
- package/dist/src/indexed-access.js +523 -478
- package/dist/src/interface-satisfaction.js +1 -1
- package/dist/src/inventory.js +18 -0
- package/dist/src/keyof-comparisons.js +124 -103
- package/dist/src/{components.js → liveness/components.js} +1 -1
- package/dist/src/{graph.js → liveness/graph.js} +45 -20
- package/dist/src/liveness/matrix.js +99 -0
- package/dist/src/liveness/sweep.js +558 -0
- package/dist/src/load/expected-module.js +2 -2
- package/dist/src/load/specifiers.js +2 -4
- package/dist/src/load/synthesize.js +5 -0
- package/dist/src/load/workspace-resolution.js +2 -2
- package/dist/src/module-declarations.js +70 -85
- package/dist/src/overrides.js +134 -112
- package/dist/src/paths.js +46 -7
- package/dist/src/platform-calls.js +2 -2
- package/dist/src/platform-symbols.js +13 -19
- package/dist/src/query.js +46 -0
- package/dist/src/references/read-rule.js +1 -0
- package/dist/src/references/read-rules.js +48 -0
- package/dist/src/references/sink.js +237 -0
- package/dist/src/references/sources.js +450 -0
- package/dist/src/references.js +110 -1285
- package/dist/src/roots/configured-declarations.js +3 -0
- package/dist/src/roots/published-reach.js +4 -4
- package/dist/src/roots/root-set.js +1 -1
- package/dist/src/roots/unseen-loads.js +38 -10
- package/dist/src/serialization-contract.js +8 -3
- package/dist/src/stores.js +4 -2
- package/dist/src/symbol-keys.js +89 -83
- package/dist/src/tests/file-class.js +76 -0
- package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
- package/dist/src/{test-support.js → tests/support.js} +2 -11
- package/dist/src/type-parameter-reads.js +178 -139
- package/dist/src/unimplemented-callees.js +262 -242
- package/dist/src/verbs/analyze.js +3 -3
- package/dist/src/verbs/explain.js +75 -132
- package/dist/src/verbs/print-retained.js +3 -3
- package/jsr.json +1 -1
- package/package.json +2 -2
- package/src/alias-chain.ts +0 -7
- package/src/amd.ts +130 -0
- package/src/analysis.ts +125 -128
- package/src/augmentations.ts +42 -28
- package/src/bindings.ts +460 -0
- package/src/calls.ts +338 -46
- package/src/commands/tools.ts +5 -11
- package/src/component-files.ts +4 -2
- package/src/conformance-record.ts +1 -1
- package/src/consumers.ts +8 -11
- package/src/contextual-uses.ts +2 -22
- package/src/contract/config.generated.ts +4 -1
- package/src/contract/contract.generated.ts +2 -2
- package/src/contract/report.generated.ts +6 -2
- package/src/dependencies.ts +27 -28
- package/src/destructuring.ts +1 -31
- package/src/element-access.ts +188 -182
- package/src/entries/build-scripts.ts +2 -2
- package/src/entries/configuration-files.ts +11 -8
- package/src/entries/conventions.ts +2 -1
- package/src/entries/html-entries.ts +15 -14
- package/src/entries/mdx-entries.ts +2 -2
- package/src/entries/static-module.ts +2 -1
- package/src/exempt.ts +31 -46
- package/src/exposure.ts +492 -0
- package/src/facts.ts +5 -3
- package/src/finding.ts +1 -1
- package/src/findings/boundary.ts +9 -0
- package/src/findings/completion.ts +48 -23
- package/src/findings/emitter.ts +1 -1
- package/src/findings/emitters.ts +23 -41
- package/src/{implementations.ts → findings/implementations.ts} +4 -4
- package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
- package/src/findings/interfaces.ts +3 -3
- package/src/findings/intra-function.ts +3 -3
- package/src/findings/reads-and-writes.ts +99 -26
- package/src/findings/unused-declarations.ts +4 -28
- package/src/findings/visibility-narrowing.ts +25 -26
- package/src/framework-lifecycle.ts +42 -14
- package/src/import-bindings.ts +98 -29
- package/src/index/sites.ts +781 -0
- package/src/indexed-access.ts +570 -527
- package/src/interface-satisfaction.ts +2 -2
- package/src/inventory.ts +19 -0
- package/src/keyof-comparisons.ts +131 -116
- package/src/{components.ts → liveness/components.ts} +3 -3
- package/src/{graph.ts → liveness/graph.ts} +93 -27
- package/src/liveness/matrix.ts +162 -0
- package/src/liveness/sweep.ts +855 -0
- package/src/load/expected-module.ts +8 -2
- package/src/load/specifiers.ts +8 -5
- package/src/load/synthesize.ts +6 -0
- package/src/load/workspace-resolution.ts +9 -2
- package/src/module-declarations.ts +74 -98
- package/src/overrides.ts +162 -134
- package/src/paths.ts +54 -8
- package/src/platform-calls.ts +3 -3
- package/src/platform-symbols.ts +11 -27
- package/src/query.ts +81 -0
- package/src/references/read-rule.ts +60 -0
- package/src/references/read-rules.ts +55 -0
- package/src/references/sink.ts +314 -0
- package/src/references/sources.ts +632 -0
- package/src/references.ts +175 -1733
- package/src/report.ts +1 -1
- package/src/roots/configured-declarations.ts +3 -0
- package/src/roots/published-reach.ts +9 -4
- package/src/roots/root-set.ts +1 -1
- package/src/roots/unseen-loads.ts +49 -11
- package/src/serialization-contract.ts +8 -3
- package/src/stores.ts +15 -3
- package/src/symbol-keys.ts +102 -102
- package/src/tests/file-class.ts +135 -0
- package/src/{outside-tests.ts → tests/outside.ts} +16 -10
- package/src/{test-support.ts → tests/support.ts} +9 -20
- package/src/type-parameter-reads.ts +187 -158
- package/src/unimplemented-callees.ts +297 -280
- package/src/verbs/analyze.ts +3 -2
- package/src/verbs/explain.ts +83 -158
- package/src/verbs/print-retained.ts +3 -3
- package/dist/src/matrix.js +0 -273
- package/dist/src/sweep.js +0 -222
- package/src/matrix.ts +0 -463
- package/src/sweep.ts +0 -361
package/dist/src/query.js
CHANGED
|
@@ -88,6 +88,36 @@ export function propertyTables(queries) {
|
|
|
88
88
|
},
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
+
/** How to read the types one type is spelled from, as {@link Queries.partsOf} names them. */
|
|
92
|
+
function partQuestion(type) {
|
|
93
|
+
if (type.isTypeParameter()) {
|
|
94
|
+
return () => [type.getConstraint(), type.getDefault()];
|
|
95
|
+
}
|
|
96
|
+
if (type.isConditionalType()) {
|
|
97
|
+
return () => [
|
|
98
|
+
type.getCheckType(),
|
|
99
|
+
type.getExtendsType(),
|
|
100
|
+
type.getTrueType(),
|
|
101
|
+
type.getFalseType(),
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
if (type.isMappedType()) {
|
|
105
|
+
return () => [type.getConstraintType(), type.getNameType(), type.getTemplateType()];
|
|
106
|
+
}
|
|
107
|
+
if (type.isIndexedAccessType()) {
|
|
108
|
+
return () => [type.getObjectType(), type.getIndexType()];
|
|
109
|
+
}
|
|
110
|
+
if (type.isIndexType() || type.isStringMappingType()) {
|
|
111
|
+
return () => [type.getTarget()];
|
|
112
|
+
}
|
|
113
|
+
if (type.isTemplateLiteralType()) {
|
|
114
|
+
return () => type.getTypes();
|
|
115
|
+
}
|
|
116
|
+
if (type.isSubstitutionType()) {
|
|
117
|
+
return () => [type.getBaseType(), type.getConstraint()];
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
91
121
|
/**
|
|
92
122
|
* The guarded questions over one project's checker. `configFile` names the project
|
|
93
123
|
* in the log, `batch` sends many questions in one round trip, `log` is the run's,
|
|
@@ -217,7 +247,23 @@ export function queriesOf(checker, configFile, batch, log, ask = ASK_DIRECTLY) {
|
|
|
217
247
|
indexedAccessOf: (type) => type.isIndexedAccessType()
|
|
218
248
|
? one("getObjectType", () => typeLocation(type), () => ({ object: type.getObjectType(), index: type.getIndexType() }))
|
|
219
249
|
: undefined,
|
|
250
|
+
partsOf: (type) => {
|
|
251
|
+
const parts = partQuestion(type);
|
|
252
|
+
return parts === undefined
|
|
253
|
+
? []
|
|
254
|
+
: one("getParts", () => typeLocation(type), () => parts().filter((part) => part !== undefined));
|
|
255
|
+
},
|
|
256
|
+
signaturePartsOf: (signature) => one("getSignatureParts", () => `signature ${String(signature.id)}`, () => {
|
|
257
|
+
const self = signature.thisParameter === undefined ? undefined : signature.getThisParameter();
|
|
258
|
+
return [
|
|
259
|
+
...((signature.typeParameters ?? []).length === 0 ? [] : signature.getTypeParameters()),
|
|
260
|
+
self === undefined ? undefined : checker.getTypeOfSymbol(self),
|
|
261
|
+
checker.getTypePredicateOfSignature(signature)?.type,
|
|
262
|
+
].filter((part) => part !== undefined);
|
|
263
|
+
}),
|
|
220
264
|
symbolOfType: (type) => one("getSymbol", () => typeLocation(type), () => type.getSymbol()),
|
|
265
|
+
aliasSymbolOf: (type) => one("getAliasSymbol", () => typeLocation(type), () => type.getAliasSymbol()),
|
|
266
|
+
aliasArgumentsOf: (type) => one("getAliasTypeArguments", () => typeLocation(type), () => type.getAliasTypeArguments()),
|
|
221
267
|
signaturesOf: (type, kind) => one("getSignaturesOfType", () => typeLocation(type), () => checker.getSignaturesOfType(type, kind)),
|
|
222
268
|
resolvedSignature: (node) => one("getResolvedSignature", () => nodeLocation(node), () => checker.getResolvedSignature(node)),
|
|
223
269
|
resolvedSignatures: (nodes, cap = DEFAULT_BATCH_CAP) => each("getResolvedSignature", nodes, cap, nodeLocation, (node) => checker.getResolvedSignature.gen(node), (node) => checker.getResolvedSignature(node)),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { elementAccess } from "../element-access.js";
|
|
2
|
+
import { indexedAccess } from "../indexed-access.js";
|
|
3
|
+
import { keyofComparisons } from "../keyof-comparisons.js";
|
|
4
|
+
import { moduleDeclarations } from "../module-declarations.js";
|
|
5
|
+
import { overrides } from "../overrides.js";
|
|
6
|
+
import { isAnswered } from "../query.js";
|
|
7
|
+
import { iteration } from "../symbol-keys.js";
|
|
8
|
+
import { typeParameterReads } from "../type-parameter-reads.js";
|
|
9
|
+
import { unimplementedCallees } from "../unimplemented-callees.js";
|
|
10
|
+
/** The member kinds a hold of every member names. */
|
|
11
|
+
const MEMBER_KINDS = new Set([
|
|
12
|
+
"method",
|
|
13
|
+
"class-member",
|
|
14
|
+
"interface-method",
|
|
15
|
+
"type-member",
|
|
16
|
+
"enum-member",
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Every read rule, each run over every side's walked files with the reference sources:
|
|
20
|
+
* a consumer's read of a target member is a reference as the target's own is.
|
|
21
|
+
*/
|
|
22
|
+
export const READ_RULES = [
|
|
23
|
+
overrides,
|
|
24
|
+
indexedAccess,
|
|
25
|
+
elementAccess,
|
|
26
|
+
keyofComparisons,
|
|
27
|
+
iteration,
|
|
28
|
+
typeParameterReads,
|
|
29
|
+
unimplementedCallees,
|
|
30
|
+
moduleDeclarations,
|
|
31
|
+
];
|
|
32
|
+
/** The declarations one hold names, with the declaration whose read it is. */
|
|
33
|
+
export function heldBy(read, { project, held, chains }) {
|
|
34
|
+
const ids = [...(read.from === "" ? [] : [read.from]), ...(read.ids ?? [])];
|
|
35
|
+
for (const name of read.names ?? []) {
|
|
36
|
+
ids.push(...(held.byName.get(name) ?? []));
|
|
37
|
+
}
|
|
38
|
+
for (const type of read.types ?? []) {
|
|
39
|
+
const properties = project.queries.propertiesOf(type);
|
|
40
|
+
for (const property of isAnswered(properties) ? properties : []) {
|
|
41
|
+
ids.push(...chains.declarationsOf(property));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (read.members === true) {
|
|
45
|
+
ids.push(...held.symbols.filter((one) => MEMBER_KINDS.has(one.kind)).map((one) => one.id));
|
|
46
|
+
}
|
|
47
|
+
return ids;
|
|
48
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { isBinaryExpression, isParenthesizedExpression, isPropertyAccessExpression, SyntaxKind, } from "@typescript/native/ast";
|
|
2
|
+
import { bindingsOf } from "../import-bindings.js";
|
|
3
|
+
import { byPosition, renderPosition } from "../position.js";
|
|
4
|
+
import { bytewise } from "../text/compare.js";
|
|
5
|
+
/**
|
|
6
|
+
* Where every reference of one pass is made: it renders the position against the side's
|
|
7
|
+
* root, takes the writing file's test class from the file classes, marks a use only a
|
|
8
|
+
* declaration's name answered `guessed` and an alias step's `alias`, tags a consumer's
|
|
9
|
+
* reference with the consumer, and orders the records.
|
|
10
|
+
*/
|
|
11
|
+
export class Sink {
|
|
12
|
+
#root;
|
|
13
|
+
#testFile;
|
|
14
|
+
#consumer;
|
|
15
|
+
#found = [];
|
|
16
|
+
#declaredAt;
|
|
17
|
+
#valued = new Map();
|
|
18
|
+
#named = new Map();
|
|
19
|
+
#held = new Set();
|
|
20
|
+
constructor(root, testFile, consumer, declaredAt) {
|
|
21
|
+
this.#root = root;
|
|
22
|
+
this.#testFile = testFile;
|
|
23
|
+
this.#consumer = consumer;
|
|
24
|
+
this.#declaredAt = declaredAt;
|
|
25
|
+
}
|
|
26
|
+
/** Whether a test file wrote one walked file's uses. */
|
|
27
|
+
isTest(file) {
|
|
28
|
+
return this.#testFile(file);
|
|
29
|
+
}
|
|
30
|
+
/** The position one node of a walked file renders at. */
|
|
31
|
+
position(file, at) {
|
|
32
|
+
return renderPosition(file, this.#root, at.getStart());
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Records one use of each target, made by `from` at `at` in `file`. A write that stores
|
|
36
|
+
* `value` is remembered for the import bindings only its values use. A `production` use is
|
|
37
|
+
* production code's whoever writes it.
|
|
38
|
+
*/
|
|
39
|
+
add(file, at, from, targets, use, via, value, production = false) {
|
|
40
|
+
const position = "column" in at ? at : this.position(file, at);
|
|
41
|
+
const test = !production && this.#testFile(file);
|
|
42
|
+
for (const one of targets) {
|
|
43
|
+
const target = typeof one === "string" ? { id: one } : one;
|
|
44
|
+
this.#found.push({
|
|
45
|
+
from,
|
|
46
|
+
to: target.id,
|
|
47
|
+
position,
|
|
48
|
+
use,
|
|
49
|
+
resolution: target.guessed === true ? "by-name" : target.stepped === true ? "alias" : via,
|
|
50
|
+
test,
|
|
51
|
+
...(target.guessed === true ? { guessed: true } : {}),
|
|
52
|
+
});
|
|
53
|
+
if (this.#consumer === undefined && !("column" in at)) {
|
|
54
|
+
const named = this.#named.get(file) ?? [];
|
|
55
|
+
named.push({ index: this.#found.length - 1, at, annotated: this.#annotates(at, from) });
|
|
56
|
+
this.#named.set(file, named);
|
|
57
|
+
}
|
|
58
|
+
if (use === "write" && value !== undefined) {
|
|
59
|
+
const valued = this.#valued.get(file) ?? [];
|
|
60
|
+
valued.push({ index: this.#found.length - 1, value });
|
|
61
|
+
this.#valued.set(file, valued);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether a name sits in the annotation of `from`'s own declaration. An annotation holds
|
|
67
|
+
* no block, so the walk stops at the first declaration or block above the name.
|
|
68
|
+
*/
|
|
69
|
+
#annotates(name, from) {
|
|
70
|
+
if (name.kind === SyntaxKind.SourceFile) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
let child = name;
|
|
74
|
+
let parent = name.parent;
|
|
75
|
+
while (parent.kind !== SyntaxKind.Block && parent.kind !== SyntaxKind.SourceFile) {
|
|
76
|
+
const id = this.#declaredAt(parent);
|
|
77
|
+
if (id !== undefined) {
|
|
78
|
+
return id === from && parent.type === child;
|
|
79
|
+
}
|
|
80
|
+
child = parent;
|
|
81
|
+
parent = parent.parent;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
/** Holds declarations an unanswered question could have made live, and the one whose read asked it. */
|
|
86
|
+
hold(ids) {
|
|
87
|
+
for (const id of ids) {
|
|
88
|
+
this.#held.add(id);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The records made so far, before {@link finish} orders them. */
|
|
92
|
+
get made() {
|
|
93
|
+
return this.#found;
|
|
94
|
+
}
|
|
95
|
+
/** Appends records another stage derived from these, rendered already. */
|
|
96
|
+
extend(references) {
|
|
97
|
+
this.#found.push(...references);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The records in position order, then the declaration named, the referencing declaration
|
|
101
|
+
* and the use, each write marked with the import bindings only its values use, and the
|
|
102
|
+
* held declarations. `usesOf` gives each walked file's name sites.
|
|
103
|
+
*/
|
|
104
|
+
finish(usesOf) {
|
|
105
|
+
const found = this.#found;
|
|
106
|
+
for (const [file, writes] of this.#valued) {
|
|
107
|
+
for (const { index, names } of aloneIn(file, usesOf.get(file) ?? [], writes, found)) {
|
|
108
|
+
const reference = found[index];
|
|
109
|
+
if (reference !== undefined) {
|
|
110
|
+
found[index] = { ...reference, alone: names };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (const [file, named] of this.#named) {
|
|
115
|
+
for (const { index, carriers } of carriersIn(named, this.#valued.get(file) ?? [], found)) {
|
|
116
|
+
const reference = found[index];
|
|
117
|
+
if (reference !== undefined) {
|
|
118
|
+
found[index] = { ...reference, carriers };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
found.sort((a, b) => byPosition(a.position, b.position) ||
|
|
123
|
+
bytewise(a.to, b.to) ||
|
|
124
|
+
bytewise(a.from, b.from) ||
|
|
125
|
+
bytewise(a.use, b.use));
|
|
126
|
+
const consumer = this.#consumer;
|
|
127
|
+
return {
|
|
128
|
+
references: consumer === undefined
|
|
129
|
+
? found
|
|
130
|
+
: found.map((reference) => ({ ...reference, consumer: consumer.id })),
|
|
131
|
+
held: [...this.#held].sort(bytewise),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** The value one assignment stores through the name it writes, where it is a plain assignment. */
|
|
136
|
+
export function storedValue(name) {
|
|
137
|
+
let target = name;
|
|
138
|
+
if (isPropertyAccessExpression(name.parent) && name.parent.name === name) {
|
|
139
|
+
target = name.parent;
|
|
140
|
+
}
|
|
141
|
+
while (isParenthesizedExpression(target.parent)) {
|
|
142
|
+
target = target.parent;
|
|
143
|
+
}
|
|
144
|
+
const parent = target.parent;
|
|
145
|
+
return isBinaryExpression(parent) &&
|
|
146
|
+
parent.operatorToken.kind === SyntaxKind.EqualsToken &&
|
|
147
|
+
parent.left === target
|
|
148
|
+
? parent.right
|
|
149
|
+
: undefined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The import bindings of one file that only the values written into one declaration
|
|
153
|
+
* use, for each write into it. A binding is named by an identifier that spells its
|
|
154
|
+
* local name and is not the member a property access names.
|
|
155
|
+
*/
|
|
156
|
+
function aloneIn(file, uses, writes, found) {
|
|
157
|
+
const bindings = new Set(bindingsOf(file).map((binding) => binding.name.text));
|
|
158
|
+
if (bindings.size === 0) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
const occurrences = new Map();
|
|
162
|
+
for (const site of uses) {
|
|
163
|
+
const text = site.node.getText();
|
|
164
|
+
const parent = site.node.parent;
|
|
165
|
+
if (!bindings.has(text) || (isPropertyAccessExpression(parent) && parent.name === site.node)) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (!occurrences.get(text)?.includes(site.node)) {
|
|
169
|
+
occurrences.set(text, [...(occurrences.get(text) ?? []), site.node]);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const inside = (node, value) => node.pos >= value.pos && node.end <= value.end;
|
|
173
|
+
const result = [];
|
|
174
|
+
for (const write of writes) {
|
|
175
|
+
const to = found[write.index]?.to;
|
|
176
|
+
const sameTarget = writes.filter((one) => found[one.index]?.to === to);
|
|
177
|
+
const names = [...occurrences]
|
|
178
|
+
.filter(([, nodes]) => nodes.some((node) => inside(node, write.value)) &&
|
|
179
|
+
nodes.every((node) => sameTarget.some((one) => inside(node, one.value))))
|
|
180
|
+
.map(([name]) => name)
|
|
181
|
+
.sort(bytewise);
|
|
182
|
+
if (names.length > 0) {
|
|
183
|
+
result.push({ index: write.index, names });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The carriers of each named record of one file: `from` where its own annotation holds the
|
|
190
|
+
* name, then the target of each write whose stored value holds it and that names another
|
|
191
|
+
* declaration, the innermost value first. Values nest or are disjoint.
|
|
192
|
+
*/
|
|
193
|
+
function carriersIn(named, writes, found) {
|
|
194
|
+
const byStart = [...named].sort((a, b) => a.at.pos - b.at.pos);
|
|
195
|
+
const holding = new Map();
|
|
196
|
+
for (const write of writes) {
|
|
197
|
+
let low = 0;
|
|
198
|
+
let high = byStart.length;
|
|
199
|
+
while (low < high) {
|
|
200
|
+
const middle = (low + high) >>> 1;
|
|
201
|
+
if ((byStart[middle]?.at.pos ?? 0) < write.value.pos) {
|
|
202
|
+
low = middle + 1;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
high = middle;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
for (let at = low; at < byStart.length; at += 1) {
|
|
209
|
+
const one = byStart[at];
|
|
210
|
+
if (one === undefined || one.at.pos >= write.value.end) {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
if (one.at.end <= write.value.end) {
|
|
214
|
+
holding.set(one.index, [...(holding.get(one.index) ?? []), write]);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const result = [];
|
|
219
|
+
for (const one of named) {
|
|
220
|
+
const reference = found[one.index];
|
|
221
|
+
if (reference === undefined) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const carriers = one.annotated ? [reference.from] : [];
|
|
225
|
+
const values = [...(holding.get(one.index) ?? [])].sort((a, b) => a.value.end - a.value.pos - (b.value.end - b.value.pos));
|
|
226
|
+
for (const write of values) {
|
|
227
|
+
const to = found[write.index]?.to;
|
|
228
|
+
if (to !== undefined && to !== reference.to && !carriers.includes(to)) {
|
|
229
|
+
carriers.push(to);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (carriers.length > 0) {
|
|
233
|
+
result.push({ index: one.index, carriers });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|