@plannotator/sem-jiff 0.0.0-stage → 0.2.2
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/CHANGELOG.md +77 -0
- package/LICENSE-APACHE +191 -0
- package/LICENSE-MIT +21 -0
- package/README.md +122 -2
- package/THIRD-PARTY-NOTICES +367 -0
- package/dist/candidate.d.ts +14 -0
- package/dist/candidate.js +1 -0
- package/dist/classifier.d.ts +25 -0
- package/dist/classifier.js +32 -0
- package/dist/copy-wasm-bin.d.ts +2 -0
- package/dist/copy-wasm-bin.js +11 -0
- package/dist/copy-wasm.d.ts +3 -0
- package/dist/copy-wasm.js +43 -0
- package/dist/coverage.d.ts +7 -0
- package/dist/coverage.js +43 -0
- package/dist/edits.d.ts +10 -0
- package/dist/edits.js +230 -0
- package/dist/extract.d.ts +5 -0
- package/dist/extract.js +24 -0
- package/dist/grammars.d.ts +22 -0
- package/dist/grammars.js +37 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +581 -0
- package/dist/inline.d.ts +21 -0
- package/dist/inline.js +959 -0
- package/dist/languages.d.ts +2 -0
- package/dist/languages.js +28 -0
- package/dist/linediff.d.ts +28 -0
- package/dist/linediff.js +205 -0
- package/dist/opinions.d.ts +84 -0
- package/dist/opinions.js +201 -0
- package/dist/pairing.d.ts +10 -0
- package/dist/pairing.js +269 -0
- package/dist/parse.d.ts +119 -0
- package/dist/parse.js +1293 -0
- package/dist/pierre-types.d.ts +101 -0
- package/dist/pierre-types.js +5 -0
- package/dist/runtime.d.ts +48 -0
- package/dist/runtime.js +60 -0
- package/dist/structure.d.ts +23 -0
- package/dist/structure.js +1111 -0
- package/dist/summary.d.ts +19 -0
- package/dist/summary.js +15 -0
- package/dist/symbol-types.d.ts +18 -0
- package/dist/symbol-types.js +1 -0
- package/dist/symbols.d.ts +6 -0
- package/dist/symbols.js +458 -0
- package/dist/syntax.d.ts +69 -0
- package/dist/syntax.js +450 -0
- package/dist/textdiff.d.ts +15 -0
- package/dist/textdiff.js +64 -0
- package/dist/textmoves.d.ts +8 -0
- package/dist/textmoves.js +143 -0
- package/package.json +108 -4
- package/src/candidate.ts +10 -0
- package/src/grammars.ts +44 -0
- package/src/opinions.ts +271 -0
- package/wasm/SHA256SUMS +12 -0
- package/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/wasm/tree-sitter-go.wasm +0 -0
- package/wasm/tree-sitter-java.wasm +0 -0
- package/wasm/tree-sitter-kotlin.wasm +0 -0
- package/wasm/tree-sitter-php.wasm +0 -0
- package/wasm/tree-sitter-python.wasm +0 -0
- package/wasm/tree-sitter-ruby.wasm +0 -0
- package/wasm/tree-sitter-rust.wasm +0 -0
- package/wasm/tree-sitter-swift.wasm +0 -0
- package/wasm/tree-sitter-tsx.wasm +0 -0
- package/wasm/tree-sitter-typescript.wasm +0 -0
- package/wasm/web-tree-sitter.wasm +0 -0
package/dist/pairing.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Which function on one side is the same function on the other: the pairing the extract/inline
|
|
2
|
+
// check builds on. A function with a counterpart still exists (it was not inlined or extracted);
|
|
3
|
+
// one with a twin moved or was renamed. Each rule below is one way the same function shows up.
|
|
4
|
+
import { rule, trial } from "./runtime.js";
|
|
5
|
+
import { swiftParams } from "./parse.js";
|
|
6
|
+
import { callsParent, callsTo, dice, pairSameNamed, tokens } from "./syntax.js";
|
|
7
|
+
export function pairFunctions(oldFns, newFns, oldRoot, newRoot, cfg) {
|
|
8
|
+
// Same function in both versions: same class (or receiver) and name, or, when the
|
|
9
|
+
// class itself was renamed, the only function of that name on each side.
|
|
10
|
+
// Overloads share a name: pair them by body similarity, not by order.
|
|
11
|
+
// The overload that kept the old parameter list is the old function: when code moves
|
|
12
|
+
// into a new, longer overload (`readFrom(in, funnel)` -> `readFrom(in, funnel, max)`),
|
|
13
|
+
// body similarity alone would pair the old one with the overload now holding its code.
|
|
14
|
+
// Trial FN_PAIRING: Swift has no `parameters` field. Its signature is the declaration's header before the
|
|
15
|
+
// body (parameter labels and types, `async`, `throws`, the result type), so overloads are told apart by what
|
|
16
|
+
// they take and give, not by their bodies alone.
|
|
17
|
+
const fnPairing = trial('FN_PAIRING');
|
|
18
|
+
const swiftSig = (f) => fnPairing && cfg.id === 'swift' && SWIFT_SIGNED.has(f.node.type);
|
|
19
|
+
const signature = (f) => {
|
|
20
|
+
const p = swiftSig(f)
|
|
21
|
+
? f.node.children.filter((c) => !!c && c.endIndex <= f.body.startIndex && c.type !== 'modifiers').flatMap(tokens).slice(0, 60)
|
|
22
|
+
: tokens(f.node.childForFieldName('parameters') ?? f.node.childForFieldName('value')?.childForFieldName('parameters') ?? f.body).slice(0, 60);
|
|
23
|
+
return [...p, ...p, ...p, ...tokens(f.body)];
|
|
24
|
+
};
|
|
25
|
+
// An overload that kept the old parameter list exactly is the old function, however
|
|
26
|
+
// much its body changed: `consumeMessages(brokerUrl, topics)` became a wrapper around a
|
|
27
|
+
// new `consumeMessages(consumer, topics)` that now holds the old body.
|
|
28
|
+
const base = (f) => f.key.replace(/#\d+$/, '');
|
|
29
|
+
const params = (f) => {
|
|
30
|
+
const p = f.node.childForFieldName('parameters') ?? f.node.childForFieldName('value')?.childForFieldName('parameters');
|
|
31
|
+
return p ? tokens(p).join(' ') : null;
|
|
32
|
+
};
|
|
33
|
+
// A tie-break, not a key: only huge same-name groups (which otherwise pair in order) pair an exact parameter list first.
|
|
34
|
+
const exactSignature = (f) => (swiftSig(f) ? swiftParams(f.node) : params(f));
|
|
35
|
+
const samePlace = (fs, f) => fs.filter((g) => base(g) === base(f));
|
|
36
|
+
const pinned = [];
|
|
37
|
+
// Either way round: one function became several overloads, or several became one.
|
|
38
|
+
for (const f of oldFns) {
|
|
39
|
+
const p = params(f);
|
|
40
|
+
const olds = samePlace(oldFns, f);
|
|
41
|
+
const news = samePlace(newFns, f);
|
|
42
|
+
if (p === null || olds.length > 1 || news.length < 2)
|
|
43
|
+
continue;
|
|
44
|
+
const same = news.filter((g) => params(g) === p);
|
|
45
|
+
if (same.length === 1)
|
|
46
|
+
pinned.push([f, same[0]]);
|
|
47
|
+
}
|
|
48
|
+
for (const g of newFns) {
|
|
49
|
+
const p = params(g);
|
|
50
|
+
const olds = samePlace(oldFns, g);
|
|
51
|
+
const news = samePlace(newFns, g);
|
|
52
|
+
if (p === null || news.length > 1 || olds.length < 2)
|
|
53
|
+
continue;
|
|
54
|
+
const same = olds.filter((f) => params(f) === p);
|
|
55
|
+
if (same.length === 1)
|
|
56
|
+
pinned.push([same[0], g]);
|
|
57
|
+
}
|
|
58
|
+
// A body that reappears token for token under another name was renamed, even when a new
|
|
59
|
+
// function took the old name (`run` -> `fly` and a new `run`; `comments` -> `reviewComments`
|
|
60
|
+
// while `conversation` -> `comments`): pairing by name would set up a false extract and inline.
|
|
61
|
+
// Only one-to-one identical bodies of some size, and only when the same-name partner differs.
|
|
62
|
+
if (rule('SWAPPED_RENAMES')) {
|
|
63
|
+
const text = (f) => tokens(f.body).join(' ');
|
|
64
|
+
const sized = (f) => tokens(f.body).length >= 12;
|
|
65
|
+
const group = (fs) => fs.filter(sized).reduce((m, f) => m.set(text(f), [...(m.get(text(f)) ?? []), f]), new Map());
|
|
66
|
+
const og = group(oldFns);
|
|
67
|
+
const ng = group(newFns);
|
|
68
|
+
const taken = new Set(pinned.flat());
|
|
69
|
+
for (const [t, os] of og) {
|
|
70
|
+
const ns = ng.get(t);
|
|
71
|
+
if (os.length !== 1 || ns?.length !== 1)
|
|
72
|
+
continue;
|
|
73
|
+
const [f, g] = [os[0], ns[0]];
|
|
74
|
+
if (f.name === g.name || taken.has(f) || taken.has(g))
|
|
75
|
+
continue;
|
|
76
|
+
const sameNameNew = newFns.filter((x) => base(x) === base(f));
|
|
77
|
+
const sameNameOld = oldFns.filter((x) => base(x) === base(g));
|
|
78
|
+
// Unless one side's same-name partner is just as identical (then it is a copy, not a rename).
|
|
79
|
+
if ([...sameNameNew, ...sameNameOld].some((x) => text(x) === t))
|
|
80
|
+
continue;
|
|
81
|
+
if (!sameNameNew.length && !sameNameOld.length)
|
|
82
|
+
continue; // a plain rename: hasTwin handles it
|
|
83
|
+
// A namesake that called the other one took its whole body: an inline (`entrySet()` that
|
|
84
|
+
// called `createEntrySet()` now holds its body) or, the other way round, an extract.
|
|
85
|
+
if (sameNameOld.some((x) => callsTo(x.node, f.name, cfg).length) || sameNameNew.some((x) => callsTo(x.node, g.name, cfg).length))
|
|
86
|
+
continue;
|
|
87
|
+
pinned.push([f, g]);
|
|
88
|
+
taken.add(f).add(g);
|
|
89
|
+
}
|
|
90
|
+
if (fnPairing)
|
|
91
|
+
pinned.push(...renameChains(oldFns, newFns, oldRoot, newRoot, cfg, base, taken));
|
|
92
|
+
}
|
|
93
|
+
const pinnedOld = new Set(pinned.map(([a]) => a));
|
|
94
|
+
const pinnedNew = new Set(pinned.map(([, b]) => b));
|
|
95
|
+
const byKey = new Map([
|
|
96
|
+
...pinned,
|
|
97
|
+
...pairSameNamed(oldFns.filter((f) => !pinnedOld.has(f)), newFns.filter((f) => !pinnedNew.has(f)), base, signature, undefined, fnPairing ? exactSignature : undefined),
|
|
98
|
+
]);
|
|
99
|
+
const count = (fs) => fs.reduce((m, f) => m.set(f.name, (m.get(f.name) ?? 0) + 1), new Map());
|
|
100
|
+
const oldCount = count(oldFns);
|
|
101
|
+
const newCount = count(newFns);
|
|
102
|
+
// With FN_PAIRING, a function already paired (a rename chain took it) is no one else's counterpart by name.
|
|
103
|
+
const pairedNew = fnPairing ? new Set(byKey.values()) : new Set();
|
|
104
|
+
const newOnlyByName = new Map(newFns.filter((f) => newCount.get(f.name) === 1 && !pairedNew.has(f)).map((f) => [f.name, f]));
|
|
105
|
+
const counterpart = (f) => byKey.get(f) ?? (oldCount.get(f.name) === 1 ? newOnlyByName.get(f.name) : undefined);
|
|
106
|
+
// A function whose twin (same name, same body) is on the other side was moved or
|
|
107
|
+
// had its class renamed; it was not inlined or extracted.
|
|
108
|
+
// Likewise one whose body reappears in a new function under another name was renamed
|
|
109
|
+
// (`entryIterator` -> `internalEntryIterator`, callers updated).
|
|
110
|
+
const matched = new Set(oldFns.map((f) => counterpart(f)).filter((g) => !!g));
|
|
111
|
+
// A rename takes the old name away. When that name is still declared on this side (the
|
|
112
|
+
// function was kept, say as a one-line arrow the pairing above does not see), its body
|
|
113
|
+
// moving to a new function is an extract or inline, not a rename. (Mere references do
|
|
114
|
+
// not count: callers elsewhere may keep calling the old name.)
|
|
115
|
+
// Declarations are counted: overrides in several classes share a name, and renaming
|
|
116
|
+
// some of them still takes declarations away.
|
|
117
|
+
let declared = null;
|
|
118
|
+
const stillNamed = (name) => {
|
|
119
|
+
declared ??= [namesIn(oldRoot), namesIn(newRoot)];
|
|
120
|
+
return (declared[0].get(name) ?? 0) >= (declared[1].get(name) ?? 0);
|
|
121
|
+
};
|
|
122
|
+
const hasTwin = (f) => {
|
|
123
|
+
const t = tokens(f.body);
|
|
124
|
+
return newFns.some((g) => {
|
|
125
|
+
// Same name, same body: moved. Unless that function is still paired with another one
|
|
126
|
+
// here (it kept its signature as a wrapper): then the body went into a new overload.
|
|
127
|
+
if (g.name === f.name)
|
|
128
|
+
return !matched.has(g) && dice(tokens(g.body), t) >= 0.9;
|
|
129
|
+
// Renamed and lightly edited on the way (`IsSafe` -> `Validate`, 0.82 alike).
|
|
130
|
+
return !matched.has(g) && t.length >= 8 && dice(tokens(g.body), t) >= 0.8 && !stillNamed(g.name);
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
return { counterpart, hasTwin };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Trial FN_PAIRING: renames where a new function took the old name, which name-only pairing reads as an
|
|
137
|
+
* extract or inline. `f` (old) and `g` (new) under different names
|
|
138
|
+
* in one class are one function when their bodies are near-identical (dice >= 0.9, 12+ tokens), or identical and short
|
|
139
|
+
* with the references to the name moved over (`schema` -> `__schema__`, callers updated); one to one, and
|
|
140
|
+
* only when a namesake took a name. A namesake that calls the other one took its body (an inline or an
|
|
141
|
+
* extract), unless it is itself one link of the chain: its body reappears in another new (old) function,
|
|
142
|
+
* with the call renamed (`clearDiskCache()` -> `clearDiskCache_()` while `clearDiskCacheWith...(_:)` ->
|
|
143
|
+
* `clearDiskCache(with:)`); a call to the parent's version (`super.f`, `superclass&.__schema__`) never counts.
|
|
144
|
+
*/
|
|
145
|
+
function renameChains(oldFns, newFns, oldRoot, newRoot, cfg, base, taken) {
|
|
146
|
+
const out = [];
|
|
147
|
+
const toks = new Map();
|
|
148
|
+
const t = (f) => toks.get(f) ?? (toks.set(f, tokens(f.body)), toks.get(f));
|
|
149
|
+
const same = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
150
|
+
let refs = null;
|
|
151
|
+
const moved = (from, to) => {
|
|
152
|
+
refs ??= [leafCounts(oldRoot), leafCounts(newRoot)];
|
|
153
|
+
const [o, n] = refs;
|
|
154
|
+
return (o.get(from) ?? 0) > (n.get(from) ?? 0) && (n.get(to) ?? 0) > (o.get(to) ?? 0);
|
|
155
|
+
};
|
|
156
|
+
const alike = (f, g) => {
|
|
157
|
+
const a = t(f);
|
|
158
|
+
const b = t(g);
|
|
159
|
+
if (a.length >= 12 && b.length >= 12)
|
|
160
|
+
return dice(a, b);
|
|
161
|
+
return a.length >= 4 && same(a, b) && f.name !== g.name && moved(f.name, g.name) ? 1 : 0;
|
|
162
|
+
};
|
|
163
|
+
const scope = (f) => base(f).slice(0, base(f).lastIndexOf('/'));
|
|
164
|
+
const ownCalls = (x, name) => callsTo(x.node, name, cfg).filter((c) => !callsParent(c));
|
|
165
|
+
// `x` (on one side) calls `name`; its own twin `y` on the other side calls `to` and reads the same with the call renamed.
|
|
166
|
+
// `y` is new to its side: no function of its name on `x`'s side.
|
|
167
|
+
const chainTwin = (x, name, to, others, xSide) => {
|
|
168
|
+
const want = t(x).map((k) => (k === name ? to : k));
|
|
169
|
+
return others.find((y) => !taken.has(y) && y.name !== x.name && !xSide.some((z) => base(z) === base(y)) && ownCalls(y, to).length && dice(want, t(y)) >= 0.8);
|
|
170
|
+
};
|
|
171
|
+
const best = (pool, skip, score1) => {
|
|
172
|
+
let top = null;
|
|
173
|
+
let score = 0;
|
|
174
|
+
let tie = false;
|
|
175
|
+
for (const g of pool) {
|
|
176
|
+
if (taken.has(g) || skip(g))
|
|
177
|
+
continue;
|
|
178
|
+
const s = score1(g);
|
|
179
|
+
if (s > score) {
|
|
180
|
+
top = g;
|
|
181
|
+
score = s;
|
|
182
|
+
tie = false;
|
|
183
|
+
}
|
|
184
|
+
else if (s === score && s > 0)
|
|
185
|
+
tie = true;
|
|
186
|
+
}
|
|
187
|
+
return score >= 0.9 && !tie ? { g: top, score } : null;
|
|
188
|
+
};
|
|
189
|
+
for (const f of oldFns) {
|
|
190
|
+
if (taken.has(f))
|
|
191
|
+
continue;
|
|
192
|
+
const m = best(newFns, (g) => g.name === f.name || scope(g) !== scope(f), (g) => alike(f, g));
|
|
193
|
+
if (!m)
|
|
194
|
+
continue;
|
|
195
|
+
const { g, score } = m;
|
|
196
|
+
const back = best(oldFns, (x) => x.name === g.name || scope(x) !== scope(g), (x) => alike(x, g));
|
|
197
|
+
if (back?.g !== f)
|
|
198
|
+
continue;
|
|
199
|
+
const sameNameNew = newFns.filter((x) => base(x) === base(f));
|
|
200
|
+
const sameNameOld = oldFns.filter((x) => base(x) === base(g));
|
|
201
|
+
if (!sameNameNew.length && !sameNameOld.length)
|
|
202
|
+
continue; // a plain rename: hasTwin handles it
|
|
203
|
+
// A same-name partner just as alike: a copy, not a rename.
|
|
204
|
+
if (sameNameNew.some((x) => alike(f, x) >= score) || sameNameOld.some((x) => alike(x, g) >= score))
|
|
205
|
+
continue;
|
|
206
|
+
const links = [];
|
|
207
|
+
let namesakeTookIt = false;
|
|
208
|
+
for (const x of sameNameOld) {
|
|
209
|
+
if (!ownCalls(x, f.name).length)
|
|
210
|
+
continue;
|
|
211
|
+
const y = chainTwin(x, f.name, g.name, newFns.filter((y) => y !== g), oldFns);
|
|
212
|
+
if (y)
|
|
213
|
+
links.push([x, y]);
|
|
214
|
+
else
|
|
215
|
+
namesakeTookIt = true;
|
|
216
|
+
}
|
|
217
|
+
for (const x of sameNameNew) {
|
|
218
|
+
if (!ownCalls(x, g.name).length)
|
|
219
|
+
continue;
|
|
220
|
+
const y = chainTwin(x, g.name, f.name, oldFns.filter((y) => y !== f), newFns);
|
|
221
|
+
if (y)
|
|
222
|
+
links.push([y, x]);
|
|
223
|
+
else
|
|
224
|
+
namesakeTookIt = true;
|
|
225
|
+
}
|
|
226
|
+
if (namesakeTookIt)
|
|
227
|
+
continue;
|
|
228
|
+
out.push([f, g], ...links);
|
|
229
|
+
taken.add(f).add(g);
|
|
230
|
+
for (const [a, b] of links)
|
|
231
|
+
taken.add(a).add(b);
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
/** How often each leaf text occurs in the tree (declarations and references alike). */
|
|
236
|
+
function leafCounts(root) {
|
|
237
|
+
const out = new Map();
|
|
238
|
+
const stack = [root];
|
|
239
|
+
while (stack.length) {
|
|
240
|
+
const n = stack.pop();
|
|
241
|
+
if (n.childCount === 0) {
|
|
242
|
+
out.set(n.text, (out.get(n.text) ?? 0) + 1);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
for (const c of n.children)
|
|
246
|
+
if (c)
|
|
247
|
+
stack.push(c);
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
/** Swift declarations with a parameter list (a computed property has none). */
|
|
252
|
+
const SWIFT_SIGNED = new Set(['function_declaration', 'init_declaration', 'subscript_declaration']);
|
|
253
|
+
/** How often the tree declares each name (a leaf that is its parent's `name` field). */
|
|
254
|
+
function namesIn(root) {
|
|
255
|
+
const out = new Map();
|
|
256
|
+
const stack = [root];
|
|
257
|
+
while (stack.length) {
|
|
258
|
+
const n = stack.pop();
|
|
259
|
+
if (n.childCount === 0) {
|
|
260
|
+
if (n.parent?.childForFieldName('name')?.id === n.id)
|
|
261
|
+
out.set(n.text, (out.get(n.text) ?? 0) + 1);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
for (const c of n.children)
|
|
265
|
+
if (c)
|
|
266
|
+
stack.push(c);
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Parser, type Node, type Tree } from 'web-tree-sitter';
|
|
2
|
+
import type { LanguageId } from './languages.js';
|
|
3
|
+
export { languageForPath, type LanguageId } from './languages.js';
|
|
4
|
+
/** Comment node types across grammars (Rust splits line and block comments; Swift calls block comments multiline_comment). */
|
|
5
|
+
export declare const COMMENT_TYPES: ReadonlySet<string>;
|
|
6
|
+
export declare const isComment: (n: Node | null | undefined) => boolean;
|
|
7
|
+
export interface LanguageConfig {
|
|
8
|
+
id: LanguageId;
|
|
9
|
+
/** The grammar's package path, e.g. `tree-sitter-go/tree-sitter-go.wasm` (see `configure`). */
|
|
10
|
+
wasm: string;
|
|
11
|
+
/** Node types that declare a named function or method. */
|
|
12
|
+
functionTypes: ReadonlySet<string>;
|
|
13
|
+
/** Node types that call a function (PHP has four: plain, member, static and nullsafe calls). */
|
|
14
|
+
callTypes: ReadonlySet<string>;
|
|
15
|
+
/** Node types that hold a list of statements. */
|
|
16
|
+
blockTypes: ReadonlySet<string>;
|
|
17
|
+
/** The statement returns from the function (`last`: it is the body's final statement, for tail expressions). */
|
|
18
|
+
isReturn(stmt: Node, last: boolean): boolean;
|
|
19
|
+
/** The function's name, or null for anonymous functions. */
|
|
20
|
+
nameOf(fn: Node): string | null;
|
|
21
|
+
/** The block node holding the function's statements. */
|
|
22
|
+
bodyOf(fn: Node): Node | null;
|
|
23
|
+
/** Statements directly inside a block. */
|
|
24
|
+
statementsOf(block: Node): Node[];
|
|
25
|
+
/** The callee name of a call expression, e.g. `foo` for `a.foo(x)`. */
|
|
26
|
+
calleeOf(call: Node): string | null;
|
|
27
|
+
/** The expression a return statement returns, if any. */
|
|
28
|
+
returnValueOf(ret: Node): Node | null;
|
|
29
|
+
/** Leaf node types that are names (variables, fields, types). */
|
|
30
|
+
identifierTypes: ReadonlySet<string>;
|
|
31
|
+
/** An identifier that is never a name to rename or pair by (Swift: names inside attributes such as `@State`). */
|
|
32
|
+
notAName?(id: Node): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Named declarations directly inside `container` (the file, or a class body),
|
|
35
|
+
* with the node to treat as the whole declaration and, for classes, the body
|
|
36
|
+
* that holds its members.
|
|
37
|
+
*/
|
|
38
|
+
declarationsIn(container: Node): Declaration[];
|
|
39
|
+
/**
|
|
40
|
+
* Node types that hold the lines just above a declaration and belong to it:
|
|
41
|
+
* comments, and attributes such as Rust's `#[derive(..)]`.
|
|
42
|
+
*/
|
|
43
|
+
attachedTypes: ReadonlySet<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Tokens the grammar reports as missing on trees that are in fact correct (Kotlin's
|
|
46
|
+
* `_class_member_semi` on one-line class bodies). Any other missing token or error means the
|
|
47
|
+
* code does not parse, and no formatting claim is made about it.
|
|
48
|
+
*/
|
|
49
|
+
harmlessMissing?: ReadonlySet<string>;
|
|
50
|
+
/**
|
|
51
|
+
* An error node the grammar makes around correct code (Swift 0.7.3: a `#else` or `#endif` line between a
|
|
52
|
+
* declaration's attributes, or a zero-width error before a directive in a type body). Code holding only such
|
|
53
|
+
* errors still counts as parsed for formatting claims.
|
|
54
|
+
*/
|
|
55
|
+
harmlessError?(n: Node): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* What the code at a line means depends on more than its own text (the namespace in effect, a
|
|
58
|
+
* visibility section): a move from one context to another is an edit, never a plain move.
|
|
59
|
+
*/
|
|
60
|
+
contextAt?(root: Node, line: number): string;
|
|
61
|
+
/**
|
|
62
|
+
* The position of an item on the line whose order means something (Kotlin's constructor parameters, enum
|
|
63
|
+
* entries): a move that changes it is an edit. Unlike contextAt, wrapping a list onto lines changes nothing here.
|
|
64
|
+
*/
|
|
65
|
+
positionAt?(root: Node, line: number): string;
|
|
66
|
+
/**
|
|
67
|
+
* Compare a claim's contexts range by range, in line order with runs collapsed, instead of
|
|
68
|
+
* requiring one context on each side: a whole Kotlin class moved with its doc comment and
|
|
69
|
+
* companion object keeps its move. Languages without it keep the one-context rule.
|
|
70
|
+
*/
|
|
71
|
+
contextRuns?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Claims this language does not make yet: their lines are shown as plain edits (0.2.1: the classes over
|
|
74
|
+
* the bar on the held3 blind set, in Ruby, Kotlin and Swift). Measurement lifts it with the HOLD_BACK
|
|
75
|
+
* rule off (SEMANTIC_NO_HOLD_BACK=1 in the harness).
|
|
76
|
+
*/
|
|
77
|
+
holdBack?: ReadonlySet<string>;
|
|
78
|
+
/**
|
|
79
|
+
* The type whose members a container holds, when members of one type can sit in several containers
|
|
80
|
+
* (Swift: a struct and its extensions). Those containers share one member scope, so a member moved
|
|
81
|
+
* from one to another pairs and is moved.
|
|
82
|
+
*/
|
|
83
|
+
typeOf?(container: Declaration): string | null;
|
|
84
|
+
/**
|
|
85
|
+
* Of two declarations that swapped places, call the edited one moved and keep the unchanged one in
|
|
86
|
+
* place, so an unchanged declaration is never named as the move while its edited neighbour moved.
|
|
87
|
+
* Swift only for now: turning it on for the languages scored before it would change their results.
|
|
88
|
+
*/
|
|
89
|
+
moveEditedFirst?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* What sits on a declaration and changes how it behaves rather than what it does (Swift attributes:
|
|
92
|
+
* `@State` to `@Binding`, a wrapper added or removed). A declaration whose marks changed is edited,
|
|
93
|
+
* never moved.
|
|
94
|
+
*/
|
|
95
|
+
marksOf?(decl: Node): string;
|
|
96
|
+
}
|
|
97
|
+
/** The node holds an error, or a missing token that is not harmless for its language. */
|
|
98
|
+
export declare function brokenTree(n: Node, cfg: LanguageConfig): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Imports are declarations too, named by what they import (the module path), so
|
|
101
|
+
* re-sorted imports pair up and show as moved rather than deleted and re-added.
|
|
102
|
+
* Adding a language's imports takes only the key: the text of its module path.
|
|
103
|
+
*/
|
|
104
|
+
export declare const importDeclaration: (node: Node, key: string, prefix?: string) => Declaration;
|
|
105
|
+
export interface Declaration {
|
|
106
|
+
node: Node;
|
|
107
|
+
kind: string;
|
|
108
|
+
name: string;
|
|
109
|
+
members?: Node;
|
|
110
|
+
/** The last node the declaration covers when that is not `node` itself (a Ruby heredoc body after it). */
|
|
111
|
+
tail?: Node;
|
|
112
|
+
}
|
|
113
|
+
/** The type written before a declaration's name (`String` in `fun String.shout()`), if any. */
|
|
114
|
+
export declare const kotlinReceiver: (n: Node) => Node | null;
|
|
115
|
+
export declare const swiftParams: (fn: Node) => string;
|
|
116
|
+
export declare const LANGUAGES: Record<LanguageId, LanguageConfig>;
|
|
117
|
+
export declare function getParser(id: LanguageId): Promise<Parser>;
|
|
118
|
+
/** Parse both versions, run `fn`, and always free the trees (they live in WASM memory). */
|
|
119
|
+
export declare function withTrees<T>(id: LanguageId, oldText: string, newText: string, fn: (oldTree: Tree, newTree: Tree) => T): Promise<T>;
|