lanekeeper 0.0.0-stage → 0.2.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/dist/bin.js +14 -0
- package/dist/chunk-7JIFSCFK.js +11881 -0
- package/dist/chunk-CWG6ZS4T.js +1034 -0
- package/dist/chunk-GQH23HGZ.js +17263 -0
- package/dist/chunk-HF2SRAEZ.js +8371 -0
- package/dist/chunk-HYHMF4RP.js +25 -0
- package/dist/chunk-JDNSSLDE.js +207 -0
- package/dist/chunk-R7L42AHY.js +4714 -0
- package/dist/grammars/tree-sitter-c_sharp.wasm +0 -0
- package/dist/grammars/tree-sitter-go.wasm +0 -0
- package/dist/grammars/tree-sitter-java.wasm +0 -0
- package/dist/grammars/tree-sitter-javascript.wasm +0 -0
- package/dist/grammars/tree-sitter-kotlin.wasm +0 -0
- package/dist/grammars/tree-sitter-php.wasm +0 -0
- package/dist/grammars/tree-sitter-python.wasm +0 -0
- package/dist/grammars/tree-sitter-ruby.wasm +0 -0
- package/dist/grammars/tree-sitter-rust.wasm +0 -0
- package/dist/grammars/tree-sitter-swift.wasm +0 -0
- package/dist/grammars/tree-sitter-tsx.wasm +0 -0
- package/dist/grammars/tree-sitter-typescript.wasm +0 -0
- package/dist/hook-26SGAMVY.js +308 -0
- package/dist/hook.js +29 -0
- package/dist/index.js +18 -0
- package/dist/main-QKDGSOKC.js +14 -0
- package/dist/queries/cs.scm +70 -0
- package/dist/queries/go.scm +53 -0
- package/dist/queries/java.scm +45 -0
- package/dist/queries/kt.scm +48 -0
- package/dist/queries/php.scm +67 -0
- package/dist/queries/rb.scm +47 -0
- package/dist/queries/rs.scm +74 -0
- package/dist/queries/swift.scm +49 -0
- package/dist/src-K6RW2H7J.js +17172 -0
- package/dist/tags-UPJ5TKHW.js +522 -0
- package/dist/wasm/web-tree-sitter.wasm +0 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,4714 @@
|
|
|
1
|
+
import { createRequire as __lkCreateRequire } from "node:module"; const require = __lkCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
catFileBatch,
|
|
4
|
+
diffNameStatus,
|
|
5
|
+
diffTreeHunks,
|
|
6
|
+
lsTree,
|
|
7
|
+
mergeBase,
|
|
8
|
+
readWorking,
|
|
9
|
+
snapshotWorktree
|
|
10
|
+
} from "./chunk-CWG6ZS4T.js";
|
|
11
|
+
import {
|
|
12
|
+
HTTP_METHODS,
|
|
13
|
+
LANGS,
|
|
14
|
+
Parser,
|
|
15
|
+
SEVERITY_RANK,
|
|
16
|
+
endLineOf,
|
|
17
|
+
external_exports,
|
|
18
|
+
hashTokens,
|
|
19
|
+
langForPath,
|
|
20
|
+
leafTokens,
|
|
21
|
+
lineOf,
|
|
22
|
+
loadLanguage,
|
|
23
|
+
normalizedText,
|
|
24
|
+
reportParseError,
|
|
25
|
+
squash,
|
|
26
|
+
stringValue
|
|
27
|
+
} from "./chunk-HF2SRAEZ.js";
|
|
28
|
+
import {
|
|
29
|
+
RULE_NAMES,
|
|
30
|
+
claimTargetText,
|
|
31
|
+
clashId,
|
|
32
|
+
hex16,
|
|
33
|
+
parseSymbolId,
|
|
34
|
+
symbolIdOf
|
|
35
|
+
} from "./chunk-GQH23HGZ.js";
|
|
36
|
+
|
|
37
|
+
// ../analysis/src/parse/lang/python.ts
|
|
38
|
+
var CALL_SEMANTICS_DECORATORS = /^(property|staticmethod|classmethod|cached_property|functools\.cached_property|[\w.]+\.(setter|getter|deleter))$/;
|
|
39
|
+
var UPPER_CASE = /^[A-Z][A-Z0-9_]*$/;
|
|
40
|
+
var PY = { dropSemicolons: true, dropTrailingCommas: false };
|
|
41
|
+
function pyText(node) {
|
|
42
|
+
return normalizedText(node, void 0, PY);
|
|
43
|
+
}
|
|
44
|
+
function extractPython(root, out) {
|
|
45
|
+
const ctx = {
|
|
46
|
+
out,
|
|
47
|
+
symbols: /* @__PURE__ */ new Map(),
|
|
48
|
+
declNodes: /* @__PURE__ */ new Map(),
|
|
49
|
+
importLocals: /* @__PURE__ */ new Set(),
|
|
50
|
+
all: findAll(root)
|
|
51
|
+
};
|
|
52
|
+
for (const stmt of root.namedChildren) if (stmt) declareStatement(ctx, stmt);
|
|
53
|
+
out.symbols.push(...ctx.symbols.values());
|
|
54
|
+
collectRefs(ctx, root);
|
|
55
|
+
}
|
|
56
|
+
function findAll(root) {
|
|
57
|
+
for (const stmt of root.namedChildren) {
|
|
58
|
+
const assign = stmt?.type === "expression_statement" ? stmt.namedChild(0) : null;
|
|
59
|
+
if (assign?.type !== "assignment" || assign.childForFieldName("left")?.text !== "__all__") continue;
|
|
60
|
+
const right = assign.childForFieldName("right");
|
|
61
|
+
if (right?.type !== "list" && right?.type !== "tuple") return null;
|
|
62
|
+
const names = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const el of right.namedChildren) {
|
|
64
|
+
const v = stringValue(el);
|
|
65
|
+
if (v !== null) names.add(v);
|
|
66
|
+
}
|
|
67
|
+
return names;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
function isPublicName(name) {
|
|
72
|
+
return !name.startsWith("_") || name.startsWith("__") && name.endsWith("__");
|
|
73
|
+
}
|
|
74
|
+
function moduleExported(ctx, name) {
|
|
75
|
+
return ctx.all ? ctx.all.has(name) : !name.startsWith("_");
|
|
76
|
+
}
|
|
77
|
+
function declareStatement(ctx, node) {
|
|
78
|
+
switch (node.type) {
|
|
79
|
+
case "import_statement":
|
|
80
|
+
case "import_from_statement":
|
|
81
|
+
declareImport(ctx, node);
|
|
82
|
+
return;
|
|
83
|
+
case "function_definition":
|
|
84
|
+
case "class_definition":
|
|
85
|
+
case "decorated_definition":
|
|
86
|
+
declareDefinition(ctx, node, "", false);
|
|
87
|
+
return;
|
|
88
|
+
case "type_alias_statement": {
|
|
89
|
+
const name = node.childForFieldName("left")?.text;
|
|
90
|
+
const value = node.childForFieldName("right");
|
|
91
|
+
if (name)
|
|
92
|
+
addSymbol(
|
|
93
|
+
ctx,
|
|
94
|
+
node,
|
|
95
|
+
name,
|
|
96
|
+
"",
|
|
97
|
+
"type",
|
|
98
|
+
moduleExported(ctx, name),
|
|
99
|
+
[pyText(value)],
|
|
100
|
+
value,
|
|
101
|
+
`type ${name}`
|
|
102
|
+
);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
case "expression_statement": {
|
|
106
|
+
const assign = node.namedChild(0);
|
|
107
|
+
if (assign?.type === "assignment") declareAssignment(ctx, node, assign);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function declareAssignment(ctx, stmt, assign) {
|
|
113
|
+
const left = assign.childForFieldName("left");
|
|
114
|
+
if (left?.type !== "identifier" || left.text === "__all__") return;
|
|
115
|
+
const name = left.text;
|
|
116
|
+
const type = assign.childForFieldName("type");
|
|
117
|
+
const right = assign.childForFieldName("right");
|
|
118
|
+
const isAlias = /\bTypeAlias$/.test(type?.text ?? "");
|
|
119
|
+
const kind = isAlias ? "type" : UPPER_CASE.test(name) ? "constant" : "variable";
|
|
120
|
+
const sig = isAlias ? [pyText(right)] : [pyText(type)];
|
|
121
|
+
addSymbol(
|
|
122
|
+
ctx,
|
|
123
|
+
stmt,
|
|
124
|
+
name,
|
|
125
|
+
"",
|
|
126
|
+
kind,
|
|
127
|
+
moduleExported(ctx, name),
|
|
128
|
+
sig,
|
|
129
|
+
right,
|
|
130
|
+
`${name}${type ? `: ${squash(type.text)}` : ""}`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function addSymbol(ctx, node, name, prefix, kind, exported, sigParts, body, signatureText, arity, bodySkip, accessor = false) {
|
|
134
|
+
const qualifiedName = prefix + name;
|
|
135
|
+
const previous = ctx.symbols.get(qualifiedName);
|
|
136
|
+
if (accessor && previous) {
|
|
137
|
+
previous.bodyHash = hashTokens([previous.bodyHash, ...body ? leafTokens(body, bodySkip, PY) : []]);
|
|
138
|
+
previous.range.endLine = Math.max(previous.range.endLine, endLineOf(node));
|
|
139
|
+
return previous;
|
|
140
|
+
}
|
|
141
|
+
const symbol = {
|
|
142
|
+
id: symbolIdOf("py", ctx.out.path, qualifiedName),
|
|
143
|
+
kind,
|
|
144
|
+
name,
|
|
145
|
+
qualifiedName,
|
|
146
|
+
file: ctx.out.path,
|
|
147
|
+
range: { startLine: lineOf(node), endLine: endLineOf(node) },
|
|
148
|
+
exported,
|
|
149
|
+
signatureHash: hashTokens([kind, ...sigParts]),
|
|
150
|
+
bodyHash: hashTokens(body ? leafTokens(body, bodySkip, PY) : []),
|
|
151
|
+
signatureText: signatureText.slice(0, 300)
|
|
152
|
+
};
|
|
153
|
+
if (arity) symbol.arity = arity;
|
|
154
|
+
ctx.symbols.delete(qualifiedName);
|
|
155
|
+
ctx.symbols.set(qualifiedName, symbol);
|
|
156
|
+
return symbol;
|
|
157
|
+
}
|
|
158
|
+
function docstringIds(block) {
|
|
159
|
+
const first = block?.namedChild(0);
|
|
160
|
+
if (first?.type === "expression_statement" && first.namedChild(0)?.type === "string")
|
|
161
|
+
return /* @__PURE__ */ new Set([first.id]);
|
|
162
|
+
return void 0;
|
|
163
|
+
}
|
|
164
|
+
function declareDefinition(ctx, node, prefix, inClass, classExported = true) {
|
|
165
|
+
let def = node;
|
|
166
|
+
const decorators = [];
|
|
167
|
+
if (node.type === "decorated_definition") {
|
|
168
|
+
for (const d of node.namedChildren)
|
|
169
|
+
if (d?.type === "decorator") decorators.push(squash(d.text.replace(/^@/, "")));
|
|
170
|
+
def = node.childForFieldName("definition") ?? node;
|
|
171
|
+
}
|
|
172
|
+
const name = def.childForFieldName("name")?.text;
|
|
173
|
+
if (!name) return;
|
|
174
|
+
const exported = inClass ? classExported && isPublicName(name) : moduleExported(ctx, name);
|
|
175
|
+
ctx.declNodes.set(def.id, prefix + name);
|
|
176
|
+
if (def.type === "function_definition") {
|
|
177
|
+
declareFunction(ctx, node, def, name, prefix, inClass, exported, decorators);
|
|
178
|
+
} else if (def.type === "class_definition") {
|
|
179
|
+
declareClass(ctx, node, def, name, prefix, exported, decorators);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function declareFunction(ctx, outer, def, name, prefix, inClass, exported, decorators) {
|
|
183
|
+
const params = def.childForFieldName("parameters");
|
|
184
|
+
const ret = def.childForFieldName("return_type");
|
|
185
|
+
const isAsync = def.children.some((c) => c?.type === "async");
|
|
186
|
+
const semantic = decorators.filter((d) => CALL_SEMANTICS_DECORATORS.test(d)).sort();
|
|
187
|
+
const isStatic = semantic.includes("staticmethod");
|
|
188
|
+
const { parts, arity } = paramSignature(params, inClass && !isStatic);
|
|
189
|
+
const body = def.childForFieldName("body");
|
|
190
|
+
const signatureText = `${isAsync ? "async " : ""}def ${name}${params ? squash(params.text) : "()"}${ret ? ` -> ${squash(ret.text)}` : ""}`;
|
|
191
|
+
addSymbol(
|
|
192
|
+
ctx,
|
|
193
|
+
outer,
|
|
194
|
+
name,
|
|
195
|
+
prefix,
|
|
196
|
+
inClass ? "method" : "function",
|
|
197
|
+
exported,
|
|
198
|
+
[isAsync ? "async" : "", ...semantic, ...parts, "->", pyText(ret)],
|
|
199
|
+
body,
|
|
200
|
+
signatureText,
|
|
201
|
+
arity,
|
|
202
|
+
docstringIds(body),
|
|
203
|
+
decorators.some((d) => d === `${name}.setter` || d === `${name}.deleter`)
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
function paramSignature(params, dropFirst) {
|
|
207
|
+
const parts = [];
|
|
208
|
+
let positional = 0;
|
|
209
|
+
let positionalMin = 0;
|
|
210
|
+
let keywordOnly = 0;
|
|
211
|
+
let keywordRequired = 0;
|
|
212
|
+
let afterStar = false;
|
|
213
|
+
let variadic = false;
|
|
214
|
+
let first = dropFirst;
|
|
215
|
+
let keywords = [];
|
|
216
|
+
const param = (required, name) => {
|
|
217
|
+
keywords?.push(name);
|
|
218
|
+
if (afterStar) {
|
|
219
|
+
keywordOnly++;
|
|
220
|
+
if (required) keywordRequired++;
|
|
221
|
+
} else {
|
|
222
|
+
positional++;
|
|
223
|
+
if (required) positionalMin = positional;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
for (const p of params?.namedChildren ?? []) {
|
|
227
|
+
if (!p || p.type === "comment") continue;
|
|
228
|
+
if (first && (p.type === "identifier" || p.type === "typed_parameter" || p.type === "default_parameter" || p.type === "typed_default_parameter")) {
|
|
229
|
+
first = false;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const inner = p.type === "typed_parameter" ? p.namedChild(0) : p;
|
|
233
|
+
const type = p.type === "typed_parameter" ? `:${pyText(p.childForFieldName("type"))}` : "";
|
|
234
|
+
switch (inner?.type) {
|
|
235
|
+
case "positional_separator":
|
|
236
|
+
parts.push("/");
|
|
237
|
+
if (keywords) keywords = [];
|
|
238
|
+
break;
|
|
239
|
+
case "keyword_separator":
|
|
240
|
+
parts.push("*");
|
|
241
|
+
afterStar = true;
|
|
242
|
+
break;
|
|
243
|
+
case "list_splat_pattern":
|
|
244
|
+
case "dictionary_splat_pattern":
|
|
245
|
+
parts.push(
|
|
246
|
+
`${inner.type === "list_splat_pattern" ? "*" : "**"}${inner.namedChild(0)?.text ?? ""}${type}`
|
|
247
|
+
);
|
|
248
|
+
variadic = true;
|
|
249
|
+
if (inner.type === "list_splat_pattern") afterStar = true;
|
|
250
|
+
else keywords = null;
|
|
251
|
+
break;
|
|
252
|
+
case "default_parameter":
|
|
253
|
+
case "typed_default_parameter":
|
|
254
|
+
parts.push(
|
|
255
|
+
`${inner.childForFieldName("name")?.text ?? ""}:${pyText(inner.childForFieldName("type"))}=`
|
|
256
|
+
);
|
|
257
|
+
param(false, inner.childForFieldName("name")?.text ?? "");
|
|
258
|
+
break;
|
|
259
|
+
case "identifier":
|
|
260
|
+
parts.push(`${inner.text}${type}`);
|
|
261
|
+
param(true, inner.text);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return {
|
|
266
|
+
parts,
|
|
267
|
+
arity: {
|
|
268
|
+
min: positionalMin + keywordRequired,
|
|
269
|
+
max: variadic ? null : positional + keywordOnly,
|
|
270
|
+
keywords
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function declareClass(ctx, outer, def, name, prefix, exported, decorators) {
|
|
275
|
+
const bases = def.childForFieldName("superclasses");
|
|
276
|
+
const body = def.childForFieldName("body");
|
|
277
|
+
const shape = [decorators.join(","), pyText(bases)];
|
|
278
|
+
const qualified = `${prefix}${name}.`;
|
|
279
|
+
const skip = new Set(docstringIds(body));
|
|
280
|
+
for (const member of body?.namedChildren ?? []) {
|
|
281
|
+
if (!member) continue;
|
|
282
|
+
if (member.type === "expression_statement") {
|
|
283
|
+
const assign = member.namedChild(0);
|
|
284
|
+
const field = assign?.type === "assignment" ? assign.childForFieldName("left") : null;
|
|
285
|
+
const type = assign?.childForFieldName("type");
|
|
286
|
+
if (field?.type === "identifier" && type) {
|
|
287
|
+
shape.push(`field:${field.text}:${pyText(type)}:${assign?.childForFieldName("right") ? "=" : ""}`);
|
|
288
|
+
}
|
|
289
|
+
} else if (member.type === "function_definition" || member.type === "decorated_definition" || member.type === "class_definition") {
|
|
290
|
+
skip.add(member.id);
|
|
291
|
+
declareDefinition(ctx, member, qualified, member.type !== "class_definition", exported);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const init = ctx.symbols.get(`${qualified}__init__`);
|
|
295
|
+
if (init) shape.push(`ctor:${init.signatureHash}`);
|
|
296
|
+
addSymbol(
|
|
297
|
+
ctx,
|
|
298
|
+
outer,
|
|
299
|
+
name,
|
|
300
|
+
prefix,
|
|
301
|
+
"class",
|
|
302
|
+
exported,
|
|
303
|
+
shape,
|
|
304
|
+
body,
|
|
305
|
+
`class ${name}${bases ? squash(bases.text) : ""}`,
|
|
306
|
+
init?.arity,
|
|
307
|
+
skip
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
function declareImport(ctx, node) {
|
|
311
|
+
const line = lineOf(node);
|
|
312
|
+
if (node.type === "import_statement") {
|
|
313
|
+
for (const n of node.namedChildren) {
|
|
314
|
+
if (!n) continue;
|
|
315
|
+
const aliased = n.type === "aliased_import";
|
|
316
|
+
const dotted = aliased ? n.childForFieldName("name") : n;
|
|
317
|
+
if (!dotted) continue;
|
|
318
|
+
const source = dotted.text;
|
|
319
|
+
const local = aliased ? n.childForFieldName("alias")?.text ?? source : source.split(".")[0];
|
|
320
|
+
ctx.out.imports.push({ source, line, names: [{ imported: "*", local }] });
|
|
321
|
+
ctx.importLocals.add(local);
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const moduleName = node.childForFieldName("module_name");
|
|
326
|
+
if (!moduleName) return;
|
|
327
|
+
const decl = { source: moduleName.text.replace(/\s+/g, ""), line, names: [] };
|
|
328
|
+
for (const n of node.namedChildren) {
|
|
329
|
+
if (!n || n.id === moduleName.id) continue;
|
|
330
|
+
if (n.type === "wildcard_import") decl.names.push({ imported: "*", local: "*" });
|
|
331
|
+
else if (n.type === "dotted_name") decl.names.push({ imported: n.text, local: n.text });
|
|
332
|
+
else if (n.type === "aliased_import") {
|
|
333
|
+
const imported = n.childForFieldName("name")?.text;
|
|
334
|
+
if (imported) decl.names.push({ imported, local: n.childForFieldName("alias")?.text ?? imported });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
for (const b of decl.names) if (b.local !== "*") ctx.importLocals.add(b.local);
|
|
338
|
+
ctx.out.imports.push(decl);
|
|
339
|
+
}
|
|
340
|
+
function calleeOf(node) {
|
|
341
|
+
if (!node) return null;
|
|
342
|
+
if (node.type === "identifier") return { name: node.text };
|
|
343
|
+
if (node.type === "attribute") {
|
|
344
|
+
const attr = node.childForFieldName("attribute");
|
|
345
|
+
const obj = node.childForFieldName("object");
|
|
346
|
+
if (!attr) return null;
|
|
347
|
+
return obj?.type === "identifier" ? { name: attr.text, qualifier: obj.text } : { name: attr.text };
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
function keywordNames(call) {
|
|
352
|
+
const args = call.childForFieldName("arguments");
|
|
353
|
+
return (args?.namedChildren ?? []).flatMap(
|
|
354
|
+
(a) => a?.type === "keyword_argument" ? [a.childForFieldName("name")?.text ?? ""] : []
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
function argCount(call) {
|
|
358
|
+
const args = call.childForFieldName("arguments");
|
|
359
|
+
if (!args) return void 0;
|
|
360
|
+
if (args.type === "generator_expression") return 1;
|
|
361
|
+
let n = 0;
|
|
362
|
+
for (const a of args.namedChildren) {
|
|
363
|
+
if (!a || a.type === "comment") continue;
|
|
364
|
+
if (a.type === "list_splat" || a.type === "dictionary_splat") return void 0;
|
|
365
|
+
n++;
|
|
366
|
+
}
|
|
367
|
+
return n;
|
|
368
|
+
}
|
|
369
|
+
function envRead(node) {
|
|
370
|
+
if (node.type === "subscript") {
|
|
371
|
+
const value = node.childForFieldName("value")?.text;
|
|
372
|
+
return value === "os.environ" || value === "environ" ? stringValue(node.childForFieldName("subscript")) : null;
|
|
373
|
+
}
|
|
374
|
+
const fn = node.childForFieldName("function")?.text;
|
|
375
|
+
if (fn === "os.environ.get" || fn === "environ.get" || fn === "os.getenv" || fn === "getenv") {
|
|
376
|
+
return stringValue(node.childForFieldName("arguments")?.namedChild(0));
|
|
377
|
+
}
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
function routesFromDecorator(ctx, decorator) {
|
|
381
|
+
const call = decorator.namedChild(0);
|
|
382
|
+
if (call?.type !== "call") return;
|
|
383
|
+
const callee = calleeOf(call.childForFieldName("function"));
|
|
384
|
+
if (!callee?.qualifier) return;
|
|
385
|
+
const args = call.childForFieldName("arguments");
|
|
386
|
+
const path = stringValue(args?.namedChild(0));
|
|
387
|
+
if (!path?.startsWith("/")) return;
|
|
388
|
+
const line = lineOf(decorator);
|
|
389
|
+
if (HTTP_METHODS.has(callee.name)) {
|
|
390
|
+
ctx.out.routes.push({ method: callee.name.toUpperCase(), path, line });
|
|
391
|
+
} else if (callee.name === "route" || callee.name === "api_route") {
|
|
392
|
+
const methodsArg = args?.namedChildren.find(
|
|
393
|
+
(a) => a?.type === "keyword_argument" && a.childForFieldName("name")?.text === "methods"
|
|
394
|
+
);
|
|
395
|
+
const list = methodsArg?.childForFieldName("value");
|
|
396
|
+
const methods = list ? list.namedChildren.map((m) => stringValue(m)).filter((m) => m !== null) : ["GET"];
|
|
397
|
+
for (const m of methods) ctx.out.routes.push({ method: m.toUpperCase(), path, line });
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
var REF_TYPES = /* @__PURE__ */ new Set([
|
|
401
|
+
"call",
|
|
402
|
+
"decorator",
|
|
403
|
+
"type",
|
|
404
|
+
"identifier",
|
|
405
|
+
"subscript",
|
|
406
|
+
"import_statement",
|
|
407
|
+
"import_from_statement"
|
|
408
|
+
]);
|
|
409
|
+
function collectRefs(ctx, root) {
|
|
410
|
+
const stack = [];
|
|
411
|
+
const fields = [];
|
|
412
|
+
const types = [];
|
|
413
|
+
let typeDepth = -1;
|
|
414
|
+
const cursor = root.walk();
|
|
415
|
+
const enclosing = () => stack.length ? stack[stack.length - 1].name : null;
|
|
416
|
+
const shadows = [];
|
|
417
|
+
const shadowed = (name) => shadows.some((sh) => sh.names.has(name));
|
|
418
|
+
const push2 = (r) => {
|
|
419
|
+
if (shadows.length) {
|
|
420
|
+
if (r.qualifier !== void 0 && shadowed(r.qualifier)) {
|
|
421
|
+
delete r.qualifier;
|
|
422
|
+
r.member = true;
|
|
423
|
+
} else if (r.qualifier === void 0 && !r.member && shadowed(r.name)) return;
|
|
424
|
+
}
|
|
425
|
+
ctx.out.refs.push(r);
|
|
426
|
+
};
|
|
427
|
+
try {
|
|
428
|
+
for (; ; ) {
|
|
429
|
+
const depth = cursor.currentDepth;
|
|
430
|
+
const type = cursor.nodeType;
|
|
431
|
+
types[depth] = type;
|
|
432
|
+
fields[depth] = cursor.currentFieldName;
|
|
433
|
+
if (typeDepth >= depth) typeDepth = -1;
|
|
434
|
+
while (stack.length && stack[stack.length - 1].depth >= depth) stack.pop();
|
|
435
|
+
while (shadows.length && shadows[shadows.length - 1].depth >= depth) shadows.pop();
|
|
436
|
+
const decl = ctx.declNodes.get(cursor.nodeId);
|
|
437
|
+
if (decl) stack.push({ depth, name: decl });
|
|
438
|
+
if (ctx.importLocals.size > 0 && (type === "function_definition" || type === "lambda")) {
|
|
439
|
+
const names = shadowedImports(ctx, cursor.currentNode);
|
|
440
|
+
if (names) shadows.push({ depth, names });
|
|
441
|
+
}
|
|
442
|
+
let descend = true;
|
|
443
|
+
const skipIdentifier = type === "identifier" && typeDepth < 0 && !ctx.importLocals.has(cursor.nodeText);
|
|
444
|
+
if (REF_TYPES.has(type) && !skipIdentifier) {
|
|
445
|
+
const node = cursor.currentNode;
|
|
446
|
+
const line = lineOf(node);
|
|
447
|
+
switch (type) {
|
|
448
|
+
case "import_statement":
|
|
449
|
+
case "import_from_statement":
|
|
450
|
+
descend = false;
|
|
451
|
+
break;
|
|
452
|
+
case "type":
|
|
453
|
+
if (typeDepth < 0) typeDepth = depth;
|
|
454
|
+
break;
|
|
455
|
+
case "decorator": {
|
|
456
|
+
routesFromDecorator(ctx, node);
|
|
457
|
+
const inner = node.namedChild(0);
|
|
458
|
+
const callee = calleeOf(inner?.type === "call" ? inner.childForFieldName("function") : inner);
|
|
459
|
+
if (callee) {
|
|
460
|
+
const r = { name: callee.name, kind: "decorator", line, enclosing: enclosing() };
|
|
461
|
+
if (callee.qualifier) r.qualifier = callee.qualifier;
|
|
462
|
+
push2(r);
|
|
463
|
+
}
|
|
464
|
+
if (inner?.type === "call") {
|
|
465
|
+
const args = inner.childForFieldName("arguments");
|
|
466
|
+
if (args) collectArgs(args, enclosing(), push2);
|
|
467
|
+
descend = false;
|
|
468
|
+
}
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
case "call": {
|
|
472
|
+
const env = envRead(node);
|
|
473
|
+
if (env) ctx.out.envReads.push({ name: env, line });
|
|
474
|
+
const callee = calleeOf(node.childForFieldName("function"));
|
|
475
|
+
if (callee) {
|
|
476
|
+
const r = { name: callee.name, kind: "call", line, enclosing: enclosing() };
|
|
477
|
+
if (callee.qualifier) r.qualifier = callee.qualifier;
|
|
478
|
+
const n = argCount(node);
|
|
479
|
+
if (n !== void 0) r.argCount = n;
|
|
480
|
+
const kw = keywordNames(node);
|
|
481
|
+
if (kw.length) r.keywords = kw;
|
|
482
|
+
push2(r);
|
|
483
|
+
}
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
case "subscript": {
|
|
487
|
+
const env = envRead(node);
|
|
488
|
+
if (env) {
|
|
489
|
+
ctx.out.envReads.push({ name: env, line });
|
|
490
|
+
descend = false;
|
|
491
|
+
}
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
case "identifier": {
|
|
495
|
+
const field = fields[depth];
|
|
496
|
+
const parent = types[depth - 1];
|
|
497
|
+
if (typeDepth >= 0 && typeDepth < depth && parent !== "attribute") {
|
|
498
|
+
push2({ name: node.text, kind: "type", line, enclosing: enclosing() });
|
|
499
|
+
} else if (ctx.importLocals.has(node.text) && field !== "function" && field !== "object" && field !== "name" && parent !== "attribute") {
|
|
500
|
+
push2({ name: node.text, kind: "identifier", line, enclosing: enclosing() });
|
|
501
|
+
}
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (descend && cursor.gotoFirstChild()) continue;
|
|
507
|
+
while (!cursor.gotoNextSibling()) {
|
|
508
|
+
if (!cursor.gotoParent()) return;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
} finally {
|
|
512
|
+
cursor.delete();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function shadowedImports(ctx, fn) {
|
|
516
|
+
let names = null;
|
|
517
|
+
const params = fn.childForFieldName("parameters");
|
|
518
|
+
const body = fn.childForFieldName("body");
|
|
519
|
+
const candidates = [
|
|
520
|
+
...(params?.namedChildren ?? []).map((p) => {
|
|
521
|
+
const inner = p?.type === "typed_parameter" ? p.namedChild(0) : p;
|
|
522
|
+
if (inner?.type === "identifier") return inner;
|
|
523
|
+
if (inner?.type === "list_splat_pattern" || inner?.type === "dictionary_splat_pattern")
|
|
524
|
+
return inner.namedChild(0);
|
|
525
|
+
return inner?.childForFieldName("name") ?? null;
|
|
526
|
+
}),
|
|
527
|
+
...(body?.descendantsOfType(["assignment", "for_statement", "with_item"]) ?? []).flatMap((n) => {
|
|
528
|
+
const target = n?.childForFieldName("left") ?? n?.childForFieldName("alias") ?? null;
|
|
529
|
+
return target?.type === "identifier" ? [target] : target?.descendantsOfType("identifier") ?? [];
|
|
530
|
+
})
|
|
531
|
+
];
|
|
532
|
+
for (const id of candidates) {
|
|
533
|
+
if (id && ctx.importLocals.has(id.text)) {
|
|
534
|
+
names ??= /* @__PURE__ */ new Set();
|
|
535
|
+
names.add(id.text);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return names;
|
|
539
|
+
}
|
|
540
|
+
function collectArgs(args, enclosing, push2) {
|
|
541
|
+
for (const call of args.descendantsOfType("call")) {
|
|
542
|
+
if (!call) continue;
|
|
543
|
+
const callee = calleeOf(call.childForFieldName("function"));
|
|
544
|
+
if (!callee) continue;
|
|
545
|
+
const r = { name: callee.name, kind: "call", line: lineOf(call), enclosing };
|
|
546
|
+
if (callee.qualifier) r.qualifier = callee.qualifier;
|
|
547
|
+
push2(r);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
|
|
552
|
+
function getLineColFromPtr(string, ptr) {
|
|
553
|
+
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
554
|
+
return [lines.length, lines.pop().length + 1];
|
|
555
|
+
}
|
|
556
|
+
function makeCodeBlock(string, line, column) {
|
|
557
|
+
let lines = string.split(/\r?\n/);
|
|
558
|
+
let codeblock = "";
|
|
559
|
+
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
560
|
+
for (let i = line - 1; i <= line + 1; i++) {
|
|
561
|
+
let l = lines[i - 1];
|
|
562
|
+
if (!l)
|
|
563
|
+
continue;
|
|
564
|
+
codeblock += i.toString().padEnd(numberLen, " ");
|
|
565
|
+
codeblock += ": ";
|
|
566
|
+
codeblock += l;
|
|
567
|
+
codeblock += "\n";
|
|
568
|
+
if (i === line) {
|
|
569
|
+
codeblock += " ".repeat(numberLen + column + 2);
|
|
570
|
+
codeblock += "^\n";
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return codeblock;
|
|
574
|
+
}
|
|
575
|
+
var TomlError = class _TomlError extends Error {
|
|
576
|
+
line;
|
|
577
|
+
column;
|
|
578
|
+
codeblock;
|
|
579
|
+
constructor(message, options) {
|
|
580
|
+
const [line, column] = getLineColFromPtr(options.toml, options.ptr);
|
|
581
|
+
const codeblock = makeCodeBlock(options.toml, line, column);
|
|
582
|
+
super(`Invalid TOML document: ${message}
|
|
583
|
+
|
|
584
|
+
${codeblock}`, options);
|
|
585
|
+
this.line = line;
|
|
586
|
+
this.column = column;
|
|
587
|
+
this.codeblock = codeblock;
|
|
588
|
+
}
|
|
589
|
+
/** @internal */
|
|
590
|
+
static x(message, ctx, ptr) {
|
|
591
|
+
throw new _TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/primitive.js
|
|
596
|
+
function parseString(ctx) {
|
|
597
|
+
let startPtr = ctx.p;
|
|
598
|
+
let c = ctx.s.charCodeAt(ctx.p++);
|
|
599
|
+
let first = c;
|
|
600
|
+
let isLiteral = c === 39;
|
|
601
|
+
let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
|
|
602
|
+
if (isMultiline) {
|
|
603
|
+
if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
|
|
604
|
+
ctx.p++;
|
|
605
|
+
else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
|
|
606
|
+
ctx.p += 2;
|
|
607
|
+
}
|
|
608
|
+
let parsed = "";
|
|
609
|
+
let sliceStart = ctx.p;
|
|
610
|
+
let state = 0;
|
|
611
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
612
|
+
c = ctx.s.charCodeAt(ctx.p);
|
|
613
|
+
if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
|
|
614
|
+
state = state && 3;
|
|
615
|
+
} else if (c < 32 && c !== 9 || c === 127) {
|
|
616
|
+
TomlError.x("control characters are not allowed in strings", ctx);
|
|
617
|
+
} else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
|
|
618
|
+
if (isMultiline) {
|
|
619
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
620
|
+
ctx.p++;
|
|
621
|
+
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
622
|
+
ctx.p++;
|
|
623
|
+
}
|
|
624
|
+
if (!state) {
|
|
625
|
+
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
626
|
+
parsed = parsed ? parsed + s : s;
|
|
627
|
+
}
|
|
628
|
+
ctx.p += isMultiline ? 3 : 1;
|
|
629
|
+
return parsed;
|
|
630
|
+
} else if (!state) {
|
|
631
|
+
if (!isLiteral && c === 92) {
|
|
632
|
+
parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
|
|
633
|
+
state = 1;
|
|
634
|
+
}
|
|
635
|
+
} else if (state === 1) {
|
|
636
|
+
if (c === 120 || c === 117 || c === 85) {
|
|
637
|
+
let errPtr = ctx.p++ - 1;
|
|
638
|
+
let value = 0;
|
|
639
|
+
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
640
|
+
for (let j = 0; j < len; j++, ctx.p++) {
|
|
641
|
+
let hex = ctx.s.charCodeAt(ctx.p);
|
|
642
|
+
let digit = (
|
|
643
|
+
/* 0-9 */
|
|
644
|
+
hex >= 48 && hex <= 57 ? hex - 48 : (
|
|
645
|
+
/* A-F */
|
|
646
|
+
hex >= 65 && hex <= 70 ? hex - 65 + 10 : (
|
|
647
|
+
/* a-f */
|
|
648
|
+
hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1
|
|
649
|
+
)
|
|
650
|
+
)
|
|
651
|
+
);
|
|
652
|
+
if (digit < 0)
|
|
653
|
+
TomlError.x("invalid non-hex character in unicode escape", ctx);
|
|
654
|
+
value = value << 4 | digit;
|
|
655
|
+
}
|
|
656
|
+
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
|
|
657
|
+
TomlError.x("invalid unicode escape", ctx, errPtr);
|
|
658
|
+
}
|
|
659
|
+
parsed += String.fromCodePoint(value);
|
|
660
|
+
sliceStart = ctx.p--;
|
|
661
|
+
state = 0;
|
|
662
|
+
} else if (isMultiline && (c === 32 || c === 9)) {
|
|
663
|
+
state = 2;
|
|
664
|
+
} else {
|
|
665
|
+
if (c === 98)
|
|
666
|
+
parsed += "\b";
|
|
667
|
+
else if (c === 116)
|
|
668
|
+
parsed += " ";
|
|
669
|
+
else if (c === 110)
|
|
670
|
+
parsed += "\n";
|
|
671
|
+
else if (c === 102)
|
|
672
|
+
parsed += "\f";
|
|
673
|
+
else if (c === 114)
|
|
674
|
+
parsed += "\r";
|
|
675
|
+
else if (c === 101)
|
|
676
|
+
parsed += "\x1B";
|
|
677
|
+
else if (c === 34)
|
|
678
|
+
parsed += '"';
|
|
679
|
+
else if (c === 92)
|
|
680
|
+
parsed += "\\";
|
|
681
|
+
else
|
|
682
|
+
TomlError.x("unrecognised escape sequence", ctx);
|
|
683
|
+
sliceStart = ctx.p + 1;
|
|
684
|
+
state = 0;
|
|
685
|
+
}
|
|
686
|
+
} else if (c !== 32 && c !== 9) {
|
|
687
|
+
if (state === 2)
|
|
688
|
+
TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
|
|
689
|
+
state = !isLiteral && c === 92 ? 1 : 0;
|
|
690
|
+
sliceStart = ctx.p;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
TomlError.x("unfinished string", ctx, startPtr);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/date.js
|
|
697
|
+
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
698
|
+
var TomlDate = class _TomlDate extends Date {
|
|
699
|
+
#hasDate = false;
|
|
700
|
+
#hasTime = false;
|
|
701
|
+
#offset = null;
|
|
702
|
+
constructor(date, fasttype, unsafeDelim) {
|
|
703
|
+
let hasDate = true;
|
|
704
|
+
let hasTime = true;
|
|
705
|
+
let offset = "Z";
|
|
706
|
+
let c;
|
|
707
|
+
if (typeof date === "string") {
|
|
708
|
+
if (fasttype)
|
|
709
|
+
prep: {
|
|
710
|
+
if (fasttype < 3) {
|
|
711
|
+
if (+date.slice(11, 13) > 23) {
|
|
712
|
+
date = "";
|
|
713
|
+
break prep;
|
|
714
|
+
}
|
|
715
|
+
if (fasttype === 2) {
|
|
716
|
+
offset = null;
|
|
717
|
+
date += "Z";
|
|
718
|
+
} else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) {
|
|
719
|
+
offset = date.slice(date.length - 6);
|
|
720
|
+
}
|
|
721
|
+
if (unsafeDelim)
|
|
722
|
+
date = date.slice(0, 10) + "T" + date.slice(11);
|
|
723
|
+
} else if (fasttype === 4) {
|
|
724
|
+
date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
|
|
725
|
+
}
|
|
726
|
+
hasDate = fasttype !== 4;
|
|
727
|
+
hasTime = fasttype !== 3;
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
let match = date.match(DATE_TIME_RE);
|
|
731
|
+
if (match) {
|
|
732
|
+
if (!match[1]) {
|
|
733
|
+
hasDate = false;
|
|
734
|
+
date = `0000-01-01T${date}`;
|
|
735
|
+
}
|
|
736
|
+
hasTime = !!match[2];
|
|
737
|
+
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
738
|
+
if (match[2] && +match[2] > 23) {
|
|
739
|
+
date = "";
|
|
740
|
+
} else {
|
|
741
|
+
offset = match[3] || null;
|
|
742
|
+
if (!offset && hasTime)
|
|
743
|
+
date += "Z";
|
|
744
|
+
}
|
|
745
|
+
} else {
|
|
746
|
+
date = "";
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
super(date);
|
|
751
|
+
if (!isNaN(this.getTime())) {
|
|
752
|
+
this.#hasDate = hasDate;
|
|
753
|
+
this.#hasTime = hasTime;
|
|
754
|
+
this.#offset = offset;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
isDateTime() {
|
|
758
|
+
return this.#hasDate && this.#hasTime;
|
|
759
|
+
}
|
|
760
|
+
isLocal() {
|
|
761
|
+
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
762
|
+
}
|
|
763
|
+
isDate() {
|
|
764
|
+
return this.#hasDate && !this.#hasTime;
|
|
765
|
+
}
|
|
766
|
+
isTime() {
|
|
767
|
+
return this.#hasTime && !this.#hasDate;
|
|
768
|
+
}
|
|
769
|
+
isValid() {
|
|
770
|
+
return this.#hasDate || this.#hasTime;
|
|
771
|
+
}
|
|
772
|
+
toISOString() {
|
|
773
|
+
let iso = super.toISOString();
|
|
774
|
+
if (this.isDate())
|
|
775
|
+
return iso.slice(0, 10);
|
|
776
|
+
if (this.isTime())
|
|
777
|
+
return iso.slice(11, 23);
|
|
778
|
+
if (this.#offset === null)
|
|
779
|
+
return iso.slice(0, -1);
|
|
780
|
+
if (this.#offset === "Z" || this.#offset === "z")
|
|
781
|
+
return iso;
|
|
782
|
+
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
783
|
+
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
784
|
+
let offsetDate = new Date(this.getTime() - offset * 6e4);
|
|
785
|
+
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
786
|
+
}
|
|
787
|
+
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
788
|
+
let date = new _TomlDate(jsDate);
|
|
789
|
+
date.#offset = offset;
|
|
790
|
+
return date;
|
|
791
|
+
}
|
|
792
|
+
static wrapAsLocalDateTime(jsDate) {
|
|
793
|
+
let date = new _TomlDate(jsDate);
|
|
794
|
+
date.#offset = null;
|
|
795
|
+
return date;
|
|
796
|
+
}
|
|
797
|
+
static wrapAsLocalDate(jsDate) {
|
|
798
|
+
let date = new _TomlDate(jsDate);
|
|
799
|
+
date.#hasTime = false;
|
|
800
|
+
date.#offset = null;
|
|
801
|
+
return date;
|
|
802
|
+
}
|
|
803
|
+
static wrapAsLocalTime(jsDate) {
|
|
804
|
+
let date = new _TomlDate(jsDate);
|
|
805
|
+
date.#hasDate = false;
|
|
806
|
+
date.#offset = null;
|
|
807
|
+
return date;
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/extract.js
|
|
812
|
+
function isDigit(char, base = 10) {
|
|
813
|
+
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
814
|
+
}
|
|
815
|
+
function isEndOfValue(char, delim) {
|
|
816
|
+
return char === 32 || char === 9 || char === 10 || char === 13 || // Structure end or next value delimiter
|
|
817
|
+
delim && (char === delim || char === 44) || // Comment
|
|
818
|
+
char === 35;
|
|
819
|
+
}
|
|
820
|
+
function extractValue(ctx, end) {
|
|
821
|
+
let errPtr = ctx.p;
|
|
822
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
823
|
+
if (c === 91 || c === 123) {
|
|
824
|
+
ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
|
|
825
|
+
let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
|
|
826
|
+
ctx.d++;
|
|
827
|
+
return value;
|
|
828
|
+
}
|
|
829
|
+
if (c === 34 || c === 39) {
|
|
830
|
+
return parseString(ctx);
|
|
831
|
+
}
|
|
832
|
+
if (c === 116) {
|
|
833
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
834
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
835
|
+
return ctx.p++, true;
|
|
836
|
+
}
|
|
837
|
+
if (c === 102) {
|
|
838
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
839
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
840
|
+
return ctx.p++, false;
|
|
841
|
+
}
|
|
842
|
+
if (c === 43 || c === 45) {
|
|
843
|
+
return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
|
|
844
|
+
}
|
|
845
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) {
|
|
846
|
+
return parseDate(ctx, c, end);
|
|
847
|
+
}
|
|
848
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 58) {
|
|
849
|
+
return parseTime(ctx, c, end);
|
|
850
|
+
}
|
|
851
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
852
|
+
}
|
|
853
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
854
|
+
let c = startChr;
|
|
855
|
+
let state = 0;
|
|
856
|
+
let hasUnderscores = false;
|
|
857
|
+
if (c === 105) {
|
|
858
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102)
|
|
859
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
860
|
+
return ctx.p++, (sign || 1) / 0;
|
|
861
|
+
}
|
|
862
|
+
if (c === 110) {
|
|
863
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110)
|
|
864
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
865
|
+
return ctx.p++, NaN;
|
|
866
|
+
}
|
|
867
|
+
if (c === 48) {
|
|
868
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
|
|
869
|
+
return ctx.bi === true ? 0n : 0;
|
|
870
|
+
if (!sign) {
|
|
871
|
+
if (c === 120)
|
|
872
|
+
return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
873
|
+
else if (c === 98)
|
|
874
|
+
return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
875
|
+
else if (c === 111)
|
|
876
|
+
return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
877
|
+
}
|
|
878
|
+
if (c === 46)
|
|
879
|
+
state = 2;
|
|
880
|
+
else if (c === 101 || c === 69)
|
|
881
|
+
state = 4;
|
|
882
|
+
else
|
|
883
|
+
TomlError.x("illegal leading zero", ctx, startPtr);
|
|
884
|
+
} else if (!isDigit(c))
|
|
885
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
886
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
887
|
+
if (!state)
|
|
888
|
+
state = 1;
|
|
889
|
+
if (c === 95) {
|
|
890
|
+
if (!(state & 1))
|
|
891
|
+
TomlError.x("illegal underscore", ctx);
|
|
892
|
+
state += 11;
|
|
893
|
+
hasUnderscores = true;
|
|
894
|
+
} else if (state === 1 && c === 46)
|
|
895
|
+
state = 2;
|
|
896
|
+
else if ((state === 1 || state === 3) && (c === 101 || c === 69))
|
|
897
|
+
state = 4;
|
|
898
|
+
else if (state === 4 && (c === 43 || c === 45)) {
|
|
899
|
+
state = 6;
|
|
900
|
+
} else if (!isDigit(c))
|
|
901
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
902
|
+
else if (state > 9)
|
|
903
|
+
state -= 11;
|
|
904
|
+
else if (!(state & 1))
|
|
905
|
+
state++;
|
|
906
|
+
}
|
|
907
|
+
if (!state) {
|
|
908
|
+
let val = (startChr - 48) * (sign || 1);
|
|
909
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
910
|
+
}
|
|
911
|
+
if (!(state & 1))
|
|
912
|
+
TomlError.x("unfinished numeric value", ctx, startPtr);
|
|
913
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
914
|
+
if (hasUnderscores)
|
|
915
|
+
str = str.replaceAll("_", "");
|
|
916
|
+
return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
|
|
917
|
+
}
|
|
918
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
919
|
+
let c, underscore = 1;
|
|
920
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
921
|
+
if (c === 95) {
|
|
922
|
+
if (underscore & 1)
|
|
923
|
+
TomlError.x("illegal underscore", ctx);
|
|
924
|
+
underscore = 3;
|
|
925
|
+
} else if (!isDigit(c, base))
|
|
926
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
927
|
+
else if (underscore & 1)
|
|
928
|
+
underscore--;
|
|
929
|
+
}
|
|
930
|
+
if (underscore & 1)
|
|
931
|
+
TomlError.x("unfinished numeric value", ctx);
|
|
932
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
933
|
+
if (underscore)
|
|
934
|
+
str = str.replaceAll("_", "");
|
|
935
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
936
|
+
}
|
|
937
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
938
|
+
if (ctx.bi !== true)
|
|
939
|
+
int: {
|
|
940
|
+
let val = parseInt(str, base);
|
|
941
|
+
if (!Number.isSafeInteger(val)) {
|
|
942
|
+
if (ctx.bi)
|
|
943
|
+
break int;
|
|
944
|
+
TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
|
|
945
|
+
}
|
|
946
|
+
return val;
|
|
947
|
+
}
|
|
948
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
|
|
949
|
+
}
|
|
950
|
+
function parseDate(ctx, c, endChr) {
|
|
951
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
952
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) {
|
|
953
|
+
return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
954
|
+
}
|
|
955
|
+
ctx.p += 5;
|
|
956
|
+
if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
|
|
957
|
+
TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
958
|
+
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
|
|
959
|
+
let t2 = ctx.s.slice(startPtr, ctx.p);
|
|
960
|
+
return readDate(ctx, t2, 3, false, startPtr);
|
|
961
|
+
}
|
|
962
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
|
|
963
|
+
TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
964
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 58)
|
|
965
|
+
ctx.p += 3;
|
|
966
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
967
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
968
|
+
;
|
|
969
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
970
|
+
if (c === 90 || c === 122) {
|
|
971
|
+
let t2 = ctx.s.slice(startPtr, ++ctx.p);
|
|
972
|
+
return readDate(ctx, t2, 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
973
|
+
}
|
|
974
|
+
if (c === 43 || c === 45) {
|
|
975
|
+
let t2 = ctx.s.slice(startPtr, ctx.p += 6);
|
|
976
|
+
return readDate(ctx, t2, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
980
|
+
return readDate(ctx, t, 2, unsafeSeparator, startPtr);
|
|
981
|
+
}
|
|
982
|
+
function parseTime(ctx, c, endChr) {
|
|
983
|
+
let start = ctx.p;
|
|
984
|
+
if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
|
|
985
|
+
return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
986
|
+
}
|
|
987
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 58)
|
|
988
|
+
ctx.p += 3;
|
|
989
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
990
|
+
while (isDigit(ctx.s.charCodeAt(++ctx.p)))
|
|
991
|
+
;
|
|
992
|
+
let t = ctx.s.slice(start, ctx.p);
|
|
993
|
+
return readDate(ctx, t, 4, false, start);
|
|
994
|
+
}
|
|
995
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
996
|
+
if (ctx.ld) {
|
|
997
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
998
|
+
if (!date.isValid())
|
|
999
|
+
TomlError.x("invalid date", ctx, errPtr);
|
|
1000
|
+
return date;
|
|
1001
|
+
}
|
|
1002
|
+
try {
|
|
1003
|
+
if (temporalSuffix)
|
|
1004
|
+
str += temporalSuffix;
|
|
1005
|
+
switch (type) {
|
|
1006
|
+
case 1:
|
|
1007
|
+
return Temporal.ZonedDateTime.from(str);
|
|
1008
|
+
case 2:
|
|
1009
|
+
return Temporal.PlainDateTime.from(str);
|
|
1010
|
+
case 3:
|
|
1011
|
+
return Temporal.PlainDate.from(str);
|
|
1012
|
+
case 4:
|
|
1013
|
+
return Temporal.PlainTime.from(str);
|
|
1014
|
+
}
|
|
1015
|
+
} catch (e) {
|
|
1016
|
+
TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/util.js
|
|
1021
|
+
function skipComment(ctx) {
|
|
1022
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
1023
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
1024
|
+
if (c === 10)
|
|
1025
|
+
break;
|
|
1026
|
+
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
1027
|
+
ctx.p++;
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
1030
|
+
if (c < 32 && c !== 9 || c === 127) {
|
|
1031
|
+
TomlError.x("control characters are not allowed in comments", ctx);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
function skipVoid(ctx, banNewLines, banComments) {
|
|
1036
|
+
let c;
|
|
1037
|
+
while (ctx.p < ctx.s.length) {
|
|
1038
|
+
while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)))
|
|
1039
|
+
ctx.p++;
|
|
1040
|
+
if (banComments || c !== 35)
|
|
1041
|
+
break;
|
|
1042
|
+
skipComment(ctx);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/struct.js
|
|
1047
|
+
function parseKey(ctx, end = 61) {
|
|
1048
|
+
let startPtr;
|
|
1049
|
+
let state = 0;
|
|
1050
|
+
let parsed = [];
|
|
1051
|
+
let sliceStart;
|
|
1052
|
+
let c = ctx.s.charCodeAt(startPtr = ctx.p);
|
|
1053
|
+
do {
|
|
1054
|
+
if (c === end) {
|
|
1055
|
+
if (!state)
|
|
1056
|
+
TomlError.x("unexpected end of key", ctx);
|
|
1057
|
+
if (state === 1)
|
|
1058
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1059
|
+
return ctx.p++, parsed;
|
|
1060
|
+
} else if (c === 46) {
|
|
1061
|
+
if (!state)
|
|
1062
|
+
TomlError.x("illegal empty bare key", ctx);
|
|
1063
|
+
if (state === 1)
|
|
1064
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1065
|
+
state = 0;
|
|
1066
|
+
} else if (!state && (c === 34 || c === 39)) {
|
|
1067
|
+
if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
|
|
1068
|
+
TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
|
|
1069
|
+
parsed.push(parseString(ctx));
|
|
1070
|
+
state = 2;
|
|
1071
|
+
ctx.p--;
|
|
1072
|
+
} else if (c === 32 || c === 9) {
|
|
1073
|
+
if (state === 1) {
|
|
1074
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1075
|
+
state = 2;
|
|
1076
|
+
}
|
|
1077
|
+
} else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) {
|
|
1078
|
+
TomlError.x("illegal character in key", ctx);
|
|
1079
|
+
} else if (!state) {
|
|
1080
|
+
state = 1;
|
|
1081
|
+
sliceStart = ctx.p;
|
|
1082
|
+
}
|
|
1083
|
+
} while (c = ctx.s.charCodeAt(++ctx.p));
|
|
1084
|
+
TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
|
|
1085
|
+
}
|
|
1086
|
+
function parseInlineTable(ctx) {
|
|
1087
|
+
let startPtr = ctx.p++;
|
|
1088
|
+
let res = /* @__PURE__ */ Object.create(null);
|
|
1089
|
+
let seen = /* @__PURE__ */ new Set();
|
|
1090
|
+
let c;
|
|
1091
|
+
while (ctx.p < ctx.s.length) {
|
|
1092
|
+
skipVoid(ctx);
|
|
1093
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
|
|
1094
|
+
ctx.p++;
|
|
1095
|
+
return res;
|
|
1096
|
+
}
|
|
1097
|
+
let k;
|
|
1098
|
+
let t = res;
|
|
1099
|
+
let hasOwn = false;
|
|
1100
|
+
let errPtr = ctx.p;
|
|
1101
|
+
let key = parseKey(ctx);
|
|
1102
|
+
for (let i = 0; i < key.length; i++) {
|
|
1103
|
+
if (i)
|
|
1104
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1105
|
+
k = key[i];
|
|
1106
|
+
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
|
|
1107
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
1108
|
+
}
|
|
1109
|
+
let unsafe = k === "__proto__";
|
|
1110
|
+
if (ctx.uk && (unsafe || k === "constructor")) {
|
|
1111
|
+
t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
|
|
1112
|
+
break;
|
|
1113
|
+
}
|
|
1114
|
+
if (!hasOwn && unsafe) {
|
|
1115
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
if (hasOwn) {
|
|
1119
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
1120
|
+
}
|
|
1121
|
+
skipVoid(ctx, true, true);
|
|
1122
|
+
let value = extractValue(
|
|
1123
|
+
ctx,
|
|
1124
|
+
125
|
|
1125
|
+
/* } */
|
|
1126
|
+
);
|
|
1127
|
+
if (t && typeof (t[k] = value) === "object")
|
|
1128
|
+
seen.add(value);
|
|
1129
|
+
skipVoid(ctx);
|
|
1130
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
|
|
1131
|
+
return res;
|
|
1132
|
+
}
|
|
1133
|
+
if (c !== 44)
|
|
1134
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
1135
|
+
}
|
|
1136
|
+
TomlError.x("unfinished table", ctx, startPtr);
|
|
1137
|
+
}
|
|
1138
|
+
function parseArray(ctx) {
|
|
1139
|
+
let startPtr = ctx.p++;
|
|
1140
|
+
let res = [];
|
|
1141
|
+
let c;
|
|
1142
|
+
while (ctx.p < ctx.s.length) {
|
|
1143
|
+
skipVoid(ctx);
|
|
1144
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
|
|
1145
|
+
ctx.p++;
|
|
1146
|
+
return res;
|
|
1147
|
+
}
|
|
1148
|
+
res.push(extractValue(
|
|
1149
|
+
ctx,
|
|
1150
|
+
93
|
|
1151
|
+
/* ] */
|
|
1152
|
+
));
|
|
1153
|
+
skipVoid(ctx);
|
|
1154
|
+
if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
|
|
1155
|
+
return res;
|
|
1156
|
+
}
|
|
1157
|
+
if (c !== 44)
|
|
1158
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
1159
|
+
}
|
|
1160
|
+
TomlError.x("unfinished array", ctx, startPtr);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/parse.js
|
|
1164
|
+
function peekTable(ctx, key, table, meta, type) {
|
|
1165
|
+
let t = table;
|
|
1166
|
+
let m = meta;
|
|
1167
|
+
let k;
|
|
1168
|
+
let hasOwn = false;
|
|
1169
|
+
let state;
|
|
1170
|
+
for (let i = 0; i < key.length; i++) {
|
|
1171
|
+
if (i) {
|
|
1172
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1173
|
+
m = (state = m[k]).c;
|
|
1174
|
+
if (type === 0 && (state.t === 1 || state.t === 2)) {
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1177
|
+
if (state.t === 2) {
|
|
1178
|
+
let l = t.length - 1;
|
|
1179
|
+
t = t[l];
|
|
1180
|
+
m = m[l].c;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
k = key[i];
|
|
1184
|
+
if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
|
|
1185
|
+
return null;
|
|
1186
|
+
}
|
|
1187
|
+
if (!hasOwn) {
|
|
1188
|
+
let unsafe = k === "__proto__";
|
|
1189
|
+
if (ctx.uk && (unsafe || k === "constructor"))
|
|
1190
|
+
return false;
|
|
1191
|
+
if (unsafe) {
|
|
1192
|
+
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
1193
|
+
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
1194
|
+
}
|
|
1195
|
+
m[k] = {
|
|
1196
|
+
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
1197
|
+
d: false,
|
|
1198
|
+
i: 0,
|
|
1199
|
+
c: /* @__PURE__ */ Object.create(null)
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
state = m[k];
|
|
1204
|
+
if (state.t !== type && !(type === 1 && state.t === 3)) {
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
1207
|
+
if (type === 2) {
|
|
1208
|
+
if (!state.d) {
|
|
1209
|
+
state.d = true;
|
|
1210
|
+
t[k] = [];
|
|
1211
|
+
}
|
|
1212
|
+
t[k].push(t = /* @__PURE__ */ Object.create(null));
|
|
1213
|
+
state.c[state.i++] = state = { t: 1, d: false, i: 0, c: /* @__PURE__ */ Object.create(null) };
|
|
1214
|
+
}
|
|
1215
|
+
if (state.d) {
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
state.d = true;
|
|
1219
|
+
if (type === 1) {
|
|
1220
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1221
|
+
} else if (type === 0 && hasOwn) {
|
|
1222
|
+
return null;
|
|
1223
|
+
}
|
|
1224
|
+
return [k, t, state.c];
|
|
1225
|
+
}
|
|
1226
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
1227
|
+
if (peek === null || ctx.uk === 2)
|
|
1228
|
+
TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
|
|
1229
|
+
}
|
|
1230
|
+
function parse(toml, options = {}) {
|
|
1231
|
+
let ctx = {
|
|
1232
|
+
s: toml,
|
|
1233
|
+
p: 0,
|
|
1234
|
+
d: options.maxDepth ?? 1e3,
|
|
1235
|
+
bi: options.integersAsBigInt ?? false,
|
|
1236
|
+
ld: options.useLegacyDate ?? true,
|
|
1237
|
+
uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
|
|
1238
|
+
};
|
|
1239
|
+
let res = /* @__PURE__ */ Object.create(null);
|
|
1240
|
+
let meta = /* @__PURE__ */ Object.create(null);
|
|
1241
|
+
let tmp;
|
|
1242
|
+
let skipping = false;
|
|
1243
|
+
let tbl = res;
|
|
1244
|
+
let m = meta;
|
|
1245
|
+
if (toml.charCodeAt(0) === 65279)
|
|
1246
|
+
ctx.p++;
|
|
1247
|
+
skipVoid(ctx);
|
|
1248
|
+
while (ctx.p < toml.length) {
|
|
1249
|
+
if (toml.charCodeAt(ctx.p) === 91) {
|
|
1250
|
+
let isTableArray = toml.charCodeAt(++ctx.p) === 91;
|
|
1251
|
+
tmp = ctx.p += +isTableArray;
|
|
1252
|
+
skipping = false;
|
|
1253
|
+
let k = parseKey(
|
|
1254
|
+
ctx,
|
|
1255
|
+
93
|
|
1256
|
+
/* ] */
|
|
1257
|
+
);
|
|
1258
|
+
if (isTableArray) {
|
|
1259
|
+
if (toml.charCodeAt(ctx.p) !== 93) {
|
|
1260
|
+
TomlError.x("expected end of table array declaration", ctx);
|
|
1261
|
+
}
|
|
1262
|
+
ctx.p++;
|
|
1263
|
+
}
|
|
1264
|
+
let p = peekTable(
|
|
1265
|
+
ctx,
|
|
1266
|
+
k,
|
|
1267
|
+
res,
|
|
1268
|
+
meta,
|
|
1269
|
+
isTableArray ? 2 : 1
|
|
1270
|
+
/* Type.EXPLICIT */
|
|
1271
|
+
);
|
|
1272
|
+
if (!p) {
|
|
1273
|
+
validateTablePeek(ctx, p, tmp);
|
|
1274
|
+
skipping = true;
|
|
1275
|
+
} else {
|
|
1276
|
+
m = p[2];
|
|
1277
|
+
tbl = p[1];
|
|
1278
|
+
}
|
|
1279
|
+
} else {
|
|
1280
|
+
tmp = ctx.p;
|
|
1281
|
+
let k = parseKey(ctx);
|
|
1282
|
+
let p = peekTable(
|
|
1283
|
+
ctx,
|
|
1284
|
+
k,
|
|
1285
|
+
tbl,
|
|
1286
|
+
m,
|
|
1287
|
+
0
|
|
1288
|
+
/* Type.DOTTED */
|
|
1289
|
+
);
|
|
1290
|
+
if (!p && !skipping)
|
|
1291
|
+
validateTablePeek(ctx, p, tmp);
|
|
1292
|
+
skipVoid(ctx, true, true);
|
|
1293
|
+
let v = extractValue(ctx, void 0);
|
|
1294
|
+
if (p && !skipping)
|
|
1295
|
+
p[1][p[0]] = v;
|
|
1296
|
+
}
|
|
1297
|
+
skipVoid(ctx, true);
|
|
1298
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) {
|
|
1299
|
+
TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
|
|
1300
|
+
}
|
|
1301
|
+
skipVoid(ctx);
|
|
1302
|
+
}
|
|
1303
|
+
return res;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/stringify.js
|
|
1307
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
1308
|
+
|
|
1309
|
+
// ../analysis/src/parse/special.ts
|
|
1310
|
+
var LOCKFILES = /* @__PURE__ */ new Set([
|
|
1311
|
+
"package-lock.json",
|
|
1312
|
+
"pnpm-lock.yaml",
|
|
1313
|
+
"yarn.lock",
|
|
1314
|
+
"bun.lockb",
|
|
1315
|
+
"bun.lock",
|
|
1316
|
+
"poetry.lock",
|
|
1317
|
+
"uv.lock",
|
|
1318
|
+
"Pipfile.lock",
|
|
1319
|
+
"Cargo.lock",
|
|
1320
|
+
"go.sum",
|
|
1321
|
+
"Gemfile.lock",
|
|
1322
|
+
"composer.lock"
|
|
1323
|
+
]);
|
|
1324
|
+
var ENV_TEMPLATES = /* @__PURE__ */ new Set([".env.example", ".env.sample", ".env.template", ".env.defaults"]);
|
|
1325
|
+
var MIGRATION_EXT = /\.(sql|py|rb|ts|js)$/;
|
|
1326
|
+
var REQUIREMENTS = /^requirements[^/]*\.txt$/;
|
|
1327
|
+
function basename(path) {
|
|
1328
|
+
return path.slice(path.lastIndexOf("/") + 1);
|
|
1329
|
+
}
|
|
1330
|
+
function dirname(path) {
|
|
1331
|
+
const i = path.lastIndexOf("/");
|
|
1332
|
+
return i === -1 ? "" : path.slice(0, i);
|
|
1333
|
+
}
|
|
1334
|
+
function isRecord(value) {
|
|
1335
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1336
|
+
}
|
|
1337
|
+
function isMigrationPath(path) {
|
|
1338
|
+
if (!MIGRATION_EXT.test(path)) return false;
|
|
1339
|
+
const dirs = path.split("/").slice(0, -1);
|
|
1340
|
+
return dirs.some(
|
|
1341
|
+
(d, i) => d === "migrations" || d === "migrate" || d === "versions" && dirs[i - 1] === "alembic"
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
function isManifest(name) {
|
|
1345
|
+
return name === "package.json" || name === "pyproject.toml" || name === "go.mod" || name === "Cargo.toml" || REQUIREMENTS.test(name);
|
|
1346
|
+
}
|
|
1347
|
+
function isSpecialPath(path) {
|
|
1348
|
+
const name = basename(path);
|
|
1349
|
+
return LOCKFILES.has(name) || ENV_TEMPLATES.has(name) || isManifest(name) || isMigrationPath(path) || nextRoute(path) !== null;
|
|
1350
|
+
}
|
|
1351
|
+
function extractSpecial(path, content) {
|
|
1352
|
+
const facts = [];
|
|
1353
|
+
const routes = [];
|
|
1354
|
+
const name = basename(path);
|
|
1355
|
+
if (LOCKFILES.has(name)) facts.push({ kind: "lockfile", file: path });
|
|
1356
|
+
else if (ENV_TEMPLATES.has(name)) facts.push(...envFacts(path, content));
|
|
1357
|
+
else if (isManifest(name)) facts.push(...manifestFacts(path, name, content));
|
|
1358
|
+
if (isMigrationPath(path)) {
|
|
1359
|
+
const migration = migrationFact(path, content);
|
|
1360
|
+
if (migration) facts.push(migration);
|
|
1361
|
+
}
|
|
1362
|
+
const route = nextRoute(path);
|
|
1363
|
+
if (route && !route.methodFromExports) routes.push({ method: "ANY", path: route.path, line: 1 });
|
|
1364
|
+
return { facts, routes };
|
|
1365
|
+
}
|
|
1366
|
+
var IDENT = String.raw`((?:[\`"\[]?[\w$]+[\`"\]]?\s*\.\s*)*[\`"\[]?[\w$]+[\`"\]]?)`;
|
|
1367
|
+
var TABLE_PATTERNS = [
|
|
1368
|
+
new RegExp(
|
|
1369
|
+
String.raw`\bCREATE\s+(?:(?:GLOBAL|LOCAL)\s+)?(?:(?:TEMP|TEMPORARY|UNLOGGED)\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?${IDENT}`,
|
|
1370
|
+
"gi"
|
|
1371
|
+
),
|
|
1372
|
+
new RegExp(String.raw`\bALTER\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:ONLY\s+)?${IDENT}`, "gi"),
|
|
1373
|
+
new RegExp(String.raw`\bDROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?${IDENT}`, "gi"),
|
|
1374
|
+
new RegExp(String.raw`\bCREATE\s+(?:UNIQUE\s+)?INDEX\b[^;]{0,300}?\bON\s+(?:ONLY\s+)?${IDENT}`, "gi"),
|
|
1375
|
+
// Rails (`create_table :users`) and Alembic (`op.create_table('users'`): first argument is the table.
|
|
1376
|
+
/\b(?:create_table|change_table|drop_table|add_column|remove_column|rename_column|change_column|add_index|remove_index|add_reference|remove_reference|alter_column|drop_column|batch_alter_table)\s*\(?\s*(?::|["'])([\w.]+)/g,
|
|
1377
|
+
// Knex / Kysely schema builders.
|
|
1378
|
+
/\b(?:createTable|createTableIfNotExists|alterTable|dropTable|dropTableIfExists)\s*\(\s*["'`]([\w.]+)/g,
|
|
1379
|
+
/\.table\s*\(\s*["'`]([\w.]+)/g
|
|
1380
|
+
];
|
|
1381
|
+
function cleanTable(raw) {
|
|
1382
|
+
const last = raw.split(".").at(-1) ?? raw;
|
|
1383
|
+
return last.replace(/[`"[\]\s]/g, "").toLowerCase();
|
|
1384
|
+
}
|
|
1385
|
+
function migrationTables(content) {
|
|
1386
|
+
const tables = /* @__PURE__ */ new Set();
|
|
1387
|
+
for (const pattern of TABLE_PATTERNS) {
|
|
1388
|
+
for (const m of content.matchAll(pattern)) {
|
|
1389
|
+
const table = cleanTable(m[1] ?? "");
|
|
1390
|
+
if (table) tables.add(table);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
return [...tables].sort();
|
|
1394
|
+
}
|
|
1395
|
+
function alembicParent(content) {
|
|
1396
|
+
const m = /^down_revision\s*(?::[^=\n]*)?=\s*(.+?)\s*$/m.exec(content);
|
|
1397
|
+
if (!m) return null;
|
|
1398
|
+
const value = m[1] ?? "";
|
|
1399
|
+
if (/^None\b/.test(value)) return "root";
|
|
1400
|
+
const revs = [...value.matchAll(/["']([^"']+)["']/g)].map((r) => r[1] ?? "").filter(Boolean);
|
|
1401
|
+
return revs.length > 0 ? revs.sort().join(",") : null;
|
|
1402
|
+
}
|
|
1403
|
+
function seqFact(path, dir, seq, content) {
|
|
1404
|
+
return {
|
|
1405
|
+
kind: "migration",
|
|
1406
|
+
file: path,
|
|
1407
|
+
dir,
|
|
1408
|
+
seq,
|
|
1409
|
+
seqType: seq.length >= 12 ? "timestamp" : "number",
|
|
1410
|
+
tables: migrationTables(content)
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
function migrationFact(path, content) {
|
|
1414
|
+
const dir = dirname(path);
|
|
1415
|
+
if (path.endsWith(".py")) {
|
|
1416
|
+
const parent = alembicParent(content);
|
|
1417
|
+
if (parent) {
|
|
1418
|
+
return {
|
|
1419
|
+
kind: "migration",
|
|
1420
|
+
file: path,
|
|
1421
|
+
dir,
|
|
1422
|
+
seq: `parent:${parent}`,
|
|
1423
|
+
seqType: "number",
|
|
1424
|
+
tables: migrationTables(content)
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
const own = /^\d+/.exec(basename(path));
|
|
1429
|
+
if (own) return seqFact(path, dir, own[0], content);
|
|
1430
|
+
const folder = /^\d+/.exec(basename(dir));
|
|
1431
|
+
if (folder) return seqFact(path, dirname(dir), folder[0], content);
|
|
1432
|
+
return null;
|
|
1433
|
+
}
|
|
1434
|
+
function depFact(file, ecosystem, name, version) {
|
|
1435
|
+
return { kind: "dependency", file, ecosystem, name, version };
|
|
1436
|
+
}
|
|
1437
|
+
var DepList = class {
|
|
1438
|
+
facts = [];
|
|
1439
|
+
seen = /* @__PURE__ */ new Set();
|
|
1440
|
+
file;
|
|
1441
|
+
ecosystem;
|
|
1442
|
+
constructor(file, ecosystem) {
|
|
1443
|
+
this.file = file;
|
|
1444
|
+
this.ecosystem = ecosystem;
|
|
1445
|
+
}
|
|
1446
|
+
add(name, version) {
|
|
1447
|
+
if (this.seen.has(name)) return;
|
|
1448
|
+
this.seen.add(name);
|
|
1449
|
+
this.facts.push(depFact(this.file, this.ecosystem, name, version));
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
function manifestFacts(path, name, content) {
|
|
1453
|
+
if (name === "package.json") return packageJsonDeps(path, content);
|
|
1454
|
+
if (name === "pyproject.toml") return pyprojectDeps(path, content);
|
|
1455
|
+
if (name === "go.mod") return goModDeps(path, content);
|
|
1456
|
+
if (name === "Cargo.toml") return cargoDeps(path, content);
|
|
1457
|
+
return requirementsDeps(path, content);
|
|
1458
|
+
}
|
|
1459
|
+
function parseJson(content) {
|
|
1460
|
+
try {
|
|
1461
|
+
return JSON.parse(content);
|
|
1462
|
+
} catch {
|
|
1463
|
+
return null;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
function parseTomlTable(content) {
|
|
1467
|
+
try {
|
|
1468
|
+
return parse(content);
|
|
1469
|
+
} catch {
|
|
1470
|
+
return null;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
var NPM_SECTIONS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
|
|
1474
|
+
function packageJsonDeps(path, content) {
|
|
1475
|
+
const pkg = parseJson(content);
|
|
1476
|
+
if (!isRecord(pkg)) return [];
|
|
1477
|
+
const list = new DepList(path, "npm");
|
|
1478
|
+
for (const section of NPM_SECTIONS) {
|
|
1479
|
+
const deps = pkg[section];
|
|
1480
|
+
if (!isRecord(deps)) continue;
|
|
1481
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
1482
|
+
if (typeof version === "string") list.add(name, version);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
return list.facts;
|
|
1486
|
+
}
|
|
1487
|
+
function normalizePypi(name) {
|
|
1488
|
+
return name.toLowerCase().replace(/[-_.]+/g, "-");
|
|
1489
|
+
}
|
|
1490
|
+
function parsePep508(spec) {
|
|
1491
|
+
const m = /^\s*([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)\s*(?:\[[^\]]*\])?\s*(.*)$/.exec(spec);
|
|
1492
|
+
if (!m) return null;
|
|
1493
|
+
const rest = (m[2] ?? "").split(";")[0]?.trim() ?? "";
|
|
1494
|
+
if (rest !== "" && !/^[=<>!~@(]/.test(rest)) return null;
|
|
1495
|
+
return { name: normalizePypi(m[1] ?? ""), version: rest };
|
|
1496
|
+
}
|
|
1497
|
+
function tomlVersion(value) {
|
|
1498
|
+
if (typeof value === "string") return value;
|
|
1499
|
+
if (isRecord(value) && typeof value.version === "string") return value.version;
|
|
1500
|
+
return "";
|
|
1501
|
+
}
|
|
1502
|
+
function pyprojectDeps(path, content) {
|
|
1503
|
+
const doc = parseTomlTable(content);
|
|
1504
|
+
if (!doc) return [];
|
|
1505
|
+
const list = new DepList(path, "pypi");
|
|
1506
|
+
const project = doc.project;
|
|
1507
|
+
if (isRecord(project) && Array.isArray(project.dependencies)) {
|
|
1508
|
+
for (const spec of project.dependencies) {
|
|
1509
|
+
const req = typeof spec === "string" ? parsePep508(spec) : null;
|
|
1510
|
+
if (req) list.add(req.name, req.version);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
const poetry = isRecord(doc.tool) ? doc.tool.poetry : void 0;
|
|
1514
|
+
if (isRecord(poetry)) {
|
|
1515
|
+
const tables = [poetry.dependencies, poetry["dev-dependencies"]];
|
|
1516
|
+
if (isRecord(poetry.group)) {
|
|
1517
|
+
for (const group of Object.values(poetry.group)) if (isRecord(group)) tables.push(group.dependencies);
|
|
1518
|
+
}
|
|
1519
|
+
for (const table of tables) {
|
|
1520
|
+
if (!isRecord(table)) continue;
|
|
1521
|
+
for (const [name, value] of Object.entries(table)) {
|
|
1522
|
+
if (name.toLowerCase() !== "python") list.add(normalizePypi(name), tomlVersion(value));
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
return list.facts;
|
|
1527
|
+
}
|
|
1528
|
+
function requirementsDeps(path, content) {
|
|
1529
|
+
const list = new DepList(path, "pypi");
|
|
1530
|
+
for (const raw of content.split(/\r?\n/)) {
|
|
1531
|
+
const line = raw.replace(/(^|\s)#.*$/, "").split(/\s+--/)[0]?.trim() ?? "";
|
|
1532
|
+
if (line === "" || line.startsWith("-")) continue;
|
|
1533
|
+
const req = parsePep508(line);
|
|
1534
|
+
if (req) list.add(req.name, req.version);
|
|
1535
|
+
}
|
|
1536
|
+
return list.facts;
|
|
1537
|
+
}
|
|
1538
|
+
function goModDeps(path, content) {
|
|
1539
|
+
const list = new DepList(path, "go");
|
|
1540
|
+
let inBlock = false;
|
|
1541
|
+
for (const raw of content.split(/\r?\n/)) {
|
|
1542
|
+
const line = raw.replace(/\/\/.*$/, "").trim();
|
|
1543
|
+
if (inBlock) {
|
|
1544
|
+
if (line === ")") inBlock = false;
|
|
1545
|
+
else addGoRequire(list, line);
|
|
1546
|
+
} else if (/^require\s*\($/.test(line)) {
|
|
1547
|
+
inBlock = true;
|
|
1548
|
+
} else if (line.startsWith("require ")) {
|
|
1549
|
+
addGoRequire(list, line.slice("require ".length).trim());
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return list.facts;
|
|
1553
|
+
}
|
|
1554
|
+
function addGoRequire(list, entry) {
|
|
1555
|
+
const m = /^(\S+)\s+(v\S+)$/.exec(entry);
|
|
1556
|
+
if (m?.[1] && m[2]) list.add(m[1], m[2]);
|
|
1557
|
+
}
|
|
1558
|
+
function cargoDeps(path, content) {
|
|
1559
|
+
const doc = parseTomlTable(content);
|
|
1560
|
+
if (!doc) return [];
|
|
1561
|
+
const list = new DepList(path, "cargo");
|
|
1562
|
+
const workspace = isRecord(doc.workspace) ? doc.workspace.dependencies : void 0;
|
|
1563
|
+
const tables = [doc.dependencies, doc["dev-dependencies"], doc["build-dependencies"], workspace];
|
|
1564
|
+
for (const table of tables) {
|
|
1565
|
+
if (!isRecord(table)) continue;
|
|
1566
|
+
for (const [name, value] of Object.entries(table)) list.add(name, tomlVersion(value));
|
|
1567
|
+
}
|
|
1568
|
+
return list.facts;
|
|
1569
|
+
}
|
|
1570
|
+
function envValue(raw) {
|
|
1571
|
+
const value = raw.trim();
|
|
1572
|
+
const quote = value[0];
|
|
1573
|
+
if (quote === '"' || quote === "'") {
|
|
1574
|
+
const end = value.indexOf(quote, 1);
|
|
1575
|
+
if (end !== -1) return value.slice(1, end);
|
|
1576
|
+
}
|
|
1577
|
+
return value.replace(/\s+#.*$/, "").trim();
|
|
1578
|
+
}
|
|
1579
|
+
function envFacts(path, content) {
|
|
1580
|
+
const out = [];
|
|
1581
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1582
|
+
for (const line of content.split(/\r?\n/)) {
|
|
1583
|
+
const m = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_.]*)\s*=(.*)$/.exec(line);
|
|
1584
|
+
const name = m?.[1];
|
|
1585
|
+
if (!name || seen.has(name)) continue;
|
|
1586
|
+
seen.add(name);
|
|
1587
|
+
out.push({ kind: "env", file: path, name, valueHash: hex16(envValue(m[2] ?? "")) });
|
|
1588
|
+
}
|
|
1589
|
+
return out;
|
|
1590
|
+
}
|
|
1591
|
+
var APP_ROUTE_FILE = /^route\.(ts|js|tsx|jsx)$/;
|
|
1592
|
+
var PAGES_API_FILE = /\.(ts|js|tsx|jsx)$/;
|
|
1593
|
+
function routeSegment(seg) {
|
|
1594
|
+
const catchAll = /^\[\[?\.\.\.([^\]]+)\]\]?$/.exec(seg);
|
|
1595
|
+
if (catchAll) return `*${catchAll[1]}`;
|
|
1596
|
+
const dynamic = /^\[([^\]]+)\]$/.exec(seg);
|
|
1597
|
+
return dynamic ? `:${dynamic[1]}` : seg;
|
|
1598
|
+
}
|
|
1599
|
+
function joinRoute(segs) {
|
|
1600
|
+
return `/${segs.map(routeSegment).join("/")}`;
|
|
1601
|
+
}
|
|
1602
|
+
function nextRoute(path) {
|
|
1603
|
+
const parts = path.split("/");
|
|
1604
|
+
const file = parts.at(-1) ?? "";
|
|
1605
|
+
const appIdx = parts.indexOf("app");
|
|
1606
|
+
if (APP_ROUTE_FILE.test(file) && appIdx !== -1 && appIdx < parts.length - 1) {
|
|
1607
|
+
const segs = [];
|
|
1608
|
+
for (const seg of parts.slice(appIdx + 1, -1)) {
|
|
1609
|
+
if (seg.startsWith("_")) return null;
|
|
1610
|
+
if (/^\(.*\)$/.test(seg) || seg.startsWith("@")) continue;
|
|
1611
|
+
segs.push(seg);
|
|
1612
|
+
}
|
|
1613
|
+
return { path: joinRoute(segs), methodFromExports: true };
|
|
1614
|
+
}
|
|
1615
|
+
const apiIdx = parts.findIndex((p, i) => p === "pages" && parts[i + 1] === "api");
|
|
1616
|
+
if (apiIdx !== -1 && apiIdx + 2 < parts.length && PAGES_API_FILE.test(file) && !file.endsWith(".d.ts")) {
|
|
1617
|
+
const stem2 = file.replace(PAGES_API_FILE, "");
|
|
1618
|
+
const segs = parts.slice(apiIdx + 1, -1);
|
|
1619
|
+
if (stem2 !== "index") segs.push(stem2);
|
|
1620
|
+
return { path: joinRoute(segs), methodFromExports: false };
|
|
1621
|
+
}
|
|
1622
|
+
return null;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// ../analysis/src/parse/lang/typescript.ts
|
|
1626
|
+
var FUNCTION_VALUES = /* @__PURE__ */ new Set(["arrow_function", "function_expression", "function", "generator_function"]);
|
|
1627
|
+
var CLASS_TYPES = /* @__PURE__ */ new Set(["class_declaration", "abstract_class_declaration", "class"]);
|
|
1628
|
+
var TYPE_DECL_PARENTS = /* @__PURE__ */ new Set([
|
|
1629
|
+
"class_declaration",
|
|
1630
|
+
"abstract_class_declaration",
|
|
1631
|
+
"interface_declaration",
|
|
1632
|
+
"type_alias_declaration",
|
|
1633
|
+
"type_parameter",
|
|
1634
|
+
"enum_declaration"
|
|
1635
|
+
]);
|
|
1636
|
+
function extractTypeScript(root, out) {
|
|
1637
|
+
const ctx = {
|
|
1638
|
+
out,
|
|
1639
|
+
lang: out.lang,
|
|
1640
|
+
symbols: /* @__PURE__ */ new Map(),
|
|
1641
|
+
declNodes: /* @__PURE__ */ new Map(),
|
|
1642
|
+
exportedLocals: /* @__PURE__ */ new Set(),
|
|
1643
|
+
importLocals: /* @__PURE__ */ new Set(),
|
|
1644
|
+
namespaceLocals: /* @__PURE__ */ new Set(),
|
|
1645
|
+
typeParams: /* @__PURE__ */ new Set()
|
|
1646
|
+
};
|
|
1647
|
+
for (const stmt of root.namedChildren) if (stmt) declareStatement2(ctx, stmt, "", false);
|
|
1648
|
+
for (const s of ctx.symbols.values()) {
|
|
1649
|
+
if (!s.qualifiedName.includes(".") && ctx.exportedLocals.has(s.qualifiedName)) s.exported = true;
|
|
1650
|
+
const { parts: _parts, ...symbol } = s;
|
|
1651
|
+
out.symbols.push(symbol);
|
|
1652
|
+
}
|
|
1653
|
+
collectRefs2(ctx, root);
|
|
1654
|
+
const next = nextRoute(out.path);
|
|
1655
|
+
if (next?.methodFromExports) {
|
|
1656
|
+
for (const s of out.symbols) {
|
|
1657
|
+
if (s.exported && !s.qualifiedName.includes(".") && HTTP_METHODS.has(s.name.toLowerCase()) && s.name === s.name.toUpperCase()) {
|
|
1658
|
+
out.routes.push({ method: s.name, path: next.path, line: s.range.startLine });
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
function declareStatement2(ctx, node, prefix, exported) {
|
|
1664
|
+
switch (node.type) {
|
|
1665
|
+
case "export_statement":
|
|
1666
|
+
declareExport(ctx, node, prefix);
|
|
1667
|
+
return;
|
|
1668
|
+
case "ambient_declaration":
|
|
1669
|
+
case "expression_statement":
|
|
1670
|
+
for (const c of node.namedChildren) if (c) declareStatement2(ctx, c, prefix, exported);
|
|
1671
|
+
return;
|
|
1672
|
+
case "function_declaration":
|
|
1673
|
+
case "generator_function_declaration":
|
|
1674
|
+
case "function_signature":
|
|
1675
|
+
declareFunction2(ctx, node, prefix, exported);
|
|
1676
|
+
return;
|
|
1677
|
+
case "class_declaration":
|
|
1678
|
+
case "abstract_class_declaration":
|
|
1679
|
+
declareClass2(ctx, node, prefix, exported);
|
|
1680
|
+
return;
|
|
1681
|
+
case "interface_declaration":
|
|
1682
|
+
case "type_alias_declaration":
|
|
1683
|
+
case "enum_declaration":
|
|
1684
|
+
declareTypeLike(ctx, node, prefix, exported);
|
|
1685
|
+
return;
|
|
1686
|
+
case "lexical_declaration":
|
|
1687
|
+
case "variable_declaration":
|
|
1688
|
+
declareVariables(ctx, node, prefix, exported);
|
|
1689
|
+
return;
|
|
1690
|
+
case "internal_module":
|
|
1691
|
+
case "module":
|
|
1692
|
+
declareNamespace(ctx, node, prefix, exported);
|
|
1693
|
+
return;
|
|
1694
|
+
case "import_statement":
|
|
1695
|
+
declareImport2(ctx, node);
|
|
1696
|
+
return;
|
|
1697
|
+
case "assignment_expression":
|
|
1698
|
+
declareCommonJsExport(ctx, node);
|
|
1699
|
+
return;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
function declareExport(ctx, node, prefix) {
|
|
1703
|
+
const source = stringValue(node.childForFieldName("source"));
|
|
1704
|
+
const decl = node.childForFieldName("declaration");
|
|
1705
|
+
const isDefault = hasChild(node, "default");
|
|
1706
|
+
if (decl) {
|
|
1707
|
+
declareStatement2(ctx, decl, prefix, true);
|
|
1708
|
+
const name = decl.childForFieldName("name")?.text;
|
|
1709
|
+
if (isDefault && name && !prefix) ctx.out.defaultExport = name;
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const value = node.childForFieldName("value");
|
|
1713
|
+
if (value) {
|
|
1714
|
+
if (value.type === "identifier") ctx.exportedLocals.add(value.text);
|
|
1715
|
+
else if (FUNCTION_VALUES.has(value.type)) addFunction(ctx, value, "default", prefix, true, "function");
|
|
1716
|
+
else if (CLASS_TYPES.has(value.type)) declareClass2(ctx, value, prefix, true, "default");
|
|
1717
|
+
if (!prefix) ctx.out.defaultExport = value.type === "identifier" ? value.text : "default";
|
|
1718
|
+
return;
|
|
1719
|
+
}
|
|
1720
|
+
const clause = node.namedChildren.find((c) => c?.type === "export_clause");
|
|
1721
|
+
const names = [];
|
|
1722
|
+
for (const spec of clause?.namedChildren ?? []) {
|
|
1723
|
+
if (spec?.type !== "export_specifier") continue;
|
|
1724
|
+
const name = spec.childForFieldName("name")?.text;
|
|
1725
|
+
const alias = spec.childForFieldName("alias")?.text;
|
|
1726
|
+
if (!name) continue;
|
|
1727
|
+
if (source === null) ctx.exportedLocals.add(name);
|
|
1728
|
+
else names.push({ imported: name, local: alias ?? name });
|
|
1729
|
+
}
|
|
1730
|
+
if (source !== null) {
|
|
1731
|
+
if (!clause) {
|
|
1732
|
+
const ns = node.namedChildren.find((c) => c?.type === "namespace_export");
|
|
1733
|
+
const local = ns?.namedChildren.find((c) => c?.type === "identifier")?.text ?? "*";
|
|
1734
|
+
names.push({ imported: "*", local });
|
|
1735
|
+
}
|
|
1736
|
+
ctx.out.imports.push({ source, names, line: lineOf(node), reexport: true });
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function hasChild(node, type) {
|
|
1740
|
+
for (let i = 0; i < node.childCount; i++) if (node.child(i)?.type === type) return true;
|
|
1741
|
+
return false;
|
|
1742
|
+
}
|
|
1743
|
+
function paramSignature2(params) {
|
|
1744
|
+
const parts = [];
|
|
1745
|
+
let min = 0;
|
|
1746
|
+
let count = 0;
|
|
1747
|
+
let variadic = false;
|
|
1748
|
+
if (!params) return { parts, arity: { min: 0, max: 0 } };
|
|
1749
|
+
const list = params.type === "identifier" ? [params] : params.namedChildren;
|
|
1750
|
+
for (const p of list) {
|
|
1751
|
+
if (!p || p.type === "comment" || p.type === "decorator") continue;
|
|
1752
|
+
let pattern = p;
|
|
1753
|
+
let optional = false;
|
|
1754
|
+
let typeText = "";
|
|
1755
|
+
let modifiers = "";
|
|
1756
|
+
if (p.type === "required_parameter" || p.type === "optional_parameter") {
|
|
1757
|
+
pattern = p.childForFieldName("pattern");
|
|
1758
|
+
optional = p.type === "optional_parameter" || p.childForFieldName("value") !== null;
|
|
1759
|
+
typeText = normalizedText(p.childForFieldName("type"));
|
|
1760
|
+
modifiers = p.namedChildren.filter((c) => c?.type === "accessibility_modifier" || c?.type === "override_modifier").map((c) => c.text).join(" ");
|
|
1761
|
+
if (hasChild(p, "readonly")) modifiers += " readonly";
|
|
1762
|
+
} else if (p.type === "assignment_pattern") {
|
|
1763
|
+
pattern = p.childForFieldName("left");
|
|
1764
|
+
optional = true;
|
|
1765
|
+
}
|
|
1766
|
+
if (pattern?.type === "this") {
|
|
1767
|
+
parts.push(`this:${typeText}`);
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
const rest = pattern?.type === "rest_pattern";
|
|
1771
|
+
const shape = !pattern || pattern.type === "identifier" ? "_" : rest ? "..." : normalizedText(pattern);
|
|
1772
|
+
parts.push(`${modifiers.trim()}|${shape}${optional ? "?" : ""}:${typeText}`);
|
|
1773
|
+
if (rest) variadic = true;
|
|
1774
|
+
else {
|
|
1775
|
+
count++;
|
|
1776
|
+
if (!optional) min = count;
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
return { parts, arity: { min, max: variadic ? null : count } };
|
|
1780
|
+
}
|
|
1781
|
+
function addSymbol2(ctx, node, name, prefix, kind, exported, sigParts, body, signatureText, arity, bodySkip) {
|
|
1782
|
+
const qualifiedName = prefix + name;
|
|
1783
|
+
ctx.declNodes.set(node.id, qualifiedName);
|
|
1784
|
+
const existing = ctx.symbols.get(qualifiedName);
|
|
1785
|
+
const bodyHash = hashTokens(body ? leafTokens(body, bodySkip) : []);
|
|
1786
|
+
if (existing) {
|
|
1787
|
+
existing.parts.push("|overload|", ...sigParts);
|
|
1788
|
+
existing.signatureHash = hashTokens(existing.parts);
|
|
1789
|
+
if (body) existing.bodyHash = bodyHash;
|
|
1790
|
+
existing.exported ||= exported;
|
|
1791
|
+
existing.range = {
|
|
1792
|
+
startLine: Math.min(existing.range.startLine, lineOf(node)),
|
|
1793
|
+
endLine: Math.max(existing.range.endLine, endLineOf(node))
|
|
1794
|
+
};
|
|
1795
|
+
if (body && arity) {
|
|
1796
|
+
existing.signatureText = signatureText;
|
|
1797
|
+
}
|
|
1798
|
+
if (arity && existing.arity) {
|
|
1799
|
+
existing.arity = {
|
|
1800
|
+
min: Math.min(existing.arity.min, arity.min),
|
|
1801
|
+
max: existing.arity.max === null || arity.max === null ? null : Math.max(existing.arity.max, arity.max)
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
const parts = [kind, ...sigParts];
|
|
1807
|
+
const symbol = {
|
|
1808
|
+
id: symbolIdOf(ctx.lang, ctx.out.path, qualifiedName),
|
|
1809
|
+
kind,
|
|
1810
|
+
name,
|
|
1811
|
+
qualifiedName,
|
|
1812
|
+
file: ctx.out.path,
|
|
1813
|
+
range: { startLine: lineOf(node), endLine: endLineOf(node) },
|
|
1814
|
+
exported,
|
|
1815
|
+
signatureHash: hashTokens(parts),
|
|
1816
|
+
bodyHash,
|
|
1817
|
+
signatureText: signatureText.slice(0, 300),
|
|
1818
|
+
parts
|
|
1819
|
+
};
|
|
1820
|
+
if (arity) symbol.arity = arity;
|
|
1821
|
+
ctx.symbols.set(qualifiedName, symbol);
|
|
1822
|
+
}
|
|
1823
|
+
function callableParts(ctx, fn) {
|
|
1824
|
+
const params = fn.childForFieldName("parameters") ?? fn.childForFieldName("parameter");
|
|
1825
|
+
const { parts, arity } = paramSignature2(params);
|
|
1826
|
+
const tp = fn.childForFieldName("type_parameters");
|
|
1827
|
+
const ret = fn.childForFieldName("return_type");
|
|
1828
|
+
const isAsync = hasChild(fn, "async");
|
|
1829
|
+
const isGenerator = hasChild(fn, "*");
|
|
1830
|
+
collectTypeParams(ctx, tp);
|
|
1831
|
+
const text = `${tp ? squash(tp.text) : ""}${params ? squash(params.type === "identifier" ? `(${params.text})` : params.text) : "()"}${ret ? squash(ret.text) : ""}`;
|
|
1832
|
+
return {
|
|
1833
|
+
parts: [
|
|
1834
|
+
isAsync ? "async" : "",
|
|
1835
|
+
isGenerator ? "*" : "",
|
|
1836
|
+
normalizedText(tp),
|
|
1837
|
+
...parts,
|
|
1838
|
+
"=>",
|
|
1839
|
+
normalizedText(ret)
|
|
1840
|
+
],
|
|
1841
|
+
arity,
|
|
1842
|
+
text,
|
|
1843
|
+
isAsync
|
|
1844
|
+
};
|
|
1845
|
+
}
|
|
1846
|
+
function collectTypeParams(ctx, tp) {
|
|
1847
|
+
for (const p of tp?.namedChildren ?? []) {
|
|
1848
|
+
const n = p?.childForFieldName("name")?.text;
|
|
1849
|
+
if (n) ctx.typeParams.add(n);
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
function addFunction(ctx, fn, name, prefix, exported, kind, at2 = fn) {
|
|
1853
|
+
const { parts, arity, text, isAsync } = callableParts(ctx, fn);
|
|
1854
|
+
const keyword = kind === "function" && (fn.type === "function_declaration" || fn.type === "generator_function_declaration" || fn.type === "function_signature") ? "function " : "";
|
|
1855
|
+
const sigText = `${isAsync ? "async " : ""}${keyword}${name}${text}`;
|
|
1856
|
+
addSymbol2(ctx, at2, name, prefix, kind, exported, parts, fn.childForFieldName("body"), sigText, arity);
|
|
1857
|
+
}
|
|
1858
|
+
function declareFunction2(ctx, node, prefix, exported) {
|
|
1859
|
+
const name = node.childForFieldName("name")?.text;
|
|
1860
|
+
if (name) addFunction(ctx, node, name, prefix, exported, "function");
|
|
1861
|
+
}
|
|
1862
|
+
function declareClass2(ctx, node, prefix, exported, fallbackName) {
|
|
1863
|
+
const name = node.childForFieldName("name")?.text ?? fallbackName;
|
|
1864
|
+
if (!name) return;
|
|
1865
|
+
const tp = node.childForFieldName("type_parameters");
|
|
1866
|
+
collectTypeParams(ctx, tp);
|
|
1867
|
+
const heritage = node.namedChildren.find((c) => c?.type === "class_heritage");
|
|
1868
|
+
const body = node.childForFieldName("body");
|
|
1869
|
+
const shape = [
|
|
1870
|
+
node.type === "abstract_class_declaration" ? "abstract" : "",
|
|
1871
|
+
normalizedText(tp),
|
|
1872
|
+
normalizedText(heritage)
|
|
1873
|
+
];
|
|
1874
|
+
const qualified = `${prefix}${name}.`;
|
|
1875
|
+
const methodIds = /* @__PURE__ */ new Set();
|
|
1876
|
+
const ctorArities = [];
|
|
1877
|
+
for (const member of body?.namedChildren ?? []) {
|
|
1878
|
+
if (!member) continue;
|
|
1879
|
+
switch (member.type) {
|
|
1880
|
+
case "public_field_definition":
|
|
1881
|
+
case "field_definition": {
|
|
1882
|
+
const memberName = member.childForFieldName("name") ?? member.childForFieldName("property");
|
|
1883
|
+
const value = member.childForFieldName("value");
|
|
1884
|
+
if (memberName && value && FUNCTION_VALUES.has(value.type)) {
|
|
1885
|
+
methodIds.add(member.id);
|
|
1886
|
+
addFunction(
|
|
1887
|
+
ctx,
|
|
1888
|
+
value,
|
|
1889
|
+
memberName.text,
|
|
1890
|
+
qualified,
|
|
1891
|
+
exported && isPublicMember(member, memberName),
|
|
1892
|
+
"method",
|
|
1893
|
+
member
|
|
1894
|
+
);
|
|
1895
|
+
} else if (memberName) {
|
|
1896
|
+
const modifiers = member.children.filter((c) => c && !c.isNamed && c.type !== "=" && c.type !== ";").map((c) => c.type).join(" ");
|
|
1897
|
+
const access = member.namedChildren.find((c) => c?.type === "accessibility_modifier")?.text ?? "";
|
|
1898
|
+
shape.push(
|
|
1899
|
+
`field:${access}:${modifiers}:${memberName.text}:${normalizedText(member.childForFieldName("type"))}`
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
break;
|
|
1903
|
+
}
|
|
1904
|
+
case "method_definition":
|
|
1905
|
+
case "method_signature":
|
|
1906
|
+
case "abstract_method_signature": {
|
|
1907
|
+
const memberName = member.childForFieldName("name");
|
|
1908
|
+
if (!memberName) break;
|
|
1909
|
+
methodIds.add(member.id);
|
|
1910
|
+
const methodName = memberName.text;
|
|
1911
|
+
if (methodName === "constructor") {
|
|
1912
|
+
const ctor = callableParts(ctx, member);
|
|
1913
|
+
shape.push("ctor", ...ctor.parts);
|
|
1914
|
+
ctorArities.push(ctor.arity);
|
|
1915
|
+
}
|
|
1916
|
+
const accessor = member.children.find((c) => c && (c.type === "get" || c.type === "set"))?.type ?? "";
|
|
1917
|
+
const isStatic = hasChild(member, "static");
|
|
1918
|
+
addMethod(
|
|
1919
|
+
ctx,
|
|
1920
|
+
member,
|
|
1921
|
+
methodName,
|
|
1922
|
+
qualified,
|
|
1923
|
+
exported && isPublicMember(member, memberName),
|
|
1924
|
+
accessor,
|
|
1925
|
+
isStatic
|
|
1926
|
+
);
|
|
1927
|
+
break;
|
|
1928
|
+
}
|
|
1929
|
+
case "index_signature":
|
|
1930
|
+
shape.push(`index:${normalizedText(member)}`);
|
|
1931
|
+
break;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
addSymbol2(
|
|
1935
|
+
ctx,
|
|
1936
|
+
node,
|
|
1937
|
+
name,
|
|
1938
|
+
prefix,
|
|
1939
|
+
"class",
|
|
1940
|
+
exported,
|
|
1941
|
+
shape,
|
|
1942
|
+
body,
|
|
1943
|
+
`class ${name}${tp ? squash(tp.text) : ""}${heritage ? ` ${squash(heritage.text)}` : ""}`,
|
|
1944
|
+
// `new Cls(...)` takes the constructor's arguments; overloads or an inherited constructor leave it unknown.
|
|
1945
|
+
ctorArities.length === 1 ? ctorArities[0] : void 0,
|
|
1946
|
+
methodIds
|
|
1947
|
+
);
|
|
1948
|
+
}
|
|
1949
|
+
function addMethod(ctx, member, name, prefix, exported, accessor, isStatic) {
|
|
1950
|
+
const { parts, arity, text, isAsync } = callableParts(ctx, member);
|
|
1951
|
+
const sigText = `${isAsync ? "async " : ""}${isStatic ? "static " : ""}${accessor ? `${accessor} ` : ""}${name}${text}`;
|
|
1952
|
+
addSymbol2(
|
|
1953
|
+
ctx,
|
|
1954
|
+
member,
|
|
1955
|
+
name,
|
|
1956
|
+
prefix,
|
|
1957
|
+
"method",
|
|
1958
|
+
exported,
|
|
1959
|
+
[isStatic ? "static" : "", accessor, ...parts],
|
|
1960
|
+
member.childForFieldName("body"),
|
|
1961
|
+
sigText,
|
|
1962
|
+
accessor === "get" ? { min: 0, max: 0 } : arity
|
|
1963
|
+
);
|
|
1964
|
+
}
|
|
1965
|
+
function isPublicMember(member, name) {
|
|
1966
|
+
if (name.type === "private_property_identifier") return false;
|
|
1967
|
+
const access = member.namedChildren.find((c) => c?.type === "accessibility_modifier")?.text;
|
|
1968
|
+
return access !== "private" && access !== "protected";
|
|
1969
|
+
}
|
|
1970
|
+
function declareTypeLike(ctx, node, prefix, exported) {
|
|
1971
|
+
const name = node.childForFieldName("name")?.text;
|
|
1972
|
+
if (!name) return;
|
|
1973
|
+
const tp = node.childForFieldName("type_parameters");
|
|
1974
|
+
collectTypeParams(ctx, tp);
|
|
1975
|
+
const kind = node.type === "interface_declaration" ? "interface" : node.type === "enum_declaration" ? "enum" : "type";
|
|
1976
|
+
const body = node.childForFieldName("body") ?? node.childForFieldName("value");
|
|
1977
|
+
const ext = node.namedChildren.find(
|
|
1978
|
+
(c) => c?.type === "extends_type_clause" || c?.type === "extends_clause"
|
|
1979
|
+
);
|
|
1980
|
+
const keyword = kind === "type" ? "type" : kind;
|
|
1981
|
+
addSymbol2(
|
|
1982
|
+
ctx,
|
|
1983
|
+
node,
|
|
1984
|
+
name,
|
|
1985
|
+
prefix,
|
|
1986
|
+
kind,
|
|
1987
|
+
exported,
|
|
1988
|
+
[hasChild(node, "const") ? "const" : "", normalizedText(tp), normalizedText(ext), normalizedText(body)],
|
|
1989
|
+
body,
|
|
1990
|
+
`${keyword} ${name}${tp ? squash(tp.text) : ""}`
|
|
1991
|
+
);
|
|
1992
|
+
}
|
|
1993
|
+
function declareVariables(ctx, node, prefix, exported) {
|
|
1994
|
+
const isConst = hasChild(node, "const");
|
|
1995
|
+
for (const d of node.namedChildren) {
|
|
1996
|
+
if (d?.type !== "variable_declarator") continue;
|
|
1997
|
+
const nameNode = d.childForFieldName("name");
|
|
1998
|
+
const value = d.childForFieldName("value");
|
|
1999
|
+
if (value && isRequireCall(value) && nameNode) {
|
|
2000
|
+
declareRequire(ctx, nameNode, value);
|
|
2001
|
+
continue;
|
|
2002
|
+
}
|
|
2003
|
+
const required = value?.type === "member_expression" ? value.childForFieldName("object") : null;
|
|
2004
|
+
const member = value?.childForFieldName("property");
|
|
2005
|
+
if (required && isRequireCall(required) && member?.type === "property_identifier" && nameNode?.type === "identifier") {
|
|
2006
|
+
declareRequire(ctx, nameNode, required, member.text);
|
|
2007
|
+
continue;
|
|
2008
|
+
}
|
|
2009
|
+
if (nameNode?.type !== "identifier") continue;
|
|
2010
|
+
const name = nameNode.text;
|
|
2011
|
+
if (value && FUNCTION_VALUES.has(value.type)) {
|
|
2012
|
+
addFunction(ctx, value, name, prefix, exported, "function", d);
|
|
2013
|
+
continue;
|
|
2014
|
+
}
|
|
2015
|
+
const type = d.childForFieldName("type");
|
|
2016
|
+
const kind = isConst ? "constant" : "variable";
|
|
2017
|
+
addSymbol2(
|
|
2018
|
+
ctx,
|
|
2019
|
+
d,
|
|
2020
|
+
name,
|
|
2021
|
+
prefix,
|
|
2022
|
+
kind,
|
|
2023
|
+
exported,
|
|
2024
|
+
[normalizedText(type)],
|
|
2025
|
+
value,
|
|
2026
|
+
`${isConst ? "const" : "let"} ${name}${type ? squash(type.text) : ""}`
|
|
2027
|
+
);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
function declareNamespace(ctx, node, prefix, exported) {
|
|
2031
|
+
const nameNode = node.childForFieldName("name");
|
|
2032
|
+
if (!nameNode) return;
|
|
2033
|
+
const name = stringValue(nameNode) ?? nameNode.text;
|
|
2034
|
+
addSymbol2(ctx, node, name, prefix, "module", exported, [], null, `namespace ${name}`);
|
|
2035
|
+
const body = node.childForFieldName("body");
|
|
2036
|
+
for (const stmt of body?.namedChildren ?? [])
|
|
2037
|
+
if (stmt) declareStatement2(ctx, stmt, `${prefix}${name}.`, false);
|
|
2038
|
+
}
|
|
2039
|
+
function declareImport2(ctx, node) {
|
|
2040
|
+
const source = stringValue(node.childForFieldName("source"));
|
|
2041
|
+
if (source === null) return;
|
|
2042
|
+
const decl = { source, names: [], line: lineOf(node) };
|
|
2043
|
+
const clause = node.namedChildren.find((c) => c?.type === "import_clause");
|
|
2044
|
+
for (const part of clause?.namedChildren ?? []) {
|
|
2045
|
+
if (!part) continue;
|
|
2046
|
+
if (part.type === "identifier") decl.names.push({ imported: "default", local: part.text });
|
|
2047
|
+
else if (part.type === "namespace_import") {
|
|
2048
|
+
const local = part.namedChildren.find((c) => c?.type === "identifier")?.text;
|
|
2049
|
+
if (local) {
|
|
2050
|
+
decl.names.push({ imported: "*", local });
|
|
2051
|
+
ctx.namespaceLocals.add(local);
|
|
2052
|
+
}
|
|
2053
|
+
} else if (part.type === "named_imports") {
|
|
2054
|
+
for (const spec of part.namedChildren) {
|
|
2055
|
+
if (spec?.type !== "import_specifier") continue;
|
|
2056
|
+
const imported = spec.childForFieldName("name")?.text;
|
|
2057
|
+
if (!imported) continue;
|
|
2058
|
+
decl.names.push({ imported, local: spec.childForFieldName("alias")?.text ?? imported });
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
for (const n of decl.names) if (n.imported !== "*") ctx.importLocals.add(n.local);
|
|
2063
|
+
ctx.out.imports.push(decl);
|
|
2064
|
+
}
|
|
2065
|
+
function isRequireCall(node) {
|
|
2066
|
+
return node.type === "call_expression" && node.childForFieldName("function")?.text === "require" && stringValue(node.childForFieldName("arguments")?.namedChild(0)) !== null;
|
|
2067
|
+
}
|
|
2068
|
+
function declareRequire(ctx, nameNode, call, member) {
|
|
2069
|
+
const source = stringValue(call.childForFieldName("arguments")?.namedChild(0));
|
|
2070
|
+
const decl = { source, names: [], line: lineOf(call) };
|
|
2071
|
+
if (member) {
|
|
2072
|
+
decl.names.push({ imported: member, local: nameNode.text });
|
|
2073
|
+
ctx.importLocals.add(nameNode.text);
|
|
2074
|
+
} else if (nameNode.type === "identifier") {
|
|
2075
|
+
decl.names.push({ imported: "*", local: nameNode.text });
|
|
2076
|
+
ctx.namespaceLocals.add(nameNode.text);
|
|
2077
|
+
} else if (nameNode.type === "object_pattern") {
|
|
2078
|
+
for (const p of nameNode.namedChildren) {
|
|
2079
|
+
if (p?.type === "shorthand_property_identifier_pattern")
|
|
2080
|
+
decl.names.push({ imported: p.text, local: p.text });
|
|
2081
|
+
else if (p?.type === "pair_pattern") {
|
|
2082
|
+
const key = p.childForFieldName("key")?.text;
|
|
2083
|
+
const value = p.childForFieldName("value");
|
|
2084
|
+
if (key && value?.type === "identifier") decl.names.push({ imported: key, local: value.text });
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
for (const n of decl.names) ctx.importLocals.add(n.local);
|
|
2088
|
+
}
|
|
2089
|
+
ctx.out.imports.push(decl);
|
|
2090
|
+
}
|
|
2091
|
+
function declareCommonJsExport(ctx, node) {
|
|
2092
|
+
const left = node.childForFieldName("left");
|
|
2093
|
+
const right = node.childForFieldName("right");
|
|
2094
|
+
if (left?.type !== "member_expression" || !right) return;
|
|
2095
|
+
const target = left.text;
|
|
2096
|
+
if (target === "module.exports") {
|
|
2097
|
+
if (right.type === "identifier") {
|
|
2098
|
+
ctx.exportedLocals.add(right.text);
|
|
2099
|
+
ctx.out.defaultExport = right.text;
|
|
2100
|
+
}
|
|
2101
|
+
for (const p of right.type === "object" ? right.namedChildren : []) {
|
|
2102
|
+
if (p?.type === "shorthand_property_identifier") ctx.exportedLocals.add(p.text);
|
|
2103
|
+
else if (p?.type === "pair") {
|
|
2104
|
+
const value = p.childForFieldName("value");
|
|
2105
|
+
if (value?.type === "identifier") ctx.exportedLocals.add(value.text);
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
} else if (/^(module\.)?exports\.[A-Za-z_$][\w$]*$/.test(target)) {
|
|
2109
|
+
if (right.type === "identifier") ctx.exportedLocals.add(right.text);
|
|
2110
|
+
const name = left.childForFieldName("property")?.text;
|
|
2111
|
+
if (name && FUNCTION_VALUES.has(right.type)) addFunction(ctx, right, name, "", true, "function", node);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
function argCount2(call) {
|
|
2115
|
+
const args = call.childForFieldName("arguments");
|
|
2116
|
+
if (args?.type !== "arguments") return void 0;
|
|
2117
|
+
let n = 0;
|
|
2118
|
+
for (const a of args.namedChildren) {
|
|
2119
|
+
if (!a || a.type === "comment") continue;
|
|
2120
|
+
if (a.type === "spread_element") return void 0;
|
|
2121
|
+
n++;
|
|
2122
|
+
}
|
|
2123
|
+
return n;
|
|
2124
|
+
}
|
|
2125
|
+
function envName(node) {
|
|
2126
|
+
const object = node.childForFieldName("object");
|
|
2127
|
+
if (!object) return null;
|
|
2128
|
+
const base = object.text.replace(/\s+/g, "");
|
|
2129
|
+
if (base !== "process.env" && base !== "import.meta.env") return null;
|
|
2130
|
+
if (node.type === "member_expression") return node.childForFieldName("property")?.text ?? null;
|
|
2131
|
+
return stringValue(node.childForFieldName("index"));
|
|
2132
|
+
}
|
|
2133
|
+
var REF_TYPES2 = /* @__PURE__ */ new Set([
|
|
2134
|
+
"call_expression",
|
|
2135
|
+
"new_expression",
|
|
2136
|
+
"type_identifier",
|
|
2137
|
+
"nested_type_identifier",
|
|
2138
|
+
"jsx_opening_element",
|
|
2139
|
+
"jsx_self_closing_element",
|
|
2140
|
+
"decorator",
|
|
2141
|
+
"identifier",
|
|
2142
|
+
"member_expression",
|
|
2143
|
+
"subscript_expression",
|
|
2144
|
+
"import_statement",
|
|
2145
|
+
"export_statement"
|
|
2146
|
+
]);
|
|
2147
|
+
var SCOPE_TYPES = /* @__PURE__ */ new Set([
|
|
2148
|
+
"function_declaration",
|
|
2149
|
+
"generator_function_declaration",
|
|
2150
|
+
"function_expression",
|
|
2151
|
+
"function",
|
|
2152
|
+
"generator_function",
|
|
2153
|
+
"arrow_function",
|
|
2154
|
+
"method_definition",
|
|
2155
|
+
"catch_clause"
|
|
2156
|
+
]);
|
|
2157
|
+
var BINDING_TYPES = ["identifier", "shorthand_property_identifier_pattern"];
|
|
2158
|
+
function shadowedImports2(ctx, scope) {
|
|
2159
|
+
const text = scope.text;
|
|
2160
|
+
if (![...ctx.importLocals, ...ctx.namespaceLocals].some((n) => text.includes(n))) return null;
|
|
2161
|
+
let names = null;
|
|
2162
|
+
const add = (n) => {
|
|
2163
|
+
if (n && (ctx.importLocals.has(n.text) || ctx.namespaceLocals.has(n.text))) {
|
|
2164
|
+
names ??= /* @__PURE__ */ new Set();
|
|
2165
|
+
names.add(n.text);
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2168
|
+
const params = scope.childForFieldName("parameters") ?? scope.childForFieldName("parameter");
|
|
2169
|
+
const bindPattern = (pattern) => {
|
|
2170
|
+
if (!pattern) return;
|
|
2171
|
+
if (pattern.type === "identifier") add(pattern);
|
|
2172
|
+
else for (const id of pattern.descendantsOfType(BINDING_TYPES)) add(id);
|
|
2173
|
+
};
|
|
2174
|
+
if (params?.type === "identifier") add(params);
|
|
2175
|
+
for (const p of params?.type === "identifier" ? [] : params?.namedChildren ?? []) {
|
|
2176
|
+
if (!p) continue;
|
|
2177
|
+
if (p.type === "required_parameter" || p.type === "optional_parameter")
|
|
2178
|
+
bindPattern(p.childForFieldName("pattern"));
|
|
2179
|
+
else if (p.type === "assignment_pattern") bindPattern(p.childForFieldName("left"));
|
|
2180
|
+
else bindPattern(p);
|
|
2181
|
+
}
|
|
2182
|
+
add(scope.type === "catch_clause" ? scope.childForFieldName("parameter") : null);
|
|
2183
|
+
const body = scope.childForFieldName("body");
|
|
2184
|
+
for (const decl of body?.descendantsOfType([
|
|
2185
|
+
"variable_declarator",
|
|
2186
|
+
"function_declaration",
|
|
2187
|
+
"class_declaration"
|
|
2188
|
+
]) ?? []) {
|
|
2189
|
+
const name = decl?.childForFieldName("name");
|
|
2190
|
+
if (name?.type === "identifier" || name?.type === "type_identifier") add(name);
|
|
2191
|
+
else for (const id of name?.descendantsOfType(BINDING_TYPES) ?? []) add(id);
|
|
2192
|
+
}
|
|
2193
|
+
return names;
|
|
2194
|
+
}
|
|
2195
|
+
function collectRefs2(ctx, root) {
|
|
2196
|
+
const out = ctx.out;
|
|
2197
|
+
const stack = [];
|
|
2198
|
+
const shadows = [];
|
|
2199
|
+
const types = [];
|
|
2200
|
+
const fields = [];
|
|
2201
|
+
const cursor = root.walk();
|
|
2202
|
+
const enclosing = () => stack.length ? stack[stack.length - 1].name : null;
|
|
2203
|
+
const shadowed = (name) => shadows.some((s) => s.names.has(name));
|
|
2204
|
+
const push2 = (ref) => {
|
|
2205
|
+
if (shadows.length) {
|
|
2206
|
+
if (ref.qualifier !== void 0 && shadowed(ref.qualifier)) {
|
|
2207
|
+
if (ref.kind === "identifier") return;
|
|
2208
|
+
delete ref.qualifier;
|
|
2209
|
+
ref.member = true;
|
|
2210
|
+
} else if (ref.qualifier === void 0 && !ref.member && shadowed(ref.name)) return;
|
|
2211
|
+
}
|
|
2212
|
+
out.refs.push(ref);
|
|
2213
|
+
};
|
|
2214
|
+
const tracksImports = ctx.importLocals.size > 0 || ctx.namespaceLocals.size > 0;
|
|
2215
|
+
try {
|
|
2216
|
+
for (; ; ) {
|
|
2217
|
+
const depth = cursor.currentDepth;
|
|
2218
|
+
const type = cursor.nodeType;
|
|
2219
|
+
types[depth] = type;
|
|
2220
|
+
fields[depth] = cursor.currentFieldName;
|
|
2221
|
+
while (stack.length && stack[stack.length - 1].depth >= depth) stack.pop();
|
|
2222
|
+
while (shadows.length && shadows[shadows.length - 1].depth >= depth) shadows.pop();
|
|
2223
|
+
let descend = true;
|
|
2224
|
+
const declName = ctx.declNodes.get(cursor.nodeId);
|
|
2225
|
+
if (declName) stack.push({ depth, name: declName });
|
|
2226
|
+
if (tracksImports && SCOPE_TYPES.has(type)) {
|
|
2227
|
+
const names = shadowedImports2(ctx, cursor.currentNode);
|
|
2228
|
+
if (names) shadows.push({ depth, names });
|
|
2229
|
+
}
|
|
2230
|
+
if (REF_TYPES2.has(type) && (type !== "identifier" || ctx.importLocals.has(cursor.nodeText))) {
|
|
2231
|
+
const node = cursor.currentNode;
|
|
2232
|
+
const parentType = types[depth - 1];
|
|
2233
|
+
const field = fields[depth];
|
|
2234
|
+
descend = visitRef(ctx, node, type, parentType, field, enclosing, push2, stack, depth);
|
|
2235
|
+
}
|
|
2236
|
+
if (descend && cursor.gotoFirstChild()) continue;
|
|
2237
|
+
while (!cursor.gotoNextSibling()) {
|
|
2238
|
+
if (!cursor.gotoParent()) return;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
} finally {
|
|
2242
|
+
cursor.delete();
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
function calleeRef(target) {
|
|
2246
|
+
if (!target) return null;
|
|
2247
|
+
if (target.type === "identifier") return { name: target.text, member: false };
|
|
2248
|
+
if (target.type === "member_expression") {
|
|
2249
|
+
const prop = target.childForFieldName("property");
|
|
2250
|
+
const obj = target.childForFieldName("object");
|
|
2251
|
+
if (!prop || prop.type === "private_property_identifier") return null;
|
|
2252
|
+
const qualifier = obj && (obj.type === "identifier" || obj.type === "this") ? obj.text : void 0;
|
|
2253
|
+
return qualifier ? { name: prop.text, qualifier, member: true } : { name: prop.text, member: true };
|
|
2254
|
+
}
|
|
2255
|
+
return null;
|
|
2256
|
+
}
|
|
2257
|
+
var SERVER_RECEIVER = /^(app|api|server|router|routes?|r|fastify|hono|\w+(Router|App|Routes|Server))$/;
|
|
2258
|
+
var TEST_PATH = /(^|\/)(__tests__|tests?|spec|e2e)\/|\.(test|spec)\.[cm]?[jt]sx?$/;
|
|
2259
|
+
function isRouteRegistration(ctx, receiver, argCount3) {
|
|
2260
|
+
return SERVER_RECEIVER.test(receiver) && (argCount3 === void 0 || argCount3 >= 2) && !TEST_PATH.test(ctx.out.path);
|
|
2261
|
+
}
|
|
2262
|
+
function visitRef(ctx, node, type, parentType, field, enclosing, push2, stack, depth) {
|
|
2263
|
+
const line = lineOf(node);
|
|
2264
|
+
switch (type) {
|
|
2265
|
+
case "import_statement":
|
|
2266
|
+
return false;
|
|
2267
|
+
case "export_statement":
|
|
2268
|
+
return node.childForFieldName("source") === null;
|
|
2269
|
+
case "call_expression": {
|
|
2270
|
+
if (parentType === "decorator") return true;
|
|
2271
|
+
const fn = node.childForFieldName("function");
|
|
2272
|
+
if (fn?.type === "identifier" && fn.text === "require") return false;
|
|
2273
|
+
const callee = calleeRef(fn);
|
|
2274
|
+
if (!callee) return true;
|
|
2275
|
+
const ref = { name: callee.name, kind: "call", line, enclosing: enclosing() };
|
|
2276
|
+
if (callee.qualifier) ref.qualifier = callee.qualifier;
|
|
2277
|
+
if (callee.member) ref.member = true;
|
|
2278
|
+
const n = argCount2(node);
|
|
2279
|
+
if (n !== void 0) ref.argCount = n;
|
|
2280
|
+
push2(ref);
|
|
2281
|
+
if (callee.qualifier && HTTP_METHODS.has(callee.name) && isRouteRegistration(ctx, callee.qualifier, n)) {
|
|
2282
|
+
const path = stringValue(node.childForFieldName("arguments")?.namedChild(0));
|
|
2283
|
+
if (path?.startsWith("/")) ctx.out.routes.push({ method: callee.name.toUpperCase(), path, line });
|
|
2284
|
+
}
|
|
2285
|
+
return true;
|
|
2286
|
+
}
|
|
2287
|
+
case "new_expression": {
|
|
2288
|
+
const callee = calleeRef(node.childForFieldName("constructor"));
|
|
2289
|
+
if (!callee) return true;
|
|
2290
|
+
const ref = { name: callee.name, kind: "new", line, enclosing: enclosing() };
|
|
2291
|
+
if (callee.qualifier) ref.qualifier = callee.qualifier;
|
|
2292
|
+
if (callee.member) ref.member = true;
|
|
2293
|
+
const n = argCount2(node);
|
|
2294
|
+
if (n !== void 0) ref.argCount = n;
|
|
2295
|
+
push2(ref);
|
|
2296
|
+
return true;
|
|
2297
|
+
}
|
|
2298
|
+
case "type_identifier": {
|
|
2299
|
+
if (field === "name" && parentType && TYPE_DECL_PARENTS.has(parentType)) return false;
|
|
2300
|
+
if (ctx.typeParams.has(node.text)) return false;
|
|
2301
|
+
push2({ name: node.text, kind: "type", line, enclosing: enclosing() });
|
|
2302
|
+
return false;
|
|
2303
|
+
}
|
|
2304
|
+
case "nested_type_identifier": {
|
|
2305
|
+
const module = node.childForFieldName("module");
|
|
2306
|
+
const name = node.childForFieldName("name");
|
|
2307
|
+
if (name) {
|
|
2308
|
+
const ref = { name: name.text, kind: "type", line, enclosing: enclosing() };
|
|
2309
|
+
if (module?.type === "identifier") ref.qualifier = module.text;
|
|
2310
|
+
push2(ref);
|
|
2311
|
+
}
|
|
2312
|
+
return false;
|
|
2313
|
+
}
|
|
2314
|
+
case "jsx_opening_element":
|
|
2315
|
+
case "jsx_self_closing_element": {
|
|
2316
|
+
const callee = calleeRef(node.childForFieldName("name"));
|
|
2317
|
+
if (callee && (callee.member || /^[A-Z]/.test(callee.name))) {
|
|
2318
|
+
const ref = { name: callee.name, kind: "jsx", line, enclosing: enclosing() };
|
|
2319
|
+
if (callee.qualifier) ref.qualifier = callee.qualifier;
|
|
2320
|
+
if (callee.member) ref.member = true;
|
|
2321
|
+
push2(ref);
|
|
2322
|
+
}
|
|
2323
|
+
return true;
|
|
2324
|
+
}
|
|
2325
|
+
case "decorator": {
|
|
2326
|
+
const inner = node.namedChild(0);
|
|
2327
|
+
const callee = calleeRef(
|
|
2328
|
+
inner?.type === "call_expression" ? inner.childForFieldName("function") : inner
|
|
2329
|
+
);
|
|
2330
|
+
if (callee) {
|
|
2331
|
+
const top = stack[stack.length - 1];
|
|
2332
|
+
const scope = top && top.depth === depth - 1 ? stack[stack.length - 2]?.name ?? null : enclosing();
|
|
2333
|
+
const ref = { name: callee.name, kind: "decorator", line, enclosing: scope };
|
|
2334
|
+
if (callee.qualifier) ref.qualifier = callee.qualifier;
|
|
2335
|
+
if (callee.member) ref.member = true;
|
|
2336
|
+
push2(ref);
|
|
2337
|
+
}
|
|
2338
|
+
return true;
|
|
2339
|
+
}
|
|
2340
|
+
case "member_expression":
|
|
2341
|
+
case "subscript_expression": {
|
|
2342
|
+
const env = envName(node);
|
|
2343
|
+
if (env) {
|
|
2344
|
+
ctx.out.envReads.push({ name: env, line });
|
|
2345
|
+
return false;
|
|
2346
|
+
}
|
|
2347
|
+
if (type === "member_expression" && parentType !== "call_expression" && field !== "function") {
|
|
2348
|
+
const obj = node.childForFieldName("object");
|
|
2349
|
+
const prop = node.childForFieldName("property");
|
|
2350
|
+
if (obj?.type === "identifier" && prop && ctx.namespaceLocals.has(obj.text) && parentType !== "new_expression") {
|
|
2351
|
+
push2({ name: prop.text, qualifier: obj.text, kind: "identifier", line, enclosing: enclosing() });
|
|
2352
|
+
return false;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
return true;
|
|
2356
|
+
}
|
|
2357
|
+
case "identifier": {
|
|
2358
|
+
if (!ctx.importLocals.has(node.text)) return false;
|
|
2359
|
+
if (field === "function" || field === "constructor" || field === "name" || field === "object")
|
|
2360
|
+
return false;
|
|
2361
|
+
if (parentType === "decorator" || parentType === "variable_declarator" && field === "name")
|
|
2362
|
+
return false;
|
|
2363
|
+
push2({ name: node.text, kind: "identifier", line, enclosing: enclosing() });
|
|
2364
|
+
return false;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
return true;
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
// ../analysis/src/parse/types.ts
|
|
2371
|
+
function emptyParsed(path, lang, tier) {
|
|
2372
|
+
return { path, lang, tier, symbols: [], refs: [], imports: [], envReads: [], routes: [], facts: [] };
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
// ../analysis/src/parse/index.ts
|
|
2376
|
+
var MAX_FILE_BYTES = 1024 * 1024;
|
|
2377
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
2378
|
+
"node_modules",
|
|
2379
|
+
"dist",
|
|
2380
|
+
"build",
|
|
2381
|
+
".next",
|
|
2382
|
+
"vendor",
|
|
2383
|
+
"__pycache__",
|
|
2384
|
+
".git",
|
|
2385
|
+
".venv",
|
|
2386
|
+
"venv",
|
|
2387
|
+
"target",
|
|
2388
|
+
"coverage",
|
|
2389
|
+
".turbo",
|
|
2390
|
+
".svelte-kit",
|
|
2391
|
+
".nuxt",
|
|
2392
|
+
"out"
|
|
2393
|
+
]);
|
|
2394
|
+
function isSkippedPath(path) {
|
|
2395
|
+
const parts = path.split("/");
|
|
2396
|
+
for (let i = 0; i < parts.length - 1; i++) if (SKIP_DIRS.has(parts[i])) return true;
|
|
2397
|
+
return /\.min\.(js|css)$|\.map$/.test(path);
|
|
2398
|
+
}
|
|
2399
|
+
function looksBinary(content) {
|
|
2400
|
+
const n = Math.min(content.length, 8e3);
|
|
2401
|
+
for (let i = 0; i < n; i++) if (content.charCodeAt(i) === 0) return true;
|
|
2402
|
+
return false;
|
|
2403
|
+
}
|
|
2404
|
+
function isAnalyzable(path) {
|
|
2405
|
+
return !isSkippedPath(path) && (langForPath(path) !== null || isSpecialPath(path));
|
|
2406
|
+
}
|
|
2407
|
+
var parsers = /* @__PURE__ */ new Map();
|
|
2408
|
+
function parserFor(lang) {
|
|
2409
|
+
let p = parsers.get(lang);
|
|
2410
|
+
if (!p) {
|
|
2411
|
+
p = loadLanguage(lang).then((language) => {
|
|
2412
|
+
if (!language) return null;
|
|
2413
|
+
const parser = new Parser();
|
|
2414
|
+
parser.setLanguage(language);
|
|
2415
|
+
return parser;
|
|
2416
|
+
});
|
|
2417
|
+
p.catch(() => parsers.delete(lang));
|
|
2418
|
+
parsers.set(lang, p);
|
|
2419
|
+
}
|
|
2420
|
+
return p;
|
|
2421
|
+
}
|
|
2422
|
+
async function parseFile(path, content) {
|
|
2423
|
+
if (isSkippedPath(path)) return emptyParsed(path, "special", 0);
|
|
2424
|
+
const special = isSpecialPath(path);
|
|
2425
|
+
const tooBig = content.length > MAX_FILE_BYTES;
|
|
2426
|
+
if (tooBig || looksBinary(content)) {
|
|
2427
|
+
const out = emptyParsed(path, "special", 0);
|
|
2428
|
+
out.skipped = tooBig ? "size" : "binary";
|
|
2429
|
+
if (special) out.facts.push(...extractSpecial(path, "").facts.filter((f) => f.kind === "lockfile"));
|
|
2430
|
+
return out;
|
|
2431
|
+
}
|
|
2432
|
+
const lang = langForPath(path);
|
|
2433
|
+
try {
|
|
2434
|
+
const out = lang ? await parseSource(path, lang, content) : emptyParsed(path, "special", 0);
|
|
2435
|
+
if (special) {
|
|
2436
|
+
const extracted = extractSpecial(path, content);
|
|
2437
|
+
out.facts.push(...extracted.facts);
|
|
2438
|
+
out.routes.push(...extracted.routes);
|
|
2439
|
+
}
|
|
2440
|
+
return out;
|
|
2441
|
+
} catch (err) {
|
|
2442
|
+
reportParseError(path, err);
|
|
2443
|
+
const out = emptyParsed(path, lang ?? "special", lang ? LANGS[lang].tier : 0);
|
|
2444
|
+
out.skipped = "error";
|
|
2445
|
+
return out;
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
async function parseSource(path, lang, content) {
|
|
2449
|
+
const spec = LANGS[lang];
|
|
2450
|
+
const out = emptyParsed(path, lang, spec.tier);
|
|
2451
|
+
const parser = await parserFor(lang);
|
|
2452
|
+
if (!parser) return out;
|
|
2453
|
+
const tree = parser.parse(content);
|
|
2454
|
+
if (!tree) return out;
|
|
2455
|
+
try {
|
|
2456
|
+
if (tree.rootNode.hasError) out.partial = true;
|
|
2457
|
+
if (lang === "ts" || lang === "tsx" || lang === "js") extractTypeScript(tree.rootNode, out);
|
|
2458
|
+
else if (lang === "py") extractPython(tree.rootNode, out);
|
|
2459
|
+
else {
|
|
2460
|
+
const { extractTags } = await import("./tags-UPJ5TKHW.js");
|
|
2461
|
+
await extractTags(tree.rootNode, out, lang);
|
|
2462
|
+
}
|
|
2463
|
+
} finally {
|
|
2464
|
+
tree.delete();
|
|
2465
|
+
}
|
|
2466
|
+
return out;
|
|
2467
|
+
}
|
|
2468
|
+
function parseClaimTarget(raw) {
|
|
2469
|
+
if (/^[a-z]+:.+#.+/.test(raw)) return { type: "symbol", symbolId: raw };
|
|
2470
|
+
const hash = raw.indexOf("#");
|
|
2471
|
+
if (hash > 0) {
|
|
2472
|
+
const file = raw.slice(0, hash);
|
|
2473
|
+
return { type: "symbol", symbolId: symbolIdOf(langForPath(file) ?? "txt", file, raw.slice(hash + 1)) };
|
|
2474
|
+
}
|
|
2475
|
+
return { type: "path", glob: raw };
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
// ../analysis/src/changes/index.ts
|
|
2479
|
+
import { isAbsolute, relative } from "path";
|
|
2480
|
+
|
|
2481
|
+
// ../rules/src/config.ts
|
|
2482
|
+
var TIER2_LANGS = /* @__PURE__ */ new Set([
|
|
2483
|
+
"go",
|
|
2484
|
+
"rs",
|
|
2485
|
+
"java",
|
|
2486
|
+
"kt",
|
|
2487
|
+
"swift",
|
|
2488
|
+
"rb",
|
|
2489
|
+
"cs",
|
|
2490
|
+
"php"
|
|
2491
|
+
]);
|
|
2492
|
+
function rulesConfigFrom(config) {
|
|
2493
|
+
return { reportThreshold: config.reportThreshold, rules: config.rules };
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
// ../rules/src/decide.ts
|
|
2497
|
+
function decide(laneId, clashes, mode, opts = {}) {
|
|
2498
|
+
const relevant = clashes.filter((c) => c.state === "open" && c.lanes.includes(laneId));
|
|
2499
|
+
if (relevant.length === 0) return { kind: "allow" };
|
|
2500
|
+
if (mode === "block") {
|
|
2501
|
+
const blocking = relevant.filter(
|
|
2502
|
+
(c) => c.severity === "high" && c.confidence >= 0.9 && opts.introduced?.has(c.id)
|
|
2503
|
+
);
|
|
2504
|
+
if (blocking.length > 0) {
|
|
2505
|
+
return {
|
|
2506
|
+
kind: "deny",
|
|
2507
|
+
clashes: blocking,
|
|
2508
|
+
reason: blocking.map((c) => `${c.summary}
|
|
2509
|
+
${c.suggestion}`).join("\n\n")
|
|
2510
|
+
};
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
return { kind: "warn", clashes: relevant };
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
// ../rules/src/glob.ts
|
|
2517
|
+
var GLOB_CACHE_SIZE = 1e3;
|
|
2518
|
+
var cache = /* @__PURE__ */ new Map();
|
|
2519
|
+
function parse2(glob) {
|
|
2520
|
+
const top = [];
|
|
2521
|
+
const groups = [];
|
|
2522
|
+
let seq = top;
|
|
2523
|
+
for (let i = 0; i < glob.length; i++) {
|
|
2524
|
+
const ch = glob[i];
|
|
2525
|
+
if (ch === "*" && glob[i + 1] === "*") {
|
|
2526
|
+
const slashBefore = i === 0 || glob[i - 1] === "/";
|
|
2527
|
+
const slashAfter = glob[i + 2] === "/";
|
|
2528
|
+
if (slashBefore && slashAfter) {
|
|
2529
|
+
seq.push({ k: "dirs" });
|
|
2530
|
+
i += 2;
|
|
2531
|
+
} else if (slashBefore && i + 2 === glob.length && i > 0) {
|
|
2532
|
+
const last = seq.pop();
|
|
2533
|
+
if (last?.k === "dirs") seq.push({ k: "any" }, { k: "char", c: 47 });
|
|
2534
|
+
else if (last && !(last.k === "char" && last.c === 47)) seq.push(last);
|
|
2535
|
+
seq.push({ k: "tail" });
|
|
2536
|
+
i += 1;
|
|
2537
|
+
} else {
|
|
2538
|
+
seq.push({ k: "any" });
|
|
2539
|
+
i += 1;
|
|
2540
|
+
}
|
|
2541
|
+
} else if (ch === "*") seq.push({ k: "star" });
|
|
2542
|
+
else if (ch === "?") seq.push({ k: "one" });
|
|
2543
|
+
else if (ch === "{" && glob.indexOf("}", i) > i) {
|
|
2544
|
+
const group = { alts: [[]], parent: seq };
|
|
2545
|
+
groups.push(group);
|
|
2546
|
+
seq = group.alts[0];
|
|
2547
|
+
} else if (ch === "}" && groups.length > 0) {
|
|
2548
|
+
const group = groups.pop();
|
|
2549
|
+
group.parent.push({ k: "group", alts: group.alts });
|
|
2550
|
+
seq = group.parent;
|
|
2551
|
+
} else if (ch === "," && groups.length > 0) {
|
|
2552
|
+
const alt = [];
|
|
2553
|
+
groups.at(-1).alts.push(alt);
|
|
2554
|
+
seq = alt;
|
|
2555
|
+
} else seq.push({ k: "char", c: glob.charCodeAt(i) });
|
|
2556
|
+
}
|
|
2557
|
+
while (groups.length > 0) {
|
|
2558
|
+
const group = groups.pop();
|
|
2559
|
+
group.parent.push({ k: "group", alts: group.alts });
|
|
2560
|
+
}
|
|
2561
|
+
return top;
|
|
2562
|
+
}
|
|
2563
|
+
var EQ = 0;
|
|
2564
|
+
var NOT_SLASH = 1;
|
|
2565
|
+
var DOT = 2;
|
|
2566
|
+
var SPLIT = 3;
|
|
2567
|
+
var MATCH = 4;
|
|
2568
|
+
var Automaton = class {
|
|
2569
|
+
kind = [];
|
|
2570
|
+
arg = [];
|
|
2571
|
+
out1 = [];
|
|
2572
|
+
out2 = [];
|
|
2573
|
+
start;
|
|
2574
|
+
/** Per-node generation marks, the current and next state lists, and the closure stack (reused across calls). */
|
|
2575
|
+
mark;
|
|
2576
|
+
lists;
|
|
2577
|
+
stack;
|
|
2578
|
+
generation = 0;
|
|
2579
|
+
/** Literal text every match starts and ends with: most paths are turned away without running the automaton. */
|
|
2580
|
+
prefix;
|
|
2581
|
+
suffix;
|
|
2582
|
+
constructor(glob) {
|
|
2583
|
+
this.start = this.seq(parse2(glob), this.node(MATCH, 0, -1, -1));
|
|
2584
|
+
const n = this.kind.length;
|
|
2585
|
+
this.mark = new Uint32Array(n);
|
|
2586
|
+
this.lists = [new Int32Array(n), new Int32Array(n)];
|
|
2587
|
+
this.stack = new Int32Array(2 * n + 1);
|
|
2588
|
+
const first = glob.search(/[*?{},]/);
|
|
2589
|
+
const last = Math.max(...[..."*?{},"].map((c) => glob.lastIndexOf(c)));
|
|
2590
|
+
this.prefix = glob.slice(0, first).replace(/\/$/, "");
|
|
2591
|
+
this.suffix = glob.slice(last + 1).replace(/^\//, "");
|
|
2592
|
+
}
|
|
2593
|
+
node(kind, arg, out1, out2) {
|
|
2594
|
+
this.kind.push(kind);
|
|
2595
|
+
this.arg.push(arg);
|
|
2596
|
+
this.out1.push(out1);
|
|
2597
|
+
this.out2.push(out2);
|
|
2598
|
+
return this.kind.length - 1;
|
|
2599
|
+
}
|
|
2600
|
+
/** `test` repeated, then `next`. */
|
|
2601
|
+
loop(test, next) {
|
|
2602
|
+
const split = this.node(SPLIT, 0, -1, next);
|
|
2603
|
+
this.out1[split] = this.node(test, 0, split, -1);
|
|
2604
|
+
return split;
|
|
2605
|
+
}
|
|
2606
|
+
/** Builds back to front: each piece's entry node, leading on to `next`. */
|
|
2607
|
+
seq(pieces, next) {
|
|
2608
|
+
let at2 = next;
|
|
2609
|
+
for (let i = pieces.length - 1; i >= 0; i--) at2 = this.piece(pieces[i], at2);
|
|
2610
|
+
return at2;
|
|
2611
|
+
}
|
|
2612
|
+
piece(p, next) {
|
|
2613
|
+
switch (p.k) {
|
|
2614
|
+
case "char":
|
|
2615
|
+
return this.node(EQ, p.c, next, -1);
|
|
2616
|
+
case "one":
|
|
2617
|
+
return this.node(NOT_SLASH, 0, next, -1);
|
|
2618
|
+
case "star":
|
|
2619
|
+
return this.loop(NOT_SLASH, next);
|
|
2620
|
+
case "any":
|
|
2621
|
+
return this.loop(DOT, next);
|
|
2622
|
+
case "dirs":
|
|
2623
|
+
return this.node(SPLIT, 0, this.loop(DOT, this.node(EQ, 47, next, -1)), next);
|
|
2624
|
+
case "tail":
|
|
2625
|
+
return this.node(SPLIT, 0, this.node(EQ, 47, this.loop(DOT, next), -1), next);
|
|
2626
|
+
case "group":
|
|
2627
|
+
return p.alts.map((alt) => this.seq(alt, next)).reduceRight((rest, entry) => this.node(SPLIT, 0, entry, rest));
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
/**
|
|
2631
|
+
* Adds `n` and every node reachable from it without reading a character to `list` (from `size`); returns the
|
|
2632
|
+
* new size. Each node is listed once per step (marked with the step's generation).
|
|
2633
|
+
*/
|
|
2634
|
+
add(list, size, n) {
|
|
2635
|
+
const stack = this.stack;
|
|
2636
|
+
let top = 0;
|
|
2637
|
+
let end = size;
|
|
2638
|
+
stack[top++] = n;
|
|
2639
|
+
while (top > 0) {
|
|
2640
|
+
const x = stack[--top];
|
|
2641
|
+
if (this.mark[x] === this.generation) continue;
|
|
2642
|
+
this.mark[x] = this.generation;
|
|
2643
|
+
if (this.kind[x] === SPLIT) {
|
|
2644
|
+
stack[top++] = this.out2[x];
|
|
2645
|
+
stack[top++] = this.out1[x];
|
|
2646
|
+
} else list[end++] = x;
|
|
2647
|
+
}
|
|
2648
|
+
return end;
|
|
2649
|
+
}
|
|
2650
|
+
test(path) {
|
|
2651
|
+
if (!path.startsWith(this.prefix) || !path.endsWith(this.suffix)) return false;
|
|
2652
|
+
let current = this.lists[0];
|
|
2653
|
+
let next = this.lists[1];
|
|
2654
|
+
this.generation++;
|
|
2655
|
+
let size = this.add(current, 0, this.start);
|
|
2656
|
+
for (let i = 0; i < path.length && size > 0; i++) {
|
|
2657
|
+
const c = path.charCodeAt(i);
|
|
2658
|
+
this.generation++;
|
|
2659
|
+
let nextSize = 0;
|
|
2660
|
+
for (let j = 0; j < size; j++) {
|
|
2661
|
+
const x = current[j];
|
|
2662
|
+
const k = this.kind[x];
|
|
2663
|
+
const ok = k === EQ ? this.arg[x] === c : k === NOT_SLASH ? c !== 47 : k === DOT && c !== 10 && c !== 13 && c !== 8232 && c !== 8233;
|
|
2664
|
+
if (ok) nextSize = this.add(next, nextSize, this.out1[x]);
|
|
2665
|
+
}
|
|
2666
|
+
[current, next] = [next, current];
|
|
2667
|
+
size = nextSize;
|
|
2668
|
+
}
|
|
2669
|
+
for (let j = 0; j < size; j++) if (this.kind[current[j]] === MATCH) return true;
|
|
2670
|
+
return false;
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
function compileGlob(glob) {
|
|
2674
|
+
const cached = cache.get(glob);
|
|
2675
|
+
if (cached) {
|
|
2676
|
+
cache.delete(glob);
|
|
2677
|
+
cache.set(glob, cached);
|
|
2678
|
+
return cached;
|
|
2679
|
+
}
|
|
2680
|
+
const compiled = /[*?{]/.test(glob) ? new Automaton(glob) : { test: (p) => p === glob };
|
|
2681
|
+
cache.set(glob, compiled);
|
|
2682
|
+
if (cache.size > GLOB_CACHE_SIZE) cache.delete(cache.keys().next().value);
|
|
2683
|
+
return compiled;
|
|
2684
|
+
}
|
|
2685
|
+
function matchesGlob(path, glob) {
|
|
2686
|
+
return compileGlob(glob).test(path);
|
|
2687
|
+
}
|
|
2688
|
+
function stem(glob) {
|
|
2689
|
+
return glob.split(/[*?{[]/)[0].replace(/\/$/, "");
|
|
2690
|
+
}
|
|
2691
|
+
function dirStem(glob) {
|
|
2692
|
+
const literal = glob.split(/[*?{[]/)[0];
|
|
2693
|
+
return literal.slice(0, literal.lastIndexOf("/") + 1).replace(/\/$/, "");
|
|
2694
|
+
}
|
|
2695
|
+
function reaches(outer, inner) {
|
|
2696
|
+
if (!outer.includes("**") || !/[*?{[]/.test(inner)) return false;
|
|
2697
|
+
const o = dirStem(outer);
|
|
2698
|
+
const i = dirStem(inner);
|
|
2699
|
+
return o === "" || i === o || i.startsWith(`${o}/`);
|
|
2700
|
+
}
|
|
2701
|
+
function claimTargetsOverlap(a, b) {
|
|
2702
|
+
if (a.type === "symbol" && b.type === "symbol") return a.symbolId === b.symbolId;
|
|
2703
|
+
if (a.type === "path" && b.type === "path") {
|
|
2704
|
+
return a.glob === b.glob || matchesGlob(stem(b.glob), a.glob) || matchesGlob(stem(a.glob), b.glob) || stem(a.glob) === stem(b.glob) || reaches(a.glob, b.glob) || reaches(b.glob, a.glob);
|
|
2705
|
+
}
|
|
2706
|
+
const symbol = a.type === "symbol" ? a.symbolId : b.symbolId;
|
|
2707
|
+
const glob = a.type === "path" ? a.glob : b.glob;
|
|
2708
|
+
const file = parseSymbolId(symbol)?.file;
|
|
2709
|
+
return file !== void 0 && matchesGlob(file, glob);
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
// ../rules/src/detect.ts
|
|
2713
|
+
function pairKey(a, b) {
|
|
2714
|
+
return a < b ? `${a}|${b}` : `${b}|${a}`;
|
|
2715
|
+
}
|
|
2716
|
+
var CALLABLE = /* @__PURE__ */ new Set(["function", "method"]);
|
|
2717
|
+
var EDITS = /* @__PURE__ */ new Set(["body_changed", "signature_changed"]);
|
|
2718
|
+
var GONE = /* @__PURE__ */ new Set(["removed", "renamed", "moved"]);
|
|
2719
|
+
function shortName(symbolId) {
|
|
2720
|
+
const qualified = parseSymbolId(symbolId)?.qualifiedName ?? symbolId;
|
|
2721
|
+
const dot = qualified.lastIndexOf(".");
|
|
2722
|
+
return dot >= 0 && !qualified.startsWith("#", dot + 1) ? qualified.slice(dot + 1) : qualified;
|
|
2723
|
+
}
|
|
2724
|
+
function fileOf(symbolId) {
|
|
2725
|
+
return parseSymbolId(symbolId)?.file ?? symbolId;
|
|
2726
|
+
}
|
|
2727
|
+
function dirname2(path) {
|
|
2728
|
+
const i = path.lastIndexOf("/");
|
|
2729
|
+
return i < 0 ? "" : path.slice(0, i);
|
|
2730
|
+
}
|
|
2731
|
+
function unique(items) {
|
|
2732
|
+
return [...new Set(items)];
|
|
2733
|
+
}
|
|
2734
|
+
function at(r) {
|
|
2735
|
+
return `${r.file}:${r.line}`;
|
|
2736
|
+
}
|
|
2737
|
+
function detectClashes(changeSets, claims, config, opts = {}) {
|
|
2738
|
+
const now = opts.now ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
2739
|
+
const info = new Map((opts.lanes ?? []).map((l) => [l.id, l]));
|
|
2740
|
+
const label = (id) => info.get(id)?.label ?? id;
|
|
2741
|
+
const sets = [...changeSets].sort((a, b) => a.laneId < b.laneId ? -1 : 1);
|
|
2742
|
+
const drafts = [];
|
|
2743
|
+
const ctx = {
|
|
2744
|
+
label,
|
|
2745
|
+
mergeConflicts: opts.mergeConflicts,
|
|
2746
|
+
limit: opts.maxPerPair ?? Number.POSITIVE_INFINITY,
|
|
2747
|
+
listed: opts.maxListed ?? Number.POSITIVE_INFINITY
|
|
2748
|
+
};
|
|
2749
|
+
const only = opts.only?.lanes;
|
|
2750
|
+
for (let i = 0; i < sets.length; i++) {
|
|
2751
|
+
for (let j = i + 1; j < sets.length; j++) {
|
|
2752
|
+
const a = sets[i];
|
|
2753
|
+
const b = sets[j];
|
|
2754
|
+
if (only && !only.has(a.laneId) && !only.has(b.laneId)) continue;
|
|
2755
|
+
const baseA = info.get(a.laneId)?.baseRef;
|
|
2756
|
+
const baseB = info.get(b.laneId)?.baseRef;
|
|
2757
|
+
if (baseA && baseB && baseA !== baseB) continue;
|
|
2758
|
+
drafts.push(...apiRules(a, b, ctx), ...apiRules(b, a, ctx));
|
|
2759
|
+
drafts.push(...sameSymbol(a, b, ctx), ...textOverlap(a, b, ctx), ...specialRules(a, b, ctx));
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
const inScope = (claim, set) => !opts.only || opts.only.lanes.has(set.laneId) || (opts.only.claims?.has(claim.id) ?? false) || (opts.only.claimLanes?.has(claim.laneId) ?? false);
|
|
2763
|
+
drafts.push(...claimConflicts(sets, claims, now, ctx, inScope));
|
|
2764
|
+
return finalize(drafts, config, now, opts.previous ?? []);
|
|
2765
|
+
}
|
|
2766
|
+
function listed(items, max, show) {
|
|
2767
|
+
const shown = items.slice(0, max).map(show).join(", ");
|
|
2768
|
+
return items.length > max ? `${shown} and ${items.length - max} more` : shown;
|
|
2769
|
+
}
|
|
2770
|
+
var laneIndexes = /* @__PURE__ */ new WeakMap();
|
|
2771
|
+
function push(map, key, value) {
|
|
2772
|
+
const list = map.get(key);
|
|
2773
|
+
if (list) list.push(value);
|
|
2774
|
+
else map.set(key, [value]);
|
|
2775
|
+
}
|
|
2776
|
+
function laneIndex(set) {
|
|
2777
|
+
let index = laneIndexes.get(set);
|
|
2778
|
+
if (!index) {
|
|
2779
|
+
index = {
|
|
2780
|
+
byResolved: /* @__PURE__ */ new Map(),
|
|
2781
|
+
byName: /* @__PURE__ */ new Map(),
|
|
2782
|
+
changes: new Map(set.symbolChanges.map((c) => [c.symbolId, c])),
|
|
2783
|
+
bySymbol: /* @__PURE__ */ new Map(),
|
|
2784
|
+
edits: /* @__PURE__ */ new Map(),
|
|
2785
|
+
api: [],
|
|
2786
|
+
apiBySymbol: /* @__PURE__ */ new Map(),
|
|
2787
|
+
apiByName: /* @__PURE__ */ new Map(),
|
|
2788
|
+
files: /* @__PURE__ */ new Map()
|
|
2789
|
+
};
|
|
2790
|
+
for (const r of set.referencesAdded) {
|
|
2791
|
+
const [map, key] = r.resolved !== void 0 ? [index.byResolved, r.resolved] : [index.byName, r.targetName];
|
|
2792
|
+
if (r.resolved === void 0 && r.confidence < 0.8) continue;
|
|
2793
|
+
push(map, key, r);
|
|
2794
|
+
}
|
|
2795
|
+
for (const change of set.symbolChanges) {
|
|
2796
|
+
push(index.bySymbol, change.symbolId, change);
|
|
2797
|
+
if (EDITS.has(change.changeType)) push(index.edits, change.symbolId, change);
|
|
2798
|
+
const isSig = change.changeType === "signature_changed";
|
|
2799
|
+
if (!isSig && !GONE.has(change.changeType)) continue;
|
|
2800
|
+
const rule = !isSig ? "R3" : CALLABLE.has(change.kind) ? "R2" : "R6";
|
|
2801
|
+
if (silenced(change, rule)) continue;
|
|
2802
|
+
const short = shortName(change.symbolId);
|
|
2803
|
+
push(index.apiBySymbol, change.symbolId, index.api.length);
|
|
2804
|
+
push(index.apiByName, short, index.api.length);
|
|
2805
|
+
index.api.push({ change, rule, short });
|
|
2806
|
+
}
|
|
2807
|
+
for (const f of set.files) push(index.files, f.path, f);
|
|
2808
|
+
laneIndexes.set(set, index);
|
|
2809
|
+
}
|
|
2810
|
+
return index;
|
|
2811
|
+
}
|
|
2812
|
+
function apiCandidates(x, y) {
|
|
2813
|
+
if (x.api.length <= y.byResolved.size + y.byName.size)
|
|
2814
|
+
return x.api.filter((a) => y.byResolved.has(a.change.symbolId) || y.byName.has(a.short));
|
|
2815
|
+
const hits = /* @__PURE__ */ new Set();
|
|
2816
|
+
for (const key of y.byResolved.keys()) for (const i of x.apiBySymbol.get(key) ?? []) hits.add(i);
|
|
2817
|
+
for (const key of y.byName.keys()) for (const i of x.apiByName.get(key) ?? []) hits.add(i);
|
|
2818
|
+
return [...hits].sort((a, b) => a - b).map((i) => x.api[i]);
|
|
2819
|
+
}
|
|
2820
|
+
function fits(arity, n, keywords) {
|
|
2821
|
+
if (n < arity.min || arity.max !== null && n > arity.max) return false;
|
|
2822
|
+
const accepted = arity.keywords;
|
|
2823
|
+
return !keywords || !accepted || keywords.every((k) => accepted.includes(k));
|
|
2824
|
+
}
|
|
2825
|
+
function widens(before, after) {
|
|
2826
|
+
return after.min <= before.min && (after.max === null || before.max !== null && after.max >= before.max);
|
|
2827
|
+
}
|
|
2828
|
+
function silenced(item, rule) {
|
|
2829
|
+
return item.suppressedRules?.some((r) => r === "*" || r === rule) ?? false;
|
|
2830
|
+
}
|
|
2831
|
+
function brokenConstructions(change, refs) {
|
|
2832
|
+
const { arityBefore: before, arityAfter: after } = change;
|
|
2833
|
+
if (change.kind !== "class" || !after) return [];
|
|
2834
|
+
return refs.filter(
|
|
2835
|
+
(r) => (r.usage === "call" || r.usage === "new") && r.argCount !== void 0 && !fits(after, r.argCount, r.keywords) && (!before || fits(before, r.argCount, r.keywords))
|
|
2836
|
+
);
|
|
2837
|
+
}
|
|
2838
|
+
function apiRules(x, y, ctx) {
|
|
2839
|
+
const out = [];
|
|
2840
|
+
const xi = laneIndex(x);
|
|
2841
|
+
const yi = laneIndex(y);
|
|
2842
|
+
for (const { change, rule, short: name } of apiCandidates(xi, yi)) {
|
|
2843
|
+
if (out.length >= ctx.limit) break;
|
|
2844
|
+
const isSig = change.changeType === "signature_changed";
|
|
2845
|
+
const refs = [...yi.byResolved.get(change.symbolId) ?? [], ...yi.byName.get(name) ?? []].filter(
|
|
2846
|
+
(r) => !(change.renamedTo && r.resolved === change.renamedTo) && !silenced(r, rule)
|
|
2847
|
+
);
|
|
2848
|
+
if (refs.length === 0) continue;
|
|
2849
|
+
const mirror = yi.changes.get(change.symbolId);
|
|
2850
|
+
if (isSig && mirror?.after?.signatureHash === change.after?.signatureHash) continue;
|
|
2851
|
+
const lx = ctx.label(x.laneId);
|
|
2852
|
+
const ly = ctx.label(y.laneId);
|
|
2853
|
+
const refConfidence = Math.min(
|
|
2854
|
+
0.95,
|
|
2855
|
+
refs.reduce((m, r) => Math.max(m, r.confidence), 0)
|
|
2856
|
+
);
|
|
2857
|
+
const first = refs[0];
|
|
2858
|
+
const uses = listed(refs, ctx.listed, at);
|
|
2859
|
+
const shown = refs.slice(0, ctx.listed);
|
|
2860
|
+
const locations = [
|
|
2861
|
+
change.range ? { laneId: x.laneId, file: fileOf(change.symbolId), line: change.range.startLine } : { laneId: x.laneId, file: fileOf(change.symbolId) },
|
|
2862
|
+
...shown.map((r) => ({ laneId: y.laneId, file: r.file, line: r.line }))
|
|
2863
|
+
];
|
|
2864
|
+
const base = {
|
|
2865
|
+
lanes: [x.laneId, y.laneId],
|
|
2866
|
+
symbols: [change.symbolId],
|
|
2867
|
+
files: unique([fileOf(change.symbolId), ...shown.map((r) => r.file)]),
|
|
2868
|
+
locations,
|
|
2869
|
+
key: [change.symbolId],
|
|
2870
|
+
inputs: JSON.stringify([change.changeType, change.after, change.renamedTo, refs.map(at)])
|
|
2871
|
+
};
|
|
2872
|
+
const broken = brokenConstructions(change, refs);
|
|
2873
|
+
if (GONE.has(change.changeType)) {
|
|
2874
|
+
const target = change.renamedTo;
|
|
2875
|
+
const verb = change.changeType;
|
|
2876
|
+
const where = target ? ` to ${shortName(target)}${change.changeType === "moved" ? ` (${fileOf(target)})` : ""}` : "";
|
|
2877
|
+
out.push({
|
|
2878
|
+
...base,
|
|
2879
|
+
rule: "R3",
|
|
2880
|
+
severity: "high",
|
|
2881
|
+
confidence: refConfidence,
|
|
2882
|
+
summary: `${name} is ${verb}${where} in lane ${lx}, but lane ${ly} adds a use of it at ${at(first)}.`,
|
|
2883
|
+
detail: `Lane ${lx} ${verb} ${change.symbolId}${where}. Lane ${ly} uses ${name} at ${uses}.`,
|
|
2884
|
+
suggestion: target ? `Use ${shortName(target)} from ${fileOf(target)} instead of ${name} at ${at(first)}, or coordinate with lane ${lx}.` : `Don't depend on ${name} at ${at(first)}; it no longer exists in lane ${lx}. Coordinate before merging.`
|
|
2885
|
+
});
|
|
2886
|
+
} else if (CALLABLE.has(change.kind)) {
|
|
2887
|
+
const after = change.arityAfter;
|
|
2888
|
+
const before = change.arityBefore;
|
|
2889
|
+
const compatible = after !== void 0 && refs.every(
|
|
2890
|
+
(r) => r.argCount !== void 0 ? fits(after, r.argCount, r.keywords) : before !== void 0 && widens(before, after)
|
|
2891
|
+
);
|
|
2892
|
+
const newSig = change.signatureText ? `: ${change.signatureText}` : "";
|
|
2893
|
+
out.push({
|
|
2894
|
+
...base,
|
|
2895
|
+
rule: "R2",
|
|
2896
|
+
severity: compatible ? "warn" : "high",
|
|
2897
|
+
confidence: compatible ? 0.6 : refConfidence,
|
|
2898
|
+
summary: compatible ? `${name}'s signature is changing in lane ${lx}; the new call at ${at(first)} in lane ${ly} may still fit it.` : `${name}'s signature is changing in lane ${lx}; the new call at ${at(first)} in lane ${ly} uses the old form.`,
|
|
2899
|
+
detail: `Lane ${lx} changes ${change.symbolId}${newSig}. Lane ${ly} adds ${refs.length === 1 ? "a use" : `${refs.length} uses`} at ${uses}.`,
|
|
2900
|
+
suggestion: `Update the call at ${at(first)} to the new signature of ${name}, or coordinate with lane ${lx} before merging.`
|
|
2901
|
+
});
|
|
2902
|
+
} else if (broken.length > 0) {
|
|
2903
|
+
const newSig = change.signatureText ? `: ${change.signatureText}` : "";
|
|
2904
|
+
out.push({
|
|
2905
|
+
...base,
|
|
2906
|
+
rule: "R2",
|
|
2907
|
+
severity: "high",
|
|
2908
|
+
confidence: broken.reduce((m, r) => Math.min(m, r.confidence), 0.95),
|
|
2909
|
+
summary: `${name}'s constructor is changing in lane ${lx}; the new construction at ${at(broken[0])} in lane ${ly} uses the old form.`,
|
|
2910
|
+
detail: `Lane ${lx} changes the constructor of ${change.symbolId}${newSig}. Lane ${ly} constructs it at ${listed(broken, ctx.listed, at)}.`,
|
|
2911
|
+
suggestion: `Update ${name}(\u2026) at ${at(broken[0])} to the new constructor, or coordinate with lane ${lx} before merging.`
|
|
2912
|
+
});
|
|
2913
|
+
} else {
|
|
2914
|
+
out.push({
|
|
2915
|
+
...base,
|
|
2916
|
+
rule: "R6",
|
|
2917
|
+
severity: "warn",
|
|
2918
|
+
confidence: Math.min(0.8, refConfidence),
|
|
2919
|
+
summary: `The shape of ${change.kind} ${name} is changing in lane ${lx}; lane ${ly} starts using it at ${at(first)}.`,
|
|
2920
|
+
detail: `Lane ${lx} changes the definition of ${change.symbolId}. Lane ${ly} uses it at ${uses}.`,
|
|
2921
|
+
suggestion: `Check the new shape of ${name} in lane ${lx} before relying on its fields at ${at(first)}.`
|
|
2922
|
+
});
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
return out;
|
|
2926
|
+
}
|
|
2927
|
+
function sameSymbol(a, b, ctx) {
|
|
2928
|
+
const out = [];
|
|
2929
|
+
const aEdits = laneIndex(a).edits;
|
|
2930
|
+
const bEdits = laneIndex(b).edits;
|
|
2931
|
+
for (const id of (aEdits.size <= bEdits.size ? aEdits : bEdits).keys()) {
|
|
2932
|
+
if (out.length >= ctx.limit) break;
|
|
2933
|
+
const cb = bEdits.get(id)?.at(-1);
|
|
2934
|
+
if (!cb || silenced(cb, "R1")) continue;
|
|
2935
|
+
const ca = aEdits.get(id)?.find(
|
|
2936
|
+
(c) => !silenced(c, "R1") && !(c.after?.signatureHash === cb.after?.signatureHash && c.after?.bodyHash === cb.after?.bodyHash)
|
|
2937
|
+
);
|
|
2938
|
+
if (!ca) continue;
|
|
2939
|
+
const bothSig = ca.changeType === "signature_changed" && cb.changeType === "signature_changed";
|
|
2940
|
+
const name = shortName(ca.symbolId);
|
|
2941
|
+
const la = ctx.label(a.laneId);
|
|
2942
|
+
const lb = ctx.label(b.laneId);
|
|
2943
|
+
out.push({
|
|
2944
|
+
rule: "R1",
|
|
2945
|
+
severity: bothSig ? "high" : "warn",
|
|
2946
|
+
confidence: 0.9,
|
|
2947
|
+
lanes: [a.laneId, b.laneId],
|
|
2948
|
+
symbols: [ca.symbolId],
|
|
2949
|
+
files: [fileOf(ca.symbolId)],
|
|
2950
|
+
summary: `Lanes ${la} and ${lb} are both changing ${name}${bothSig ? "'s signature" : ""}.`,
|
|
2951
|
+
detail: `Lane ${la}: ${ca.changeType.replace("_", " ")}. Lane ${lb}: ${cb.changeType.replace("_", " ")}. Symbol ${ca.symbolId}.`,
|
|
2952
|
+
suggestion: `Coordinate on ${name}: keep your change minimal, or wait for the other lane (${la}/${lb}) to merge first.`,
|
|
2953
|
+
key: [ca.symbolId],
|
|
2954
|
+
inputs: JSON.stringify([ca.after, cb.after])
|
|
2955
|
+
});
|
|
2956
|
+
}
|
|
2957
|
+
return out;
|
|
2958
|
+
}
|
|
2959
|
+
function span(h) {
|
|
2960
|
+
return h.oldLines === 0 ? [h.oldStart + 0.5, h.oldStart + 0.5] : [h.oldStart - 0.5, h.oldStart + h.oldLines - 0.5];
|
|
2961
|
+
}
|
|
2962
|
+
var spanCache = /* @__PURE__ */ new WeakMap();
|
|
2963
|
+
function mergedSpans(f) {
|
|
2964
|
+
let merged = spanCache.get(f);
|
|
2965
|
+
if (!merged) {
|
|
2966
|
+
const sorted = f.hunks.map(span).sort((x, y) => x[0] - y[0]);
|
|
2967
|
+
const out = [];
|
|
2968
|
+
for (const [s, e] of sorted) {
|
|
2969
|
+
if (out.length > 0 && s <= out[out.length - 1])
|
|
2970
|
+
out[out.length - 1] = Math.max(out[out.length - 1], e);
|
|
2971
|
+
else out.push(s, e);
|
|
2972
|
+
}
|
|
2973
|
+
merged = Float64Array.from(out);
|
|
2974
|
+
spanCache.set(f, merged);
|
|
2975
|
+
}
|
|
2976
|
+
return merged;
|
|
2977
|
+
}
|
|
2978
|
+
function filesOverlap(fa, fb) {
|
|
2979
|
+
if (fa.status === "D" && fb.status === "D") return false;
|
|
2980
|
+
if (fa.status === "D" || fb.status === "D" || fa.status === "A" && fb.status === "A") return true;
|
|
2981
|
+
const a = mergedSpans(fa);
|
|
2982
|
+
const b = mergedSpans(fb);
|
|
2983
|
+
let i = 0;
|
|
2984
|
+
let j = 0;
|
|
2985
|
+
while (i < a.length && j < b.length) {
|
|
2986
|
+
if (a[i + 1] < b[j]) i += 2;
|
|
2987
|
+
else if (b[j + 1] < a[i]) j += 2;
|
|
2988
|
+
else return true;
|
|
2989
|
+
}
|
|
2990
|
+
return false;
|
|
2991
|
+
}
|
|
2992
|
+
function textOverlap(a, b, ctx) {
|
|
2993
|
+
const la = ctx.label(a.laneId);
|
|
2994
|
+
const lb = ctx.label(b.laneId);
|
|
2995
|
+
const draft = (file, confirmed, hunks = null) => ({
|
|
2996
|
+
rule: "R4",
|
|
2997
|
+
severity: confirmed ? "high" : "warn",
|
|
2998
|
+
confidence: confirmed ? 1 : 0.7,
|
|
2999
|
+
lanes: [a.laneId, b.laneId],
|
|
3000
|
+
symbols: [],
|
|
3001
|
+
files: [file],
|
|
3002
|
+
summary: confirmed ? `Lanes ${la} and ${lb} have conflicting edits in ${file}; git cannot merge them.` : `Lanes ${la} and ${lb} are editing the same lines in ${file}.`,
|
|
3003
|
+
detail: confirmed ? `git merge-tree reports a conflict in ${file}.` : `Both lanes change overlapping or adjacent lines of ${file}.`,
|
|
3004
|
+
suggestion: `Lanes ${la} and ${lb} are editing the same lines in ${file}; keep your edit small or let one lane merge first.`,
|
|
3005
|
+
key: [file],
|
|
3006
|
+
inputs: JSON.stringify([file, confirmed, hunks])
|
|
3007
|
+
});
|
|
3008
|
+
const conflicts = ctx.mergeConflicts?.get(pairKey(a.laneId, b.laneId));
|
|
3009
|
+
if (conflicts) return conflicts.slice(0, ctx.limit).map((f) => draft(f, true));
|
|
3010
|
+
if (a.baseCommit !== b.baseCommit) return [];
|
|
3011
|
+
const aFiles = laneIndex(a).files;
|
|
3012
|
+
const bFiles = laneIndex(b).files;
|
|
3013
|
+
const out = [];
|
|
3014
|
+
for (const path of (aFiles.size <= bFiles.size ? aFiles : bFiles).keys()) {
|
|
3015
|
+
if (out.length >= ctx.limit) break;
|
|
3016
|
+
const fb = bFiles.get(path)?.at(-1);
|
|
3017
|
+
const fa = fb && aFiles.get(path)?.find((f) => filesOverlap(f, fb));
|
|
3018
|
+
if (fa && fb) out.push(draft(fa.path, false, [fa.hunks, fb.hunks]));
|
|
3019
|
+
}
|
|
3020
|
+
return out;
|
|
3021
|
+
}
|
|
3022
|
+
function normalizeRoutePath(path) {
|
|
3023
|
+
const parts = path.split("/").filter((p) => p !== "").map((p) => /^(:.+|\{.+\}|\[.+\]|<.+>|\*.*)$/.test(p) ? ":param" : p);
|
|
3024
|
+
return `/${parts.join("/")}`;
|
|
3025
|
+
}
|
|
3026
|
+
function routeScope(file) {
|
|
3027
|
+
const m = /^((?:packages|apps|services|libs)\/[^/]+)\//.exec(file);
|
|
3028
|
+
return m ? m[1] : "";
|
|
3029
|
+
}
|
|
3030
|
+
function specials(set, kind) {
|
|
3031
|
+
return set.special.filter((s) => s.kind === kind);
|
|
3032
|
+
}
|
|
3033
|
+
var migrationIndexes = /* @__PURE__ */ new WeakMap();
|
|
3034
|
+
function migrationIndex(set) {
|
|
3035
|
+
let index = migrationIndexes.get(set);
|
|
3036
|
+
if (!index) {
|
|
3037
|
+
index = { list: specials(set, "migration"), bySeq: /* @__PURE__ */ new Map(), byTable: /* @__PURE__ */ new Map() };
|
|
3038
|
+
index.list.forEach((m, i) => {
|
|
3039
|
+
const dir = m.dir ?? dirname2(m.file);
|
|
3040
|
+
push(index.bySeq, `${dir}\0${m.seq}`, i);
|
|
3041
|
+
if (m.seqType === "timestamp")
|
|
3042
|
+
for (const t of new Set(m.tables)) push(index.byTable, `${dir}\0${t}`, i);
|
|
3043
|
+
});
|
|
3044
|
+
migrationIndexes.set(set, index);
|
|
3045
|
+
}
|
|
3046
|
+
return index;
|
|
3047
|
+
}
|
|
3048
|
+
function specialRules(a, b, ctx) {
|
|
3049
|
+
const la = ctx.label(a.laneId);
|
|
3050
|
+
const lb = ctx.label(b.laneId);
|
|
3051
|
+
const lanes = [a.laneId, b.laneId];
|
|
3052
|
+
const out = [];
|
|
3053
|
+
const migrationsB = migrationIndex(b);
|
|
3054
|
+
for (const ma of specials(a, "migration")) {
|
|
3055
|
+
if (out.length >= ctx.limit) break;
|
|
3056
|
+
const dirA = ma.dir ?? dirname2(ma.file);
|
|
3057
|
+
const candidates = new Set(migrationsB.bySeq.get(`${dirA}\0${ma.seq}`));
|
|
3058
|
+
if (ma.seqType === "timestamp")
|
|
3059
|
+
for (const t of ma.tables)
|
|
3060
|
+
for (const i of migrationsB.byTable.get(`${dirA}\0${t}`) ?? []) candidates.add(i);
|
|
3061
|
+
for (const i of [...candidates].sort((x, y) => x - y)) {
|
|
3062
|
+
const mb = migrationsB.list[i];
|
|
3063
|
+
const shared = ma.tables.filter((t) => mb.tables.includes(t));
|
|
3064
|
+
if (ma.seq === mb.seq) {
|
|
3065
|
+
out.push({
|
|
3066
|
+
rule: "R7",
|
|
3067
|
+
severity: "high",
|
|
3068
|
+
confidence: 0.95,
|
|
3069
|
+
lanes,
|
|
3070
|
+
symbols: [`migration:${dirA}#${ma.seq}`],
|
|
3071
|
+
files: unique([ma.file, mb.file]),
|
|
3072
|
+
summary: `Both lanes add migration ${ma.seq} in ${dirA} (${ma.file} in ${la}, ${mb.file} in ${lb}).`,
|
|
3073
|
+
detail: `Two migrations with the same sequence cannot both apply in order.`,
|
|
3074
|
+
suggestion: `Renumber your migration after the other lane merges, so ${dirA} keeps one ${ma.seq}.`,
|
|
3075
|
+
key: [`${dirA}#${ma.seq}`],
|
|
3076
|
+
inputs: JSON.stringify([ma.file, mb.file])
|
|
3077
|
+
});
|
|
3078
|
+
} else if (ma.seqType === "timestamp" && mb.seqType === "timestamp" && shared.length > 0) {
|
|
3079
|
+
out.push({
|
|
3080
|
+
rule: "R7",
|
|
3081
|
+
severity: "warn",
|
|
3082
|
+
confidence: 0.7,
|
|
3083
|
+
lanes,
|
|
3084
|
+
symbols: shared.map((t) => `table:${t}`),
|
|
3085
|
+
files: unique([ma.file, mb.file]),
|
|
3086
|
+
summary: `Lanes ${la} and ${lb} both add migrations that change table ${shared.join(", ")}.`,
|
|
3087
|
+
detail: `${ma.file} (${la}) and ${mb.file} (${lb}) run in timestamp order; check they don't depend on each other.`,
|
|
3088
|
+
suggestion: `Check the combined migration order for ${shared.join(", ")} before merging.`,
|
|
3089
|
+
key: [`${dirA}#${ma.seq}#${mb.seq}`],
|
|
3090
|
+
inputs: JSON.stringify([ma.file, mb.file, shared])
|
|
3091
|
+
});
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
const depsB = new Map(specials(b, "dependency").map((d) => [`${d.file}|${d.ecosystem}|${d.name}`, d]));
|
|
3096
|
+
for (const da of specials(a, "dependency")) {
|
|
3097
|
+
const db = depsB.get(`${da.file}|${da.ecosystem}|${da.name}`);
|
|
3098
|
+
if (!db || db.after === da.after) continue;
|
|
3099
|
+
const va = da.after ?? "removed";
|
|
3100
|
+
const vb = db.after ?? "removed";
|
|
3101
|
+
out.push({
|
|
3102
|
+
rule: "R8",
|
|
3103
|
+
severity: "warn",
|
|
3104
|
+
confidence: 0.9,
|
|
3105
|
+
lanes,
|
|
3106
|
+
symbols: [`dep:${da.ecosystem}:${da.name}`],
|
|
3107
|
+
files: [da.file],
|
|
3108
|
+
summary: `Both lanes change ${da.name} in ${da.file} (${va} in ${la} vs ${vb} in ${lb}).`,
|
|
3109
|
+
detail: `Lane ${la} sets ${da.name} to ${va}; lane ${lb} sets it to ${vb}.`,
|
|
3110
|
+
suggestion: `Agree on one version of ${da.name} before merging, then regenerate the lockfile once.`,
|
|
3111
|
+
key: [`${da.file}#${da.ecosystem}:${da.name}`],
|
|
3112
|
+
inputs: JSON.stringify([va, vb])
|
|
3113
|
+
});
|
|
3114
|
+
}
|
|
3115
|
+
const locksB = new Set(specials(b, "lockfile").map((l) => l.file));
|
|
3116
|
+
for (const lock of specials(a, "lockfile")) {
|
|
3117
|
+
if (!locksB.has(lock.file)) continue;
|
|
3118
|
+
out.push({
|
|
3119
|
+
rule: "R8",
|
|
3120
|
+
severity: "warn",
|
|
3121
|
+
confidence: 0.9,
|
|
3122
|
+
lanes,
|
|
3123
|
+
symbols: [],
|
|
3124
|
+
files: [lock.file],
|
|
3125
|
+
summary: `Lanes ${la} and ${lb} both modify ${lock.file}.`,
|
|
3126
|
+
detail: `Lockfile edits from two lanes almost always conflict.`,
|
|
3127
|
+
suggestion: `After one lane merges, rebase and regenerate ${lock.file} instead of merging it by hand.`,
|
|
3128
|
+
key: [lock.file],
|
|
3129
|
+
inputs: lock.file
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
const routesB = new Map(
|
|
3133
|
+
specials(b, "route").map((r) => [
|
|
3134
|
+
`${routeScope(r.file)}|${r.method.toUpperCase()} ${normalizeRoutePath(r.path)}`,
|
|
3135
|
+
r
|
|
3136
|
+
])
|
|
3137
|
+
);
|
|
3138
|
+
for (const ra of specials(a, "route")) {
|
|
3139
|
+
const route = `${ra.method.toUpperCase()} ${normalizeRoutePath(ra.path)}`;
|
|
3140
|
+
const rb = routesB.get(`${routeScope(ra.file)}|${route}`);
|
|
3141
|
+
if (!rb) continue;
|
|
3142
|
+
out.push({
|
|
3143
|
+
rule: "R9",
|
|
3144
|
+
severity: "warn",
|
|
3145
|
+
confidence: 0.85,
|
|
3146
|
+
lanes,
|
|
3147
|
+
symbols: [`route:${route}`],
|
|
3148
|
+
files: unique([ra.file, rb.file]),
|
|
3149
|
+
summary: `Both lanes add ${ra.method.toUpperCase()} ${ra.path} (${ra.file} in ${la}, ${rb.file} in ${lb}).`,
|
|
3150
|
+
detail: `Two handlers for one route: only one will win at runtime.`,
|
|
3151
|
+
suggestion: `Pick one handler for ${route}; lanes ${la} and ${lb} should agree which one stays.`,
|
|
3152
|
+
key: [`${routeScope(ra.file)}|${route}`],
|
|
3153
|
+
inputs: JSON.stringify([ra.file, rb.file])
|
|
3154
|
+
});
|
|
3155
|
+
}
|
|
3156
|
+
const envB = new Map(specials(b, "env").map((e) => [`${dirname2(e.file)}|${e.name}`, e]));
|
|
3157
|
+
for (const ea of specials(a, "env")) {
|
|
3158
|
+
const eb = envB.get(`${dirname2(ea.file)}|${ea.name}`);
|
|
3159
|
+
if (!eb || !ea.valueHash || !eb.valueHash || ea.valueHash === eb.valueHash) continue;
|
|
3160
|
+
out.push({
|
|
3161
|
+
rule: "R9",
|
|
3162
|
+
severity: "warn",
|
|
3163
|
+
confidence: 0.85,
|
|
3164
|
+
lanes,
|
|
3165
|
+
symbols: [`env:${ea.name}`],
|
|
3166
|
+
files: unique([ea.file, eb.file]),
|
|
3167
|
+
summary: `Both lanes declare ${ea.name} in ${ea.file} with different values.`,
|
|
3168
|
+
detail: `Lanes ${la} and ${lb} give ${ea.name} different example values, which usually means different meanings.`,
|
|
3169
|
+
suggestion: `Agree on what ${ea.name} means, or rename one of them.`,
|
|
3170
|
+
key: [`${dirname2(ea.file)}|${ea.name}`],
|
|
3171
|
+
inputs: JSON.stringify([ea.valueHash, eb.valueHash])
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
return out.slice(0, ctx.limit);
|
|
3175
|
+
}
|
|
3176
|
+
function claimConflicts(sets, claims, now, ctx, inScope) {
|
|
3177
|
+
const { label } = ctx;
|
|
3178
|
+
const out = [];
|
|
3179
|
+
for (const claim of claims) {
|
|
3180
|
+
if (claim.expiresAt <= now) continue;
|
|
3181
|
+
const target = claimTargetText(claim.target);
|
|
3182
|
+
const matcher = claim.target.type === "path" ? compileGlob(claim.target.glob) : null;
|
|
3183
|
+
for (const set of sets) {
|
|
3184
|
+
if (set.laneId === claim.laneId || !inScope(claim, set)) continue;
|
|
3185
|
+
let symbols = [];
|
|
3186
|
+
let files = [];
|
|
3187
|
+
if (claim.target.type === "symbol") {
|
|
3188
|
+
const symbolId = claim.target.symbolId;
|
|
3189
|
+
if (!laneIndex(set).bySymbol.get(symbolId)?.some((c) => !silenced(c, "R5")))
|
|
3190
|
+
continue;
|
|
3191
|
+
symbols = [symbolId];
|
|
3192
|
+
files = [fileOf(symbolId)];
|
|
3193
|
+
} else if (matcher) {
|
|
3194
|
+
files = set.files.filter((f) => matcher.test(f.path) || f.oldPath !== void 0 && matcher.test(f.oldPath)).map((f) => f.path);
|
|
3195
|
+
if (files.length === 0) continue;
|
|
3196
|
+
}
|
|
3197
|
+
const owner = label(claim.laneId);
|
|
3198
|
+
out.push({
|
|
3199
|
+
rule: "R5",
|
|
3200
|
+
severity: claim.mode === "exclusive" ? "high" : "warn",
|
|
3201
|
+
confidence: 1,
|
|
3202
|
+
lanes: [claim.laneId, set.laneId],
|
|
3203
|
+
symbols,
|
|
3204
|
+
files: files.slice(0, ctx.listed),
|
|
3205
|
+
summary: `Lane ${owner} claimed ${target}${claim.mode === "exclusive" ? " exclusively" : ""} for: "${claim.intent}".`,
|
|
3206
|
+
detail: `Lane ${label(set.laneId)} edits ${listed(files, ctx.listed, String)}, inside that claim (expires ${claim.expiresAt}).`,
|
|
3207
|
+
suggestion: `Avoid ${target} while lane ${owner} works on it, or ask the user before continuing.`,
|
|
3208
|
+
key: [claim.id],
|
|
3209
|
+
inputs: JSON.stringify([files, claim.mode])
|
|
3210
|
+
});
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
return out;
|
|
3214
|
+
}
|
|
3215
|
+
function finalize(drafts, config, now, previous) {
|
|
3216
|
+
const prev = new Map(previous.map((c) => [c.id, c]));
|
|
3217
|
+
const byId = /* @__PURE__ */ new Map();
|
|
3218
|
+
for (const d of drafts) {
|
|
3219
|
+
const override = config.rules[d.rule];
|
|
3220
|
+
if (override?.enabled === false) continue;
|
|
3221
|
+
let severity = override?.severity ?? d.severity;
|
|
3222
|
+
const tier2 = d.symbols.some((s) => TIER2_LANGS.has(s.slice(0, s.indexOf(":"))));
|
|
3223
|
+
if (tier2 && severity === "high") severity = "warn";
|
|
3224
|
+
if (d.confidence < config.reportThreshold) continue;
|
|
3225
|
+
const id = clashId(d.rule, d.lanes, d.key);
|
|
3226
|
+
if (byId.has(id)) continue;
|
|
3227
|
+
const fingerprint = hex16(d.inputs);
|
|
3228
|
+
const old = prev.get(id);
|
|
3229
|
+
const state = old?.state === "suppressed" ? "suppressed" : old?.state === "acknowledged" && old.fingerprint === fingerprint ? "acknowledged" : "open";
|
|
3230
|
+
const clash = {
|
|
3231
|
+
id,
|
|
3232
|
+
rule: d.rule,
|
|
3233
|
+
severity,
|
|
3234
|
+
confidence: d.confidence,
|
|
3235
|
+
lanes: d.lanes,
|
|
3236
|
+
symbols: d.symbols,
|
|
3237
|
+
files: d.files,
|
|
3238
|
+
summary: d.summary,
|
|
3239
|
+
detail: d.detail,
|
|
3240
|
+
suggestion: d.suggestion,
|
|
3241
|
+
firstSeenAt: old?.firstSeenAt ?? now,
|
|
3242
|
+
lastSeenAt: now,
|
|
3243
|
+
state,
|
|
3244
|
+
fingerprint
|
|
3245
|
+
};
|
|
3246
|
+
if (d.locations) clash.locations = d.locations;
|
|
3247
|
+
byId.set(id, clash);
|
|
3248
|
+
}
|
|
3249
|
+
return [...byId.values()].sort(
|
|
3250
|
+
(x, y) => SEVERITY_RANK[y.severity] - SEVERITY_RANK[x.severity] || y.confidence - x.confidence || Number(x.rule.slice(1)) - Number(y.rule.slice(1)) || (x.id < y.id ? -1 : 1)
|
|
3251
|
+
);
|
|
3252
|
+
}
|
|
3253
|
+
|
|
3254
|
+
// ../rules/src/owners.ts
|
|
3255
|
+
function globsOf(pattern) {
|
|
3256
|
+
let p = pattern;
|
|
3257
|
+
const dirOnly = p.endsWith("/");
|
|
3258
|
+
if (dirOnly) p = p.slice(0, -1);
|
|
3259
|
+
const anchored = p.startsWith("/") || p.includes("/");
|
|
3260
|
+
if (p.startsWith("/")) p = p.slice(1);
|
|
3261
|
+
const base = anchored ? p : `**/${p}`;
|
|
3262
|
+
if (dirOnly) return [`${base}/**`];
|
|
3263
|
+
return p.split("/").at(-1)?.includes("*") ? [base] : [base, `${base}/**`];
|
|
3264
|
+
}
|
|
3265
|
+
function parseCodeowners(text) {
|
|
3266
|
+
const rules = [];
|
|
3267
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
3268
|
+
const line = raw.trim();
|
|
3269
|
+
if (!line || line.startsWith("#")) continue;
|
|
3270
|
+
const [pattern, ...rest] = line.split(/\s+/);
|
|
3271
|
+
const owners = rest.filter((o) => !o.startsWith("#") && o.includes("@"));
|
|
3272
|
+
rules.push({ pattern, owners, globs: globsOf(pattern) });
|
|
3273
|
+
}
|
|
3274
|
+
return rules;
|
|
3275
|
+
}
|
|
3276
|
+
function ownersFor(rules, path) {
|
|
3277
|
+
for (let i = rules.length - 1; i >= 0; i--) {
|
|
3278
|
+
const r = rules[i];
|
|
3279
|
+
if (r.globs.some((g) => compileGlob(g).test(path))) return r.owners;
|
|
3280
|
+
}
|
|
3281
|
+
return [];
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
// ../rules/src/plan.ts
|
|
3285
|
+
function planItemSize(cs) {
|
|
3286
|
+
return cs.symbolChanges.length + cs.files.length;
|
|
3287
|
+
}
|
|
3288
|
+
var API_RULES = /* @__PURE__ */ new Set(["R2", "R3", "R6"]);
|
|
3289
|
+
function planMerge(items, clashes) {
|
|
3290
|
+
const byId = new Map(items.map((i) => [i.id, i]));
|
|
3291
|
+
const rank = (a, b) => a.size - b.size || (a.createdAt < b.createdAt ? -1 : a.createdAt > b.createdAt ? 1 : a.id < b.id ? -1 : 1);
|
|
3292
|
+
const out = new Map(items.map((i) => [i.id, /* @__PURE__ */ new Set()]));
|
|
3293
|
+
const edges = [];
|
|
3294
|
+
const reaches2 = (from, to) => {
|
|
3295
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3296
|
+
const stack = [from];
|
|
3297
|
+
while (stack.length) {
|
|
3298
|
+
const n = stack.pop();
|
|
3299
|
+
if (n === to) return true;
|
|
3300
|
+
if (seen.has(n)) continue;
|
|
3301
|
+
seen.add(n);
|
|
3302
|
+
stack.push(...out.get(n));
|
|
3303
|
+
}
|
|
3304
|
+
return false;
|
|
3305
|
+
};
|
|
3306
|
+
const addEdge = (before, after, clash) => {
|
|
3307
|
+
if (out.get(before).has(after)) return;
|
|
3308
|
+
out.get(before).add(after);
|
|
3309
|
+
edges.push({
|
|
3310
|
+
before,
|
|
3311
|
+
after,
|
|
3312
|
+
reason: `${clash.rule} ${RULE_NAMES[clash.rule]}: ${clash.summary}`,
|
|
3313
|
+
clashId: clash.id
|
|
3314
|
+
});
|
|
3315
|
+
};
|
|
3316
|
+
const active = clashes.filter(
|
|
3317
|
+
(c) => (c.state === "open" || c.state === "acknowledged") && byId.has(c.lanes[0]) && byId.has(c.lanes[1])
|
|
3318
|
+
);
|
|
3319
|
+
const soft = [];
|
|
3320
|
+
for (const c of active) {
|
|
3321
|
+
const [a, b] = c.lanes;
|
|
3322
|
+
if (API_RULES.has(c.rule)) addEdge(a, b, c);
|
|
3323
|
+
else if (c.rule === "R7") {
|
|
3324
|
+
const [first, second] = byId.get(a).createdAt <= byId.get(b).createdAt ? [a, b] : [b, a];
|
|
3325
|
+
addEdge(first, second, c);
|
|
3326
|
+
} else soft.push(c);
|
|
3327
|
+
}
|
|
3328
|
+
for (const c of soft) {
|
|
3329
|
+
const [first, second] = rank(byId.get(c.lanes[0]), byId.get(c.lanes[1])) <= 0 ? c.lanes : [c.lanes[1], c.lanes[0]];
|
|
3330
|
+
if (!out.get(second).has(first) && !reaches2(second, first)) addEdge(first, second, c);
|
|
3331
|
+
}
|
|
3332
|
+
const components = stronglyConnected(
|
|
3333
|
+
items.map((i) => i.id),
|
|
3334
|
+
out
|
|
3335
|
+
).map((ids) => ids.map((id) => byId.get(id)).sort(rank));
|
|
3336
|
+
const componentOf = /* @__PURE__ */ new Map();
|
|
3337
|
+
components.forEach((members, c) => {
|
|
3338
|
+
for (const m of members) componentOf.set(m.id, c);
|
|
3339
|
+
});
|
|
3340
|
+
const successors = components.map(() => /* @__PURE__ */ new Set());
|
|
3341
|
+
const indegree = components.map(() => 0);
|
|
3342
|
+
for (const [from, targets] of out) {
|
|
3343
|
+
for (const to of targets) {
|
|
3344
|
+
const a = componentOf.get(from);
|
|
3345
|
+
const b = componentOf.get(to);
|
|
3346
|
+
if (a !== b && !successors[a].has(b)) {
|
|
3347
|
+
successors[a].add(b);
|
|
3348
|
+
indegree[b]++;
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
const ready = components.map((_, c) => c).filter((c) => indegree[c] === 0);
|
|
3353
|
+
const order = [];
|
|
3354
|
+
while (ready.length) {
|
|
3355
|
+
ready.sort((x, y) => rank(components[x][0], components[y][0]));
|
|
3356
|
+
const next = ready.shift();
|
|
3357
|
+
order.push(...components[next].map((m) => m.id));
|
|
3358
|
+
for (const c of successors[next]) if (--indegree[c] === 0) ready.push(c);
|
|
3359
|
+
}
|
|
3360
|
+
const cycles = components.filter((m) => m.length > 1).map((m) => m.map((x) => x.id).sort());
|
|
3361
|
+
const notes = cycles.map(
|
|
3362
|
+
(cycle) => `Lanes ${cycle.join(", ")} depend on each other (cycle): resolve one clash by hand before merging.`
|
|
3363
|
+
);
|
|
3364
|
+
return { order, edges, cycles, notes };
|
|
3365
|
+
}
|
|
3366
|
+
function stronglyConnected(nodes, out) {
|
|
3367
|
+
const index = /* @__PURE__ */ new Map();
|
|
3368
|
+
const low = /* @__PURE__ */ new Map();
|
|
3369
|
+
const onStack = /* @__PURE__ */ new Set();
|
|
3370
|
+
const stack = [];
|
|
3371
|
+
const result = [];
|
|
3372
|
+
let next = 0;
|
|
3373
|
+
const visit = (v) => {
|
|
3374
|
+
index.set(v, next);
|
|
3375
|
+
low.set(v, next++);
|
|
3376
|
+
stack.push(v);
|
|
3377
|
+
onStack.add(v);
|
|
3378
|
+
for (const w of out.get(v)) {
|
|
3379
|
+
if (!index.has(w)) {
|
|
3380
|
+
visit(w);
|
|
3381
|
+
low.set(v, Math.min(low.get(v), low.get(w)));
|
|
3382
|
+
} else if (onStack.has(w)) low.set(v, Math.min(low.get(v), index.get(w)));
|
|
3383
|
+
}
|
|
3384
|
+
if (low.get(v) === index.get(v)) {
|
|
3385
|
+
const component = [];
|
|
3386
|
+
let w;
|
|
3387
|
+
do {
|
|
3388
|
+
w = stack.pop();
|
|
3389
|
+
onStack.delete(w);
|
|
3390
|
+
component.push(w);
|
|
3391
|
+
} while (w !== v);
|
|
3392
|
+
result.push(component);
|
|
3393
|
+
}
|
|
3394
|
+
};
|
|
3395
|
+
for (const n of nodes) if (!index.has(n)) visit(n);
|
|
3396
|
+
return result;
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
// ../rules/pricing.json
|
|
3400
|
+
var pricing_default = {
|
|
3401
|
+
version: 1,
|
|
3402
|
+
unit: "usd_per_million_tokens",
|
|
3403
|
+
note: "Estimates only, and placeholders until set for your plan. Override in .lanekeeper/config.yml under cost.pricing. Rates are USD per million tokens.",
|
|
3404
|
+
models: {
|
|
3405
|
+
"claude-opus-5-5": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
|
|
3406
|
+
"claude-sonnet-5-5": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
3407
|
+
"claude-haiku-5-5": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
|
|
3408
|
+
"claude-fable-5-1": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 }
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
|
|
3412
|
+
// ../rules/src/pricing.ts
|
|
3413
|
+
var ModelRateSchema = external_exports.object({
|
|
3414
|
+
input: external_exports.number().nonnegative(),
|
|
3415
|
+
output: external_exports.number().nonnegative(),
|
|
3416
|
+
cacheRead: external_exports.number().nonnegative(),
|
|
3417
|
+
cacheWrite: external_exports.number().nonnegative()
|
|
3418
|
+
});
|
|
3419
|
+
var PricingSchema = external_exports.object({
|
|
3420
|
+
version: external_exports.number().int(),
|
|
3421
|
+
models: external_exports.record(external_exports.string(), ModelRateSchema)
|
|
3422
|
+
});
|
|
3423
|
+
var DEFAULT_PRICING = PricingSchema.parse(pricing_default);
|
|
3424
|
+
function rateFor(pricing, model) {
|
|
3425
|
+
if (pricing.models[model]) return pricing.models[model];
|
|
3426
|
+
let best = null;
|
|
3427
|
+
for (const [id, rate] of Object.entries(pricing.models))
|
|
3428
|
+
if (model.startsWith(id) && (!best || id.length > best.id.length)) best = { id, rate };
|
|
3429
|
+
return best?.rate ?? null;
|
|
3430
|
+
}
|
|
3431
|
+
function costOf(pricing, u) {
|
|
3432
|
+
const rate = rateFor(pricing, u.model);
|
|
3433
|
+
if (!rate) return null;
|
|
3434
|
+
const M = 1e6;
|
|
3435
|
+
return (u.inputTokens * rate.input + u.outputTokens * rate.output + u.cacheRead * rate.cacheRead + u.cacheWrite * rate.cacheWrite) / M;
|
|
3436
|
+
}
|
|
3437
|
+
function withOverrides(base, overrides) {
|
|
3438
|
+
if (Object.keys(overrides).length === 0) return base;
|
|
3439
|
+
return { version: base.version, models: { ...base.models, ...overrides } };
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
// ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/base.js
|
|
3443
|
+
var Diff = class {
|
|
3444
|
+
diff(oldStr, newStr, options = {}) {
|
|
3445
|
+
let callback;
|
|
3446
|
+
if (typeof options === "function") {
|
|
3447
|
+
callback = options;
|
|
3448
|
+
options = {};
|
|
3449
|
+
} else if ("callback" in options) {
|
|
3450
|
+
callback = options.callback;
|
|
3451
|
+
}
|
|
3452
|
+
const oldString = this.castInput(oldStr, options);
|
|
3453
|
+
const newString = this.castInput(newStr, options);
|
|
3454
|
+
const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
|
|
3455
|
+
const newTokens = this.removeEmpty(this.tokenize(newString, options));
|
|
3456
|
+
return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
|
|
3457
|
+
}
|
|
3458
|
+
diffWithOptionsObj(oldTokens, newTokens, options, callback) {
|
|
3459
|
+
var _a;
|
|
3460
|
+
const done = (value) => {
|
|
3461
|
+
value = this.postProcess(value, options);
|
|
3462
|
+
if (callback) {
|
|
3463
|
+
setTimeout(function() {
|
|
3464
|
+
callback(value);
|
|
3465
|
+
}, 0);
|
|
3466
|
+
return void 0;
|
|
3467
|
+
} else {
|
|
3468
|
+
return value;
|
|
3469
|
+
}
|
|
3470
|
+
};
|
|
3471
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
3472
|
+
let editLength = 1;
|
|
3473
|
+
let maxEditLength = newLen + oldLen;
|
|
3474
|
+
if (options.maxEditLength != null) {
|
|
3475
|
+
maxEditLength = Math.min(maxEditLength, options.maxEditLength);
|
|
3476
|
+
}
|
|
3477
|
+
const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
|
|
3478
|
+
const abortAfterTimestamp = Date.now() + maxExecutionTime;
|
|
3479
|
+
const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
|
|
3480
|
+
let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
|
|
3481
|
+
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
3482
|
+
return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
|
|
3483
|
+
}
|
|
3484
|
+
let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
|
|
3485
|
+
const execEditLength = () => {
|
|
3486
|
+
for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
|
|
3487
|
+
let basePath;
|
|
3488
|
+
const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
|
|
3489
|
+
if (removePath) {
|
|
3490
|
+
bestPath[diagonalPath - 1] = void 0;
|
|
3491
|
+
}
|
|
3492
|
+
let canAdd = false;
|
|
3493
|
+
if (addPath) {
|
|
3494
|
+
const addPathNewPos = addPath.oldPos - diagonalPath;
|
|
3495
|
+
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
|
|
3496
|
+
}
|
|
3497
|
+
const canRemove = removePath && removePath.oldPos + 1 < oldLen;
|
|
3498
|
+
if (!canAdd && !canRemove) {
|
|
3499
|
+
bestPath[diagonalPath] = void 0;
|
|
3500
|
+
continue;
|
|
3501
|
+
}
|
|
3502
|
+
if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
|
|
3503
|
+
basePath = this.addToPath(addPath, true, false, 0, options);
|
|
3504
|
+
} else {
|
|
3505
|
+
basePath = this.addToPath(removePath, false, true, 1, options);
|
|
3506
|
+
}
|
|
3507
|
+
newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
|
|
3508
|
+
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
|
|
3509
|
+
return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
|
|
3510
|
+
} else {
|
|
3511
|
+
bestPath[diagonalPath] = basePath;
|
|
3512
|
+
if (basePath.oldPos + 1 >= oldLen) {
|
|
3513
|
+
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
|
|
3514
|
+
}
|
|
3515
|
+
if (newPos + 1 >= newLen) {
|
|
3516
|
+
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
editLength++;
|
|
3521
|
+
};
|
|
3522
|
+
if (callback) {
|
|
3523
|
+
(function exec() {
|
|
3524
|
+
setTimeout(function() {
|
|
3525
|
+
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
|
|
3526
|
+
return callback(void 0);
|
|
3527
|
+
}
|
|
3528
|
+
if (!execEditLength()) {
|
|
3529
|
+
exec();
|
|
3530
|
+
}
|
|
3531
|
+
}, 0);
|
|
3532
|
+
})();
|
|
3533
|
+
} else {
|
|
3534
|
+
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
|
|
3535
|
+
const ret = execEditLength();
|
|
3536
|
+
if (ret) {
|
|
3537
|
+
return ret;
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
addToPath(path, added, removed, oldPosInc, options) {
|
|
3543
|
+
const last = path.lastComponent;
|
|
3544
|
+
if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
|
|
3545
|
+
return {
|
|
3546
|
+
oldPos: path.oldPos + oldPosInc,
|
|
3547
|
+
lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
|
|
3548
|
+
};
|
|
3549
|
+
} else {
|
|
3550
|
+
return {
|
|
3551
|
+
oldPos: path.oldPos + oldPosInc,
|
|
3552
|
+
lastComponent: { count: 1, added, removed, previousComponent: last }
|
|
3553
|
+
};
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
|
|
3557
|
+
const newLen = newTokens.length, oldLen = oldTokens.length;
|
|
3558
|
+
let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
|
|
3559
|
+
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
|
|
3560
|
+
newPos++;
|
|
3561
|
+
oldPos++;
|
|
3562
|
+
commonCount++;
|
|
3563
|
+
if (options.oneChangePerToken) {
|
|
3564
|
+
basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
if (commonCount && !options.oneChangePerToken) {
|
|
3568
|
+
basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
|
|
3569
|
+
}
|
|
3570
|
+
basePath.oldPos = oldPos;
|
|
3571
|
+
return newPos;
|
|
3572
|
+
}
|
|
3573
|
+
equals(left, right, options) {
|
|
3574
|
+
if (options.comparator) {
|
|
3575
|
+
return options.comparator(left, right);
|
|
3576
|
+
} else {
|
|
3577
|
+
return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
removeEmpty(array) {
|
|
3581
|
+
const ret = [];
|
|
3582
|
+
for (let i = 0; i < array.length; i++) {
|
|
3583
|
+
if (array[i]) {
|
|
3584
|
+
ret.push(array[i]);
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
return ret;
|
|
3588
|
+
}
|
|
3589
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3590
|
+
castInput(value, options) {
|
|
3591
|
+
return value;
|
|
3592
|
+
}
|
|
3593
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3594
|
+
tokenize(value, options) {
|
|
3595
|
+
return Array.from(value);
|
|
3596
|
+
}
|
|
3597
|
+
join(chars) {
|
|
3598
|
+
return chars.join("");
|
|
3599
|
+
}
|
|
3600
|
+
postProcess(changeObjects, options) {
|
|
3601
|
+
return changeObjects;
|
|
3602
|
+
}
|
|
3603
|
+
get useLongestToken() {
|
|
3604
|
+
return false;
|
|
3605
|
+
}
|
|
3606
|
+
buildValues(lastComponent, newTokens, oldTokens) {
|
|
3607
|
+
const components = [];
|
|
3608
|
+
let nextComponent;
|
|
3609
|
+
while (lastComponent) {
|
|
3610
|
+
components.push(lastComponent);
|
|
3611
|
+
nextComponent = lastComponent.previousComponent;
|
|
3612
|
+
delete lastComponent.previousComponent;
|
|
3613
|
+
lastComponent = nextComponent;
|
|
3614
|
+
}
|
|
3615
|
+
components.reverse();
|
|
3616
|
+
const componentLen = components.length;
|
|
3617
|
+
let componentPos = 0, newPos = 0, oldPos = 0;
|
|
3618
|
+
for (; componentPos < componentLen; componentPos++) {
|
|
3619
|
+
const component = components[componentPos];
|
|
3620
|
+
if (!component.removed) {
|
|
3621
|
+
if (!component.added && this.useLongestToken) {
|
|
3622
|
+
let value = newTokens.slice(newPos, newPos + component.count);
|
|
3623
|
+
value = value.map(function(value2, i) {
|
|
3624
|
+
const oldValue = oldTokens[oldPos + i];
|
|
3625
|
+
return oldValue.length > value2.length ? oldValue : value2;
|
|
3626
|
+
});
|
|
3627
|
+
component.value = this.join(value);
|
|
3628
|
+
} else {
|
|
3629
|
+
component.value = this.join(newTokens.slice(newPos, newPos + component.count));
|
|
3630
|
+
}
|
|
3631
|
+
newPos += component.count;
|
|
3632
|
+
if (!component.added) {
|
|
3633
|
+
oldPos += component.count;
|
|
3634
|
+
}
|
|
3635
|
+
} else {
|
|
3636
|
+
component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
|
|
3637
|
+
oldPos += component.count;
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
return components;
|
|
3641
|
+
}
|
|
3642
|
+
};
|
|
3643
|
+
|
|
3644
|
+
// ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/diff/line.js
|
|
3645
|
+
var LineDiff = class extends Diff {
|
|
3646
|
+
constructor() {
|
|
3647
|
+
super(...arguments);
|
|
3648
|
+
this.tokenize = tokenize;
|
|
3649
|
+
}
|
|
3650
|
+
equals(left, right, options) {
|
|
3651
|
+
if (options.ignoreWhitespace) {
|
|
3652
|
+
if (!options.newlineIsToken || !left.includes("\n")) {
|
|
3653
|
+
left = left.trim();
|
|
3654
|
+
}
|
|
3655
|
+
if (!options.newlineIsToken || !right.includes("\n")) {
|
|
3656
|
+
right = right.trim();
|
|
3657
|
+
}
|
|
3658
|
+
} else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
|
|
3659
|
+
if (left.endsWith("\n")) {
|
|
3660
|
+
left = left.slice(0, -1);
|
|
3661
|
+
}
|
|
3662
|
+
if (right.endsWith("\n")) {
|
|
3663
|
+
right = right.slice(0, -1);
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
return super.equals(left, right, options);
|
|
3667
|
+
}
|
|
3668
|
+
};
|
|
3669
|
+
var lineDiff = new LineDiff();
|
|
3670
|
+
function diffLines(oldStr, newStr, options) {
|
|
3671
|
+
return lineDiff.diff(oldStr, newStr, options);
|
|
3672
|
+
}
|
|
3673
|
+
function tokenize(value, options) {
|
|
3674
|
+
if (options.stripTrailingCr) {
|
|
3675
|
+
value = value.replace(/\r\n/g, "\n");
|
|
3676
|
+
}
|
|
3677
|
+
const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
|
|
3678
|
+
if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
|
3679
|
+
linesAndNewlines.pop();
|
|
3680
|
+
}
|
|
3681
|
+
for (let i = 0; i < linesAndNewlines.length; i++) {
|
|
3682
|
+
const line = linesAndNewlines[i];
|
|
3683
|
+
if (i % 2 && !options.newlineIsToken) {
|
|
3684
|
+
retLines[retLines.length - 1] += line;
|
|
3685
|
+
} else {
|
|
3686
|
+
retLines.push(line);
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
return retLines;
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
// ../../node_modules/.pnpm/diff@9.0.0/node_modules/diff/libesm/patch/create.js
|
|
3693
|
+
function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
|
3694
|
+
let optionsObj;
|
|
3695
|
+
if (!options) {
|
|
3696
|
+
optionsObj = {};
|
|
3697
|
+
} else if (typeof options === "function") {
|
|
3698
|
+
optionsObj = { callback: options };
|
|
3699
|
+
} else {
|
|
3700
|
+
optionsObj = options;
|
|
3701
|
+
}
|
|
3702
|
+
if (typeof optionsObj.context === "undefined") {
|
|
3703
|
+
optionsObj.context = 4;
|
|
3704
|
+
}
|
|
3705
|
+
const context = optionsObj.context;
|
|
3706
|
+
if (optionsObj.newlineIsToken) {
|
|
3707
|
+
throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
|
|
3708
|
+
}
|
|
3709
|
+
if (!optionsObj.callback) {
|
|
3710
|
+
return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
|
|
3711
|
+
} else {
|
|
3712
|
+
const { callback } = optionsObj;
|
|
3713
|
+
diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
|
|
3714
|
+
const patch = diffLinesResultToPatch(diff);
|
|
3715
|
+
callback(patch);
|
|
3716
|
+
} }));
|
|
3717
|
+
}
|
|
3718
|
+
function diffLinesResultToPatch(diff) {
|
|
3719
|
+
if (!diff) {
|
|
3720
|
+
return;
|
|
3721
|
+
}
|
|
3722
|
+
diff.push({ value: "", lines: [] });
|
|
3723
|
+
function contextLines(lines) {
|
|
3724
|
+
return lines.map(function(entry) {
|
|
3725
|
+
return " " + entry;
|
|
3726
|
+
});
|
|
3727
|
+
}
|
|
3728
|
+
const hunks = [];
|
|
3729
|
+
let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
|
|
3730
|
+
for (let i = 0; i < diff.length; i++) {
|
|
3731
|
+
const current = diff[i], lines = current.lines || splitLines(current.value);
|
|
3732
|
+
current.lines = lines;
|
|
3733
|
+
if (current.added || current.removed) {
|
|
3734
|
+
if (!oldRangeStart) {
|
|
3735
|
+
const prev = diff[i - 1];
|
|
3736
|
+
oldRangeStart = oldLine;
|
|
3737
|
+
newRangeStart = newLine;
|
|
3738
|
+
if (prev) {
|
|
3739
|
+
curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
|
|
3740
|
+
oldRangeStart -= curRange.length;
|
|
3741
|
+
newRangeStart -= curRange.length;
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
for (const line of lines) {
|
|
3745
|
+
curRange.push((current.added ? "+" : "-") + line);
|
|
3746
|
+
}
|
|
3747
|
+
if (current.added) {
|
|
3748
|
+
newLine += lines.length;
|
|
3749
|
+
} else {
|
|
3750
|
+
oldLine += lines.length;
|
|
3751
|
+
}
|
|
3752
|
+
} else {
|
|
3753
|
+
if (oldRangeStart) {
|
|
3754
|
+
if (lines.length <= context * 2 && i < diff.length - 2) {
|
|
3755
|
+
for (const line of contextLines(lines)) {
|
|
3756
|
+
curRange.push(line);
|
|
3757
|
+
}
|
|
3758
|
+
} else {
|
|
3759
|
+
const contextSize = Math.min(lines.length, context);
|
|
3760
|
+
for (const line of contextLines(lines.slice(0, contextSize))) {
|
|
3761
|
+
curRange.push(line);
|
|
3762
|
+
}
|
|
3763
|
+
const hunk = {
|
|
3764
|
+
oldStart: oldRangeStart,
|
|
3765
|
+
oldLines: oldLine - oldRangeStart + contextSize,
|
|
3766
|
+
newStart: newRangeStart,
|
|
3767
|
+
newLines: newLine - newRangeStart + contextSize,
|
|
3768
|
+
lines: curRange
|
|
3769
|
+
};
|
|
3770
|
+
hunks.push(hunk);
|
|
3771
|
+
oldRangeStart = 0;
|
|
3772
|
+
newRangeStart = 0;
|
|
3773
|
+
curRange = [];
|
|
3774
|
+
}
|
|
3775
|
+
}
|
|
3776
|
+
oldLine += lines.length;
|
|
3777
|
+
newLine += lines.length;
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
for (const hunk of hunks) {
|
|
3781
|
+
for (let i = 0; i < hunk.lines.length; i++) {
|
|
3782
|
+
if (hunk.lines[i].endsWith("\n")) {
|
|
3783
|
+
hunk.lines[i] = hunk.lines[i].slice(0, -1);
|
|
3784
|
+
} else {
|
|
3785
|
+
hunk.lines.splice(i + 1, 0, "\");
|
|
3786
|
+
i++;
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
}
|
|
3790
|
+
return {
|
|
3791
|
+
oldFileName,
|
|
3792
|
+
newFileName,
|
|
3793
|
+
oldHeader,
|
|
3794
|
+
newHeader,
|
|
3795
|
+
hunks
|
|
3796
|
+
};
|
|
3797
|
+
}
|
|
3798
|
+
}
|
|
3799
|
+
function splitLines(text) {
|
|
3800
|
+
const hasTrailingNl = text.endsWith("\n");
|
|
3801
|
+
const result = text.split("\n").map((line) => line + "\n");
|
|
3802
|
+
if (hasTrailingNl) {
|
|
3803
|
+
result.pop();
|
|
3804
|
+
} else {
|
|
3805
|
+
result.push(result.pop().slice(0, -1));
|
|
3806
|
+
}
|
|
3807
|
+
return result;
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
// ../analysis/src/changes/file-changes.ts
|
|
3811
|
+
import { createHash } from "crypto";
|
|
3812
|
+
|
|
3813
|
+
// ../analysis/src/changes/resolve.ts
|
|
3814
|
+
import { posix } from "path";
|
|
3815
|
+
var TS_EXTENSIONS = [".ts", ".tsx", ".d.ts", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts"];
|
|
3816
|
+
var JS_TO_TS = {
|
|
3817
|
+
".js": [".ts", ".tsx"],
|
|
3818
|
+
".jsx": [".tsx"],
|
|
3819
|
+
".mjs": [".mts"],
|
|
3820
|
+
".cjs": [".cts"]
|
|
3821
|
+
};
|
|
3822
|
+
function firstExisting(view, candidates) {
|
|
3823
|
+
for (const c of candidates) if (view.hasPath(c)) return c;
|
|
3824
|
+
return null;
|
|
3825
|
+
}
|
|
3826
|
+
function tsCandidates(base) {
|
|
3827
|
+
const out = [base];
|
|
3828
|
+
const ext = posix.extname(base);
|
|
3829
|
+
for (const alt of JS_TO_TS[ext] ?? []) out.push(base.slice(0, -ext.length) + alt);
|
|
3830
|
+
for (const e of TS_EXTENSIONS) out.push(base + e);
|
|
3831
|
+
for (const e of TS_EXTENSIONS) out.push(`${base}/index${e}`);
|
|
3832
|
+
return out;
|
|
3833
|
+
}
|
|
3834
|
+
function resolveTs(from, source, view) {
|
|
3835
|
+
if (source.startsWith(".")) {
|
|
3836
|
+
const hit = firstExisting(view, tsCandidates(posix.normalize(posix.join(posix.dirname(from), source))));
|
|
3837
|
+
return hit ? { kind: "file", path: hit } : { kind: "missing" };
|
|
3838
|
+
}
|
|
3839
|
+
const ts = view.tsconfig;
|
|
3840
|
+
if (ts) {
|
|
3841
|
+
for (const [pattern, targets] of ts.paths) {
|
|
3842
|
+
const star = pattern.indexOf("*");
|
|
3843
|
+
const prefix = star < 0 ? pattern : pattern.slice(0, star);
|
|
3844
|
+
const suffix = star < 0 ? "" : pattern.slice(star + 1);
|
|
3845
|
+
const matches = star < 0 ? source === pattern : source.startsWith(prefix) && source.endsWith(suffix);
|
|
3846
|
+
if (!matches) continue;
|
|
3847
|
+
const captured = star < 0 ? "" : source.slice(prefix.length, source.length - suffix.length);
|
|
3848
|
+
for (const target of targets) {
|
|
3849
|
+
const rel = posix.normalize(posix.join(ts.baseUrl, target.replace("*", captured)));
|
|
3850
|
+
const hit = firstExisting(view, tsCandidates(rel));
|
|
3851
|
+
if (hit) return { kind: "file", path: hit };
|
|
3852
|
+
}
|
|
3853
|
+
return { kind: "missing" };
|
|
3854
|
+
}
|
|
3855
|
+
const viaBase = firstExisting(view, tsCandidates(posix.normalize(posix.join(ts.baseUrl, source))));
|
|
3856
|
+
if (viaBase) return { kind: "file", path: viaBase };
|
|
3857
|
+
}
|
|
3858
|
+
return { kind: "external" };
|
|
3859
|
+
}
|
|
3860
|
+
function pyModuleFile(view, dir, dotted) {
|
|
3861
|
+
const rel = dotted ? posix.join(dir, ...dotted.split(".")) : dir;
|
|
3862
|
+
return firstExisting(view, [`${rel}.py`, `${rel}.pyi`, `${rel}/__init__.py`]);
|
|
3863
|
+
}
|
|
3864
|
+
function pyRoots(from) {
|
|
3865
|
+
const roots = ["", "src"];
|
|
3866
|
+
const parts = posix.dirname(from).split("/");
|
|
3867
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
3868
|
+
const dir = parts.slice(0, i).join("/");
|
|
3869
|
+
if (dir !== "." && dir !== "src") roots.push(dir);
|
|
3870
|
+
}
|
|
3871
|
+
return roots;
|
|
3872
|
+
}
|
|
3873
|
+
function resolvePy(from, source, view) {
|
|
3874
|
+
const dots = /^\.*/.exec(source)[0].length;
|
|
3875
|
+
if (dots > 0) {
|
|
3876
|
+
let dir = posix.dirname(from);
|
|
3877
|
+
for (let i = 1; i < dots; i++) dir = posix.dirname(dir);
|
|
3878
|
+
const hit = pyModuleFile(view, dir === "." ? "" : dir, source.slice(dots));
|
|
3879
|
+
return hit ? { kind: "file", path: hit } : { kind: "missing" };
|
|
3880
|
+
}
|
|
3881
|
+
for (const root of pyRoots(from)) {
|
|
3882
|
+
const hit = pyModuleFile(view, root, source);
|
|
3883
|
+
if (hit) return { kind: "file", path: hit };
|
|
3884
|
+
}
|
|
3885
|
+
return { kind: "external" };
|
|
3886
|
+
}
|
|
3887
|
+
function resolveModule(from, lang, source, view) {
|
|
3888
|
+
if (lang === "py") return resolvePy(from, source, view);
|
|
3889
|
+
if (lang === "ts" || lang === "tsx" || lang === "js") return resolveTs(from, source, view);
|
|
3890
|
+
return { kind: "external" };
|
|
3891
|
+
}
|
|
3892
|
+
function findExport(path, name, view, depth = 0) {
|
|
3893
|
+
const file = view.file(path);
|
|
3894
|
+
if (!file || depth > 5) return null;
|
|
3895
|
+
const qualified = name === "default" ? file.defaultExport ?? "default" : name;
|
|
3896
|
+
const own = file.symbols.get(qualified);
|
|
3897
|
+
if (own) return own;
|
|
3898
|
+
for (const decl of file.imports) {
|
|
3899
|
+
if (file.lang !== "py" && !decl.reexport) continue;
|
|
3900
|
+
for (const binding of decl.names) {
|
|
3901
|
+
const viaStar = binding.local === "*" && binding.imported === "*";
|
|
3902
|
+
if (!viaStar && binding.local !== name) continue;
|
|
3903
|
+
const target = resolveModule(path, file.lang, decl.source, view);
|
|
3904
|
+
if (target.kind !== "file") continue;
|
|
3905
|
+
const found = findExport(target.path, viaStar ? name : binding.imported, view, depth + 1);
|
|
3906
|
+
if (found) return found;
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
3909
|
+
return null;
|
|
3910
|
+
}
|
|
3911
|
+
function importsByLocal(file) {
|
|
3912
|
+
const map = /* @__PURE__ */ new Map();
|
|
3913
|
+
for (const decl of file.imports) {
|
|
3914
|
+
if (decl.reexport) continue;
|
|
3915
|
+
for (const b of decl.names) if (b.local !== "*") map.set(b.local, { decl, imported: b.imported });
|
|
3916
|
+
}
|
|
3917
|
+
return map;
|
|
3918
|
+
}
|
|
3919
|
+
function referenceResolver(file, view) {
|
|
3920
|
+
const imports = importsByLocal(file);
|
|
3921
|
+
const own = view.file(file.path);
|
|
3922
|
+
const ownSymbols = new Map(file.symbols.map((s) => [s.qualifiedName, s.id]));
|
|
3923
|
+
const ownSymbol = (qualified) => ownSymbols.get(qualified) ?? own?.symbols.get(qualified) ?? null;
|
|
3924
|
+
const star = file.imports.filter(
|
|
3925
|
+
(d) => !d.reexport && d.names.some((b) => b.local === "*" && b.imported === "*")
|
|
3926
|
+
);
|
|
3927
|
+
const module = (source) => resolveModule(file.path, file.lang, source, view);
|
|
3928
|
+
const pythonSubmodule = (imp) => {
|
|
3929
|
+
if (file.lang !== "py" || imp.imported === "*") return null;
|
|
3930
|
+
const pkg = module(imp.decl.source);
|
|
3931
|
+
if (pkg.kind === "file" && findExport(pkg.path, imp.imported, view)) return null;
|
|
3932
|
+
const source = /^\.+$/.test(imp.decl.source) ? `${imp.decl.source}${imp.imported}` : `${imp.decl.source}.${imp.imported}`;
|
|
3933
|
+
return module(source).kind === "file" ? { decl: { ...imp.decl, source }, imported: "*" } : null;
|
|
3934
|
+
};
|
|
3935
|
+
const viaImport = (local, member) => {
|
|
3936
|
+
const found = imports.get(local);
|
|
3937
|
+
if (!found) return void 0;
|
|
3938
|
+
const imp = pythonSubmodule(found) ?? found;
|
|
3939
|
+
const target = module(imp.decl.source);
|
|
3940
|
+
if (target.kind !== "file") return null;
|
|
3941
|
+
if (imp.imported === "*") {
|
|
3942
|
+
if (!member) return null;
|
|
3943
|
+
const id2 = findExport(target.path, member, view);
|
|
3944
|
+
return id2 ? { resolved: id2, confidence: 0.95 } : null;
|
|
3945
|
+
}
|
|
3946
|
+
const id = findExport(target.path, imp.imported, view);
|
|
3947
|
+
if (!id) return null;
|
|
3948
|
+
if (!member) return { resolved: id, confidence: 0.95 };
|
|
3949
|
+
const at2 = parseSymbolId(id);
|
|
3950
|
+
const memberId = at2 ? view.file(at2.file)?.symbols.get(`${at2.qualifiedName}.${member}`) : void 0;
|
|
3951
|
+
return memberId ? { resolved: memberId, confidence: 0.95 } : null;
|
|
3952
|
+
};
|
|
3953
|
+
return (ref) => {
|
|
3954
|
+
if (ref.qualifier !== void 0) {
|
|
3955
|
+
const q = ref.qualifier;
|
|
3956
|
+
if (q === "this" || q === "self" || q === "cls") {
|
|
3957
|
+
const cls = ref.enclosing?.split(".").slice(0, -1).join(".");
|
|
3958
|
+
const id = cls ? ownSymbol(`${cls}.${ref.name}`) : null;
|
|
3959
|
+
return id ? { resolved: id, confidence: 0.95 } : null;
|
|
3960
|
+
}
|
|
3961
|
+
const imported2 = viaImport(q, ref.name);
|
|
3962
|
+
if (imported2 !== void 0) return imported2;
|
|
3963
|
+
const local2 = ownSymbol(`${q}.${ref.name}`);
|
|
3964
|
+
return local2 ? { resolved: local2, confidence: 0.95 } : null;
|
|
3965
|
+
}
|
|
3966
|
+
if (ref.member) return null;
|
|
3967
|
+
const imported = viaImport(ref.name);
|
|
3968
|
+
if (imported !== void 0) return imported;
|
|
3969
|
+
const local = ownSymbol(ref.name);
|
|
3970
|
+
if (local) return { resolved: local, confidence: 0.95 };
|
|
3971
|
+
for (const decl of star) {
|
|
3972
|
+
const target = module(decl.source);
|
|
3973
|
+
const id = target.kind === "file" ? findExport(target.path, ref.name, view) : null;
|
|
3974
|
+
if (id) return { resolved: id, confidence: 0.95 };
|
|
3975
|
+
}
|
|
3976
|
+
if (!guessesBareNames(file)) return null;
|
|
3977
|
+
const candidates = view.lookupName(ref.name).filter((id) => id.startsWith(`${file.lang}:`) || sameFamily(file.lang, id));
|
|
3978
|
+
if (candidates.length === 1) return { resolved: candidates[0], confidence: 0.8 };
|
|
3979
|
+
if (candidates.length > 1) return { confidence: 0.4 };
|
|
3980
|
+
return null;
|
|
3981
|
+
};
|
|
3982
|
+
}
|
|
3983
|
+
function guessesBareNames(file) {
|
|
3984
|
+
if (file.lang === "ts" || file.lang === "tsx" || file.lang === "py") return false;
|
|
3985
|
+
if (file.lang === "js") return file.imports.length === 0 && !file.symbols.some((s) => s.exported);
|
|
3986
|
+
return true;
|
|
3987
|
+
}
|
|
3988
|
+
var JS_FAMILY = /* @__PURE__ */ new Set(["ts", "tsx", "js"]);
|
|
3989
|
+
function sameFamily(lang, id) {
|
|
3990
|
+
return JS_FAMILY.has(lang) && JS_FAMILY.has(id.slice(0, id.indexOf(":")));
|
|
3991
|
+
}
|
|
3992
|
+
|
|
3993
|
+
// ../analysis/src/changes/file-changes.ts
|
|
3994
|
+
var SUPPRESS = /lanekeeper-ignore\b(?:[\s:]+((?:R\d+[\s,]*)+))?/;
|
|
3995
|
+
var COMMENT_ONLY = /^(\/\/|#|\/\*|--|\*)*$/;
|
|
3996
|
+
function parseSuppressions(content) {
|
|
3997
|
+
const out = /* @__PURE__ */ new Map();
|
|
3998
|
+
const lines = content.split("\n");
|
|
3999
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4000
|
+
const line = lines[i];
|
|
4001
|
+
const m = SUPPRESS.exec(line);
|
|
4002
|
+
if (!m) continue;
|
|
4003
|
+
const rules = (m[1] ?? "").match(/R\d+/g) ?? [];
|
|
4004
|
+
out.set(i + 1, rules);
|
|
4005
|
+
if (COMMENT_ONLY.test(line.slice(0, m.index).trim())) out.set(i + 2, rules);
|
|
4006
|
+
}
|
|
4007
|
+
return out;
|
|
4008
|
+
}
|
|
4009
|
+
function suppressedAt(s, line) {
|
|
4010
|
+
const rules = s.get(line);
|
|
4011
|
+
if (rules === void 0) return void 0;
|
|
4012
|
+
return rules.length === 0 ? ["*"] : rules;
|
|
4013
|
+
}
|
|
4014
|
+
function refKeyOf(r) {
|
|
4015
|
+
return `${r.usage ?? ""}|${r.resolved ?? `?${r.targetName}`}`;
|
|
4016
|
+
}
|
|
4017
|
+
function subtractRefs(candidates, baseKeys) {
|
|
4018
|
+
const counts = /* @__PURE__ */ new Map();
|
|
4019
|
+
for (const k of baseKeys) counts.set(k, (counts.get(k) ?? 0) + 1);
|
|
4020
|
+
const out = [];
|
|
4021
|
+
for (const r of candidates) {
|
|
4022
|
+
const key = refKeyOf(r);
|
|
4023
|
+
const n = counts.get(key) ?? 0;
|
|
4024
|
+
if (n > 0) counts.set(key, n - 1);
|
|
4025
|
+
else out.push(r);
|
|
4026
|
+
}
|
|
4027
|
+
return out;
|
|
4028
|
+
}
|
|
4029
|
+
function resolveAll(laneId, path, file, view) {
|
|
4030
|
+
const resolve = referenceResolver(file, view);
|
|
4031
|
+
const out = [];
|
|
4032
|
+
for (const r of file.refs) {
|
|
4033
|
+
const res = resolve(r);
|
|
4034
|
+
if (!res) continue;
|
|
4035
|
+
const ref = {
|
|
4036
|
+
laneId,
|
|
4037
|
+
fromSymbolId: r.enclosing ? symbolIdOf(file.lang, path, r.enclosing) : null,
|
|
4038
|
+
file: path,
|
|
4039
|
+
line: r.line,
|
|
4040
|
+
targetName: r.name,
|
|
4041
|
+
confidence: res.confidence,
|
|
4042
|
+
usage: r.kind
|
|
4043
|
+
};
|
|
4044
|
+
if (res.resolved) ref.resolved = res.resolved;
|
|
4045
|
+
if (r.argCount !== void 0) ref.argCount = r.argCount;
|
|
4046
|
+
if (r.keywords) ref.keywords = r.keywords;
|
|
4047
|
+
out.push(ref);
|
|
4048
|
+
}
|
|
4049
|
+
return out;
|
|
4050
|
+
}
|
|
4051
|
+
function hashes(s) {
|
|
4052
|
+
return { signatureHash: s.signatureHash, bodyHash: s.bodyHash };
|
|
4053
|
+
}
|
|
4054
|
+
function symbolChange(laneId, s, changeType, before) {
|
|
4055
|
+
const c = { laneId, symbolId: s.id, kind: s.kind, changeType, exported: s.exported };
|
|
4056
|
+
if (before) c.before = hashes(before);
|
|
4057
|
+
if (changeType === "removed") c.before = hashes(s);
|
|
4058
|
+
else c.after = hashes(s);
|
|
4059
|
+
if (changeType !== "removed") {
|
|
4060
|
+
if (s.signatureText) c.signatureText = s.signatureText;
|
|
4061
|
+
c.range = s.range;
|
|
4062
|
+
if (s.arity) c.arityAfter = s.arity;
|
|
4063
|
+
}
|
|
4064
|
+
const arityBefore = changeType === "removed" ? s.arity : before?.arity;
|
|
4065
|
+
if (arityBefore) c.arityBefore = arityBefore;
|
|
4066
|
+
return c;
|
|
4067
|
+
}
|
|
4068
|
+
function specialChanges(path, before, after) {
|
|
4069
|
+
const out = [];
|
|
4070
|
+
const factsBefore = before?.facts ?? [];
|
|
4071
|
+
const factsAfter = after?.facts ?? [];
|
|
4072
|
+
const of = (facts, kind) => facts.filter((f) => f.kind === kind);
|
|
4073
|
+
const hadMigration = new Set(of(factsBefore, "migration").map((m) => m.file));
|
|
4074
|
+
for (const m of of(factsAfter, "migration")) {
|
|
4075
|
+
if (!hadMigration.has(m.file))
|
|
4076
|
+
out.push({
|
|
4077
|
+
kind: "migration",
|
|
4078
|
+
file: m.file,
|
|
4079
|
+
dir: m.dir,
|
|
4080
|
+
seq: m.seq,
|
|
4081
|
+
seqType: m.seqType,
|
|
4082
|
+
tables: m.tables
|
|
4083
|
+
});
|
|
4084
|
+
}
|
|
4085
|
+
const depKey = (d) => `${d.ecosystem}|${d.name}`;
|
|
4086
|
+
const depsBefore = new Map(of(factsBefore, "dependency").map((d) => [depKey(d), d]));
|
|
4087
|
+
const depsAfter = new Map(of(factsAfter, "dependency").map((d) => [depKey(d), d]));
|
|
4088
|
+
for (const [key, d] of depsAfter) {
|
|
4089
|
+
const old = depsBefore.get(key);
|
|
4090
|
+
if (old?.version === d.version) continue;
|
|
4091
|
+
out.push(
|
|
4092
|
+
old ? {
|
|
4093
|
+
kind: "dependency",
|
|
4094
|
+
file: path,
|
|
4095
|
+
ecosystem: d.ecosystem,
|
|
4096
|
+
name: d.name,
|
|
4097
|
+
before: old.version,
|
|
4098
|
+
after: d.version
|
|
4099
|
+
} : { kind: "dependency", file: path, ecosystem: d.ecosystem, name: d.name, after: d.version }
|
|
4100
|
+
);
|
|
4101
|
+
}
|
|
4102
|
+
for (const [key, d] of depsBefore) {
|
|
4103
|
+
if (!depsAfter.has(key))
|
|
4104
|
+
out.push({ kind: "dependency", file: path, ecosystem: d.ecosystem, name: d.name, before: d.version });
|
|
4105
|
+
}
|
|
4106
|
+
if (of(factsAfter, "lockfile").length > 0 || of(factsBefore, "lockfile").length > 0)
|
|
4107
|
+
out.push({ kind: "lockfile", file: path });
|
|
4108
|
+
const envBefore = new Map(of(factsBefore, "env").map((e) => [e.name, e.valueHash]));
|
|
4109
|
+
for (const e of of(factsAfter, "env")) {
|
|
4110
|
+
if (envBefore.has(e.name) && envBefore.get(e.name) === e.valueHash) continue;
|
|
4111
|
+
out.push(
|
|
4112
|
+
e.valueHash === void 0 ? { kind: "env", file: path, name: e.name } : { kind: "env", file: path, name: e.name, valueHash: e.valueHash }
|
|
4113
|
+
);
|
|
4114
|
+
}
|
|
4115
|
+
const routeKey = (r) => `${r.method.toUpperCase()} ${r.path}`;
|
|
4116
|
+
const routesBefore = new Set((before?.routes ?? []).map(routeKey));
|
|
4117
|
+
const seenRoutes = /* @__PURE__ */ new Set();
|
|
4118
|
+
for (const r of after?.routes ?? []) {
|
|
4119
|
+
const key = routeKey(r);
|
|
4120
|
+
if (routesBefore.has(key) || seenRoutes.has(key)) continue;
|
|
4121
|
+
seenRoutes.add(key);
|
|
4122
|
+
out.push({ kind: "route", file: path, method: r.method.toUpperCase(), path: r.path });
|
|
4123
|
+
}
|
|
4124
|
+
const readsBefore = new Set((before?.envReads ?? []).map((e) => e.name));
|
|
4125
|
+
const seenReads = /* @__PURE__ */ new Set();
|
|
4126
|
+
for (const e of after?.envReads ?? []) {
|
|
4127
|
+
if (readsBefore.has(e.name) || seenReads.has(e.name)) continue;
|
|
4128
|
+
seenReads.add(e.name);
|
|
4129
|
+
out.push({ kind: "env", file: path, name: e.name });
|
|
4130
|
+
}
|
|
4131
|
+
return out;
|
|
4132
|
+
}
|
|
4133
|
+
function diffFile(input) {
|
|
4134
|
+
const { laneId, path, before, after, view } = input;
|
|
4135
|
+
const result = {
|
|
4136
|
+
changes: [],
|
|
4137
|
+
removed: [],
|
|
4138
|
+
added: [],
|
|
4139
|
+
suppressedSymbols: /* @__PURE__ */ new Map(),
|
|
4140
|
+
refs: [],
|
|
4141
|
+
baseRefKeys: [],
|
|
4142
|
+
special: specialChanges(path, before, after)
|
|
4143
|
+
};
|
|
4144
|
+
if (before?.skipped || after?.skipped) return result;
|
|
4145
|
+
const supp = input.afterContent ? parseSuppressions(input.afterContent) : /* @__PURE__ */ new Map();
|
|
4146
|
+
const partial = before?.partial === true || after?.partial === true;
|
|
4147
|
+
const beforeSyms = new Map((before?.symbols ?? []).map((s) => [s.qualifiedName, s]));
|
|
4148
|
+
const afterSyms = new Map((after?.symbols ?? []).map((s) => [s.qualifiedName, s]));
|
|
4149
|
+
for (const [name, a] of afterSyms) {
|
|
4150
|
+
const silenced2 = suppressedAt(supp, a.range.startLine);
|
|
4151
|
+
const b = beforeSyms.get(name);
|
|
4152
|
+
let change = null;
|
|
4153
|
+
if (b && b.id === a.id) {
|
|
4154
|
+
if (b.signatureHash !== a.signatureHash) change = symbolChange(laneId, a, "signature_changed", b);
|
|
4155
|
+
else if (b.bodyHash !== a.bodyHash) change = symbolChange(laneId, a, "body_changed", b);
|
|
4156
|
+
} else if (!partial) {
|
|
4157
|
+
result.added.push(a);
|
|
4158
|
+
if (silenced2) result.suppressedSymbols.set(a.id, silenced2);
|
|
4159
|
+
}
|
|
4160
|
+
if (change) {
|
|
4161
|
+
if (silenced2) change.suppressedRules = silenced2;
|
|
4162
|
+
result.changes.push(change);
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
if (!partial) {
|
|
4166
|
+
for (const [name, b] of beforeSyms) {
|
|
4167
|
+
const a = afterSyms.get(name);
|
|
4168
|
+
if (!a || a.id !== b.id) result.removed.push(b);
|
|
4169
|
+
}
|
|
4170
|
+
}
|
|
4171
|
+
if (after) {
|
|
4172
|
+
result.refs = resolveAll(laneId, path, after, view);
|
|
4173
|
+
for (const r of result.refs) {
|
|
4174
|
+
const silenced2 = suppressedAt(supp, r.line);
|
|
4175
|
+
if (silenced2) r.suppressedRules = silenced2;
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
if (before)
|
|
4179
|
+
result.baseRefKeys = resolveAll(laneId, input.oldPath ?? path, before, input.baseView).map(refKeyOf);
|
|
4180
|
+
return result;
|
|
4181
|
+
}
|
|
4182
|
+
var TOKEN = /[A-Za-z_$][\w$]*|\d+|[^\s\w]/g;
|
|
4183
|
+
function bodyTokens(content, s) {
|
|
4184
|
+
if (!content) return /* @__PURE__ */ new Set();
|
|
4185
|
+
const text = content.split("\n").slice(s.range.startLine - 1, s.range.endLine).join("\n");
|
|
4186
|
+
const tokens = new Set(text.match(TOKEN) ?? []);
|
|
4187
|
+
tokens.delete(s.name);
|
|
4188
|
+
return tokens;
|
|
4189
|
+
}
|
|
4190
|
+
function jaccard(a, b) {
|
|
4191
|
+
let inter = 0;
|
|
4192
|
+
for (const t of a) if (b.has(t)) inter++;
|
|
4193
|
+
return inter / (a.size + b.size - inter || 1);
|
|
4194
|
+
}
|
|
4195
|
+
var MIN_RENAME_TOKENS = 8;
|
|
4196
|
+
function pairRenames(laneId, removed, added, contents, suppressed = /* @__PURE__ */ new Map()) {
|
|
4197
|
+
const out = [];
|
|
4198
|
+
const free = new Set(added);
|
|
4199
|
+
const tokenCache = /* @__PURE__ */ new Map();
|
|
4200
|
+
const tokens = (s, side) => {
|
|
4201
|
+
let t = tokenCache.get(s);
|
|
4202
|
+
if (!t) {
|
|
4203
|
+
t = bodyTokens(contents[side](s.file), s);
|
|
4204
|
+
tokenCache.set(s, t);
|
|
4205
|
+
}
|
|
4206
|
+
return t;
|
|
4207
|
+
};
|
|
4208
|
+
for (const r of removed) {
|
|
4209
|
+
const rt = tokens(r, "before");
|
|
4210
|
+
let best = null;
|
|
4211
|
+
let bestScore = 0;
|
|
4212
|
+
if (rt.size >= MIN_RENAME_TOKENS) {
|
|
4213
|
+
for (const a of free) {
|
|
4214
|
+
if (a.kind !== r.kind || a.qualifiedName.includes(".") !== r.qualifiedName.includes(".")) continue;
|
|
4215
|
+
const score = a.bodyHash === r.bodyHash ? 1 : jaccard(rt, tokens(a, "after"));
|
|
4216
|
+
const sameFileBonus = a.file === r.file ? 1e-3 : 0;
|
|
4217
|
+
if (score >= 0.85 && score + sameFileBonus > bestScore) {
|
|
4218
|
+
best = a;
|
|
4219
|
+
bestScore = score + sameFileBonus;
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
if (best) {
|
|
4224
|
+
free.delete(best);
|
|
4225
|
+
const c = symbolChange(laneId, r, "removed");
|
|
4226
|
+
c.changeType = best.file === r.file ? "renamed" : "moved";
|
|
4227
|
+
c.renamedTo = best.id;
|
|
4228
|
+
c.after = hashes(best);
|
|
4229
|
+
if (best.arity) c.arityAfter = best.arity;
|
|
4230
|
+
const silenced2 = suppressed.get(best.id);
|
|
4231
|
+
if (silenced2) c.suppressedRules = silenced2;
|
|
4232
|
+
out.push(c);
|
|
4233
|
+
} else out.push(symbolChange(laneId, r, "removed"));
|
|
4234
|
+
}
|
|
4235
|
+
for (const a of free) {
|
|
4236
|
+
const c = symbolChange(laneId, a, "added");
|
|
4237
|
+
const silenced2 = suppressed.get(a.id);
|
|
4238
|
+
if (silenced2) c.suppressedRules = silenced2;
|
|
4239
|
+
out.push(c);
|
|
4240
|
+
}
|
|
4241
|
+
return out;
|
|
4242
|
+
}
|
|
4243
|
+
function contentKey(content) {
|
|
4244
|
+
return hex16(content);
|
|
4245
|
+
}
|
|
4246
|
+
function gitBlobOid(content) {
|
|
4247
|
+
return createHash("sha1").update(`blob ${Buffer.byteLength(content)}\0`).update(content).digest("hex");
|
|
4248
|
+
}
|
|
4249
|
+
|
|
4250
|
+
// ../analysis/src/changes/symbol-index.ts
|
|
4251
|
+
var INDEX_BATCH = 2e3;
|
|
4252
|
+
var MemoryParseCache = class {
|
|
4253
|
+
map = /* @__PURE__ */ new Map();
|
|
4254
|
+
limit;
|
|
4255
|
+
constructor(limit = 2e4) {
|
|
4256
|
+
this.limit = limit;
|
|
4257
|
+
}
|
|
4258
|
+
get(path, key) {
|
|
4259
|
+
return this.map.get(`${path}\0${key}`);
|
|
4260
|
+
}
|
|
4261
|
+
set(path, key, parsed) {
|
|
4262
|
+
if (this.map.size >= this.limit) this.map.delete(this.map.keys().next().value);
|
|
4263
|
+
this.map.set(`${path}\0${key}`, parsed);
|
|
4264
|
+
}
|
|
4265
|
+
};
|
|
4266
|
+
async function parseCached(cache2, path, key, content) {
|
|
4267
|
+
const hit = cache2.get(path, key);
|
|
4268
|
+
if (hit) return hit;
|
|
4269
|
+
const parsed = await parseFile(path, content);
|
|
4270
|
+
cache2.set(path, key, parsed);
|
|
4271
|
+
return parsed;
|
|
4272
|
+
}
|
|
4273
|
+
function toIndexed(parsed) {
|
|
4274
|
+
const file = {
|
|
4275
|
+
path: parsed.path,
|
|
4276
|
+
lang: parsed.lang,
|
|
4277
|
+
symbols: new Map(parsed.symbols.map((s) => [s.qualifiedName, s.id])),
|
|
4278
|
+
imports: parsed.imports
|
|
4279
|
+
};
|
|
4280
|
+
if (parsed.defaultExport) file.defaultExport = parsed.defaultExport;
|
|
4281
|
+
return file;
|
|
4282
|
+
}
|
|
4283
|
+
function addName(byName, file) {
|
|
4284
|
+
for (const [qualified, id] of file.symbols) {
|
|
4285
|
+
if (qualified.includes(".")) continue;
|
|
4286
|
+
let set = byName.get(qualified);
|
|
4287
|
+
if (!set) {
|
|
4288
|
+
set = /* @__PURE__ */ new Set();
|
|
4289
|
+
byName.set(qualified, set);
|
|
4290
|
+
}
|
|
4291
|
+
set.add(id);
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
var SymbolIndex = class {
|
|
4295
|
+
files = /* @__PURE__ */ new Map();
|
|
4296
|
+
paths = /* @__PURE__ */ new Set();
|
|
4297
|
+
byName = /* @__PURE__ */ new Map();
|
|
4298
|
+
tsconfig = null;
|
|
4299
|
+
add(file) {
|
|
4300
|
+
this.files.set(file.path, file);
|
|
4301
|
+
this.paths.add(file.path);
|
|
4302
|
+
addName(this.byName, file);
|
|
4303
|
+
}
|
|
4304
|
+
hasPath(path) {
|
|
4305
|
+
return this.paths.has(path);
|
|
4306
|
+
}
|
|
4307
|
+
file(path) {
|
|
4308
|
+
return this.files.get(path);
|
|
4309
|
+
}
|
|
4310
|
+
lookupName(name) {
|
|
4311
|
+
return [...this.byName.get(name) ?? []];
|
|
4312
|
+
}
|
|
4313
|
+
/** A view of the index as seen from one lane: its changed files replace or remove base entries. */
|
|
4314
|
+
overlay(changed) {
|
|
4315
|
+
const base = this;
|
|
4316
|
+
const own = /* @__PURE__ */ new Map();
|
|
4317
|
+
for (const f of changed.values()) if (f) addName(own, f);
|
|
4318
|
+
return {
|
|
4319
|
+
tsconfig: base.tsconfig,
|
|
4320
|
+
hasPath: (path) => changed.has(path) ? changed.get(path) !== null : base.paths.has(path),
|
|
4321
|
+
file: (path) => changed.has(path) ? changed.get(path) ?? void 0 : base.files.get(path),
|
|
4322
|
+
lookupName(name) {
|
|
4323
|
+
const ids = base.lookupName(name).filter((id) => {
|
|
4324
|
+
const file = parseSymbolId(id)?.file;
|
|
4325
|
+
return file === void 0 || !changed.has(file);
|
|
4326
|
+
});
|
|
4327
|
+
return [...ids, ...own.get(name) ?? []];
|
|
4328
|
+
}
|
|
4329
|
+
};
|
|
4330
|
+
}
|
|
4331
|
+
};
|
|
4332
|
+
function parseJsonc(text) {
|
|
4333
|
+
let out = "";
|
|
4334
|
+
let inString = false;
|
|
4335
|
+
for (let i = 0; i < text.length; i++) {
|
|
4336
|
+
const ch = text[i];
|
|
4337
|
+
if (inString) {
|
|
4338
|
+
out += ch;
|
|
4339
|
+
if (ch === "\\") out += text[++i] ?? "";
|
|
4340
|
+
else if (ch === '"') inString = false;
|
|
4341
|
+
} else if (ch === '"') {
|
|
4342
|
+
inString = true;
|
|
4343
|
+
out += ch;
|
|
4344
|
+
} else if (ch === "/" && text[i + 1] === "/") {
|
|
4345
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
4346
|
+
out += "\n";
|
|
4347
|
+
} else if (ch === "/" && text[i + 1] === "*") {
|
|
4348
|
+
i = text.indexOf("*/", i + 2);
|
|
4349
|
+
if (i < 0) break;
|
|
4350
|
+
i++;
|
|
4351
|
+
} else out += ch;
|
|
4352
|
+
}
|
|
4353
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
|
|
4354
|
+
}
|
|
4355
|
+
var TsconfigSchema = external_exports.object({
|
|
4356
|
+
compilerOptions: external_exports.object({
|
|
4357
|
+
baseUrl: external_exports.string().optional(),
|
|
4358
|
+
paths: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())).optional()
|
|
4359
|
+
}).optional()
|
|
4360
|
+
});
|
|
4361
|
+
function readTsPaths(text) {
|
|
4362
|
+
try {
|
|
4363
|
+
const opts = TsconfigSchema.parse(parseJsonc(text)).compilerOptions ?? {};
|
|
4364
|
+
const baseUrl = (opts.baseUrl ?? "").replace(/^\.\/?/, "").replace(/\/$/, "");
|
|
4365
|
+
const paths = Object.entries(opts.paths ?? {});
|
|
4366
|
+
return opts.baseUrl !== void 0 || paths.length ? { baseUrl, paths } : null;
|
|
4367
|
+
} catch (err) {
|
|
4368
|
+
reportParseError("tsconfig.json", err);
|
|
4369
|
+
return null;
|
|
4370
|
+
}
|
|
4371
|
+
}
|
|
4372
|
+
async function buildSymbolIndex(cwd, commit, cache2, include = () => true) {
|
|
4373
|
+
const index = new SymbolIndex();
|
|
4374
|
+
const entries = await lsTree(cwd, commit);
|
|
4375
|
+
for (const e of entries) index.paths.add(e.path);
|
|
4376
|
+
const wanted = entries.filter((e) => isAnalyzable(e.path) && include(e.path));
|
|
4377
|
+
const indexed = wanted.map((e) => {
|
|
4378
|
+
const hit = cache2.get(e.path, e.oid);
|
|
4379
|
+
return hit && (hit.skipped ? null : toIndexed(hit));
|
|
4380
|
+
});
|
|
4381
|
+
const missing = wanted.flatMap((e, i) => indexed[i] === void 0 ? [{ e, i }] : []);
|
|
4382
|
+
for (let b = 0; b < missing.length; b += INDEX_BATCH) {
|
|
4383
|
+
const batch = missing.slice(b, b + INDEX_BATCH);
|
|
4384
|
+
const blobs = await catFileBatch(
|
|
4385
|
+
cwd,
|
|
4386
|
+
batch.map(({ e }) => e.oid)
|
|
4387
|
+
);
|
|
4388
|
+
for (const { e, i } of batch) {
|
|
4389
|
+
const blob = blobs.get(e.oid);
|
|
4390
|
+
if (!blob) continue;
|
|
4391
|
+
const parsed = await parseCached(cache2, e.path, e.oid, blob.content);
|
|
4392
|
+
indexed[i] = parsed.skipped ? null : toIndexed(parsed);
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
for (const f of indexed) if (f) index.add(f);
|
|
4396
|
+
const tsconfig = entries.find((e) => e.path === "tsconfig.json");
|
|
4397
|
+
if (tsconfig) {
|
|
4398
|
+
const blob = (await catFileBatch(cwd, [tsconfig.oid])).get(tsconfig.oid);
|
|
4399
|
+
if (blob) index.tsconfig = readTsPaths(blob.content);
|
|
4400
|
+
}
|
|
4401
|
+
return index;
|
|
4402
|
+
}
|
|
4403
|
+
|
|
4404
|
+
// ../analysis/src/changes/index.ts
|
|
4405
|
+
function laneRefs(files) {
|
|
4406
|
+
const all = [...files];
|
|
4407
|
+
return subtractRefs(
|
|
4408
|
+
all.flatMap((d) => d.refs),
|
|
4409
|
+
all.flatMap((d) => d.baseRefKeys)
|
|
4410
|
+
);
|
|
4411
|
+
}
|
|
4412
|
+
function includedPath(config, path) {
|
|
4413
|
+
return !isSkippedPath(path) && !config.ignore.some((g) => matchesGlob(path, g));
|
|
4414
|
+
}
|
|
4415
|
+
async function createChangeContext(repoRoot, baseCommit, config, parseCache = new MemoryParseCache()) {
|
|
4416
|
+
const index = await buildSymbolIndex(repoRoot, baseCommit, parseCache, (p) => includedPath(config, p));
|
|
4417
|
+
return { repoRoot, baseCommit, config, index, parseCache, laneCache: /* @__PURE__ */ new Map() };
|
|
4418
|
+
}
|
|
4419
|
+
function emptyChangeSet(laneId, baseCommit) {
|
|
4420
|
+
return {
|
|
4421
|
+
laneId,
|
|
4422
|
+
baseCommit,
|
|
4423
|
+
computedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4424
|
+
files: [],
|
|
4425
|
+
symbolChanges: [],
|
|
4426
|
+
referencesAdded: [],
|
|
4427
|
+
special: []
|
|
4428
|
+
};
|
|
4429
|
+
}
|
|
4430
|
+
function sortSet(cs) {
|
|
4431
|
+
const by = (key) => (a, b) => key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0;
|
|
4432
|
+
cs.files.sort(by((f) => f.path));
|
|
4433
|
+
cs.symbolChanges.sort(by((c) => c.symbolId));
|
|
4434
|
+
cs.referencesAdded.sort(by((r) => `${r.file}\0${String(r.line).padStart(8, "0")}\0${r.targetName}`));
|
|
4435
|
+
cs.special.sort(by((s) => `${s.kind}\0${s.file}\0${JSON.stringify(s)}`));
|
|
4436
|
+
return cs;
|
|
4437
|
+
}
|
|
4438
|
+
function keepReexported(changes, view) {
|
|
4439
|
+
return changes.map((c) => {
|
|
4440
|
+
if (c.changeType !== "removed" && c.changeType !== "moved" && c.changeType !== "renamed") return c;
|
|
4441
|
+
const at2 = parseSymbolId(c.symbolId);
|
|
4442
|
+
if (!at2 || at2.qualifiedName.includes(".") || !view.file(at2.file)) return c;
|
|
4443
|
+
const now = findExport(at2.file, at2.qualifiedName, view);
|
|
4444
|
+
if (!now || now === c.symbolId || c.renamedTo && now !== c.renamedTo) return c;
|
|
4445
|
+
const { renamedTo: _to, ...rest } = c;
|
|
4446
|
+
const newArity = c.renamedTo && JSON.stringify(c.arityBefore) !== JSON.stringify(c.arityAfter);
|
|
4447
|
+
return { ...rest, changeType: newArity ? "signature_changed" : "body_changed" };
|
|
4448
|
+
});
|
|
4449
|
+
}
|
|
4450
|
+
function assemble(laneId, baseCommit, files, diffs, contents, view) {
|
|
4451
|
+
const removed = [];
|
|
4452
|
+
const added = [];
|
|
4453
|
+
const suppressed = /* @__PURE__ */ new Map();
|
|
4454
|
+
const cs = {
|
|
4455
|
+
laneId,
|
|
4456
|
+
baseCommit,
|
|
4457
|
+
computedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4458
|
+
files,
|
|
4459
|
+
symbolChanges: [],
|
|
4460
|
+
referencesAdded: [],
|
|
4461
|
+
special: []
|
|
4462
|
+
};
|
|
4463
|
+
for (const d of diffs) {
|
|
4464
|
+
cs.symbolChanges.push(...d.changes);
|
|
4465
|
+
cs.special.push(...d.special);
|
|
4466
|
+
removed.push(...d.removed);
|
|
4467
|
+
added.push(...d.added);
|
|
4468
|
+
for (const [id, rules] of d.suppressedSymbols) suppressed.set(id, rules);
|
|
4469
|
+
}
|
|
4470
|
+
cs.referencesAdded = laneRefs(diffs);
|
|
4471
|
+
cs.symbolChanges.push(...pairRenames(laneId, removed, added, contents, suppressed));
|
|
4472
|
+
cs.symbolChanges = keepReexported(cs.symbolChanges, view);
|
|
4473
|
+
return sortSet(cs);
|
|
4474
|
+
}
|
|
4475
|
+
async function computeChangeSet(laneId, worktree, ctx) {
|
|
4476
|
+
const snap = await snapshotWorktree(worktree);
|
|
4477
|
+
return computeCommitChangeSet(laneId, worktree, snap.commit, ctx);
|
|
4478
|
+
}
|
|
4479
|
+
async function computeCommitChangeSet(laneId, worktree, commit, ctx) {
|
|
4480
|
+
const key = `${ctx.baseCommit}|${commit}`;
|
|
4481
|
+
const hit = ctx.laneCache.get(laneId);
|
|
4482
|
+
if (hit?.key === key) return { changeSet: hit.changeSet, snapshot: commit, cached: true };
|
|
4483
|
+
const base = await mergeBase(worktree, commit, ctx.baseCommit);
|
|
4484
|
+
const files = (await diffNameStatus(worktree, base, commit)).filter(
|
|
4485
|
+
(f) => includedPath(ctx.config, f.path)
|
|
4486
|
+
);
|
|
4487
|
+
const hunkPaths = files.flatMap((f) => f.oldPath ? [f.oldPath, f.path] : [f.path]);
|
|
4488
|
+
const [hunks, blobs] = await Promise.all([
|
|
4489
|
+
diffTreeHunks(worktree, base, commit, hunkPaths),
|
|
4490
|
+
catFileBatch(worktree, [
|
|
4491
|
+
...files.filter((f) => f.status !== "A").map((f) => `${base}:${f.oldPath ?? f.path}`),
|
|
4492
|
+
...files.filter((f) => f.status !== "D").map((f) => `${commit}:${f.path}`)
|
|
4493
|
+
])
|
|
4494
|
+
]);
|
|
4495
|
+
const version = async (spec, path) => {
|
|
4496
|
+
const blob = blobs.get(spec);
|
|
4497
|
+
if (!blob) return { parsed: null, content: void 0 };
|
|
4498
|
+
return {
|
|
4499
|
+
parsed: await parseCached(ctx.parseCache, path, blob.oid || contentKey(blob.content), blob.content),
|
|
4500
|
+
content: blob.content
|
|
4501
|
+
};
|
|
4502
|
+
};
|
|
4503
|
+
const before = /* @__PURE__ */ new Map();
|
|
4504
|
+
const after = /* @__PURE__ */ new Map();
|
|
4505
|
+
const versions = [];
|
|
4506
|
+
const overlay = /* @__PURE__ */ new Map();
|
|
4507
|
+
for (const f of files) {
|
|
4508
|
+
const oldPath = f.oldPath ?? f.path;
|
|
4509
|
+
const none = { parsed: null, content: void 0 };
|
|
4510
|
+
const b = f.status === "A" ? none : await version(`${base}:${oldPath}`, oldPath);
|
|
4511
|
+
const a = f.status === "D" ? none : await version(`${commit}:${f.path}`, f.path);
|
|
4512
|
+
before.set(oldPath, b.content);
|
|
4513
|
+
after.set(f.path, a.content);
|
|
4514
|
+
if (f.oldPath) overlay.set(f.oldPath, null);
|
|
4515
|
+
overlay.set(f.path, a.parsed && !a.parsed.skipped ? toIndexed(a.parsed) : null);
|
|
4516
|
+
versions.push({ file: { ...f, hunks: hunks.get(f.path) ?? hunks.get(oldPath) ?? [] }, oldPath, b, a });
|
|
4517
|
+
}
|
|
4518
|
+
const view = ctx.index.overlay(overlay);
|
|
4519
|
+
const diffs = versions.map(
|
|
4520
|
+
({ file, oldPath, b, a }) => diffFile({
|
|
4521
|
+
laneId,
|
|
4522
|
+
path: file.path,
|
|
4523
|
+
oldPath,
|
|
4524
|
+
before: b.parsed,
|
|
4525
|
+
after: a.parsed,
|
|
4526
|
+
afterContent: a.content ?? null,
|
|
4527
|
+
view,
|
|
4528
|
+
baseView: ctx.index
|
|
4529
|
+
})
|
|
4530
|
+
);
|
|
4531
|
+
const changeSet = assemble(
|
|
4532
|
+
laneId,
|
|
4533
|
+
base,
|
|
4534
|
+
versions.map((v) => v.file),
|
|
4535
|
+
diffs,
|
|
4536
|
+
{ before: (p) => before.get(p), after: (p) => after.get(p) },
|
|
4537
|
+
view
|
|
4538
|
+
);
|
|
4539
|
+
const baseBlobs = /* @__PURE__ */ new Map();
|
|
4540
|
+
for (const f of files) {
|
|
4541
|
+
const blob = f.status === "A" ? void 0 : blobs.get(`${base}:${f.oldPath ?? f.path}`);
|
|
4542
|
+
if (blob) baseBlobs.set(f.oldPath ?? f.path, blob);
|
|
4543
|
+
}
|
|
4544
|
+
const fileRefs = new Map(
|
|
4545
|
+
versions.map(
|
|
4546
|
+
(v, i) => [v.file.path, { refs: diffs[i].refs, baseRefKeys: diffs[i].baseRefKeys }]
|
|
4547
|
+
)
|
|
4548
|
+
);
|
|
4549
|
+
ctx.laneCache.set(laneId, { key, changeSet, overlay, baseBlobs, fileRefs });
|
|
4550
|
+
return { changeSet, snapshot: commit, cached: false };
|
|
4551
|
+
}
|
|
4552
|
+
function applyEdits(content, edits) {
|
|
4553
|
+
let out = content;
|
|
4554
|
+
for (const e of edits) {
|
|
4555
|
+
if (e.oldString === "") {
|
|
4556
|
+
out = e.newString + out;
|
|
4557
|
+
continue;
|
|
4558
|
+
}
|
|
4559
|
+
if (!out.includes(e.oldString)) return null;
|
|
4560
|
+
out = e.replaceAll ? out.split(e.oldString).join(e.newString) : out.replace(e.oldString, () => e.newString);
|
|
4561
|
+
}
|
|
4562
|
+
return out;
|
|
4563
|
+
}
|
|
4564
|
+
function hunksBetween(a, b) {
|
|
4565
|
+
return structuredPatch("a", "b", a, b, "", "", { context: 0 }).hunks.map((h) => ({
|
|
4566
|
+
oldStart: h.oldLines === 0 ? h.oldStart - 1 : h.oldStart,
|
|
4567
|
+
oldLines: h.oldLines,
|
|
4568
|
+
newStart: h.newLines === 0 ? h.newStart - 1 : h.newStart,
|
|
4569
|
+
newLines: h.newLines
|
|
4570
|
+
}));
|
|
4571
|
+
}
|
|
4572
|
+
async function projectEdit(current, worktree, ctx, edit) {
|
|
4573
|
+
const path = (isAbsolute(edit.file) ? relative(worktree, edit.file) : edit.file).split("\\").join("/");
|
|
4574
|
+
if (path.startsWith("..") || !includedPath(ctx.config, path)) return current;
|
|
4575
|
+
const existing = current.files.find((f) => f.path === path);
|
|
4576
|
+
const oldPath = existing?.oldPath ?? path;
|
|
4577
|
+
const working = await readWorking(worktree, path);
|
|
4578
|
+
const next = edit.content ?? (edit.edits ? applyEdits(working ?? "", edit.edits) : null);
|
|
4579
|
+
if (next === null) return current;
|
|
4580
|
+
const baseSpec = `${current.baseCommit}:${oldPath}`;
|
|
4581
|
+
const cache2 = ctx.laneCache.get(current.laneId);
|
|
4582
|
+
let baseBlob = existing?.status === "A" ? null : cache2?.baseBlobs.get(oldPath) ?? null;
|
|
4583
|
+
if (baseBlob === null && existing?.status !== "A") {
|
|
4584
|
+
baseBlob = (await catFileBatch(worktree, [baseSpec])).get(baseSpec) ?? null;
|
|
4585
|
+
if (baseBlob) cache2?.baseBlobs.set(oldPath, baseBlob);
|
|
4586
|
+
}
|
|
4587
|
+
const before = baseBlob ? await parseCached(ctx.parseCache, oldPath, baseBlob.oid, baseBlob.content) : null;
|
|
4588
|
+
const after = await parseCached(ctx.parseCache, path, gitBlobOid(next), next);
|
|
4589
|
+
const overlay = new Map(ctx.laneCache.get(current.laneId)?.overlay ?? []);
|
|
4590
|
+
overlay.set(path, after.skipped ? null : toIndexed(after));
|
|
4591
|
+
const view = ctx.index.overlay(overlay);
|
|
4592
|
+
const diff = diffFile({
|
|
4593
|
+
laneId: current.laneId,
|
|
4594
|
+
path,
|
|
4595
|
+
oldPath,
|
|
4596
|
+
before,
|
|
4597
|
+
after,
|
|
4598
|
+
afterContent: next,
|
|
4599
|
+
view,
|
|
4600
|
+
baseView: ctx.index
|
|
4601
|
+
});
|
|
4602
|
+
const inFile = (id) => {
|
|
4603
|
+
const file2 = parseSymbolId(id)?.file;
|
|
4604
|
+
return file2 === path || file2 === oldPath;
|
|
4605
|
+
};
|
|
4606
|
+
const afterIds = new Set(after.symbols.map((s) => s.id));
|
|
4607
|
+
const movesIn = current.symbolChanges.filter(
|
|
4608
|
+
(c) => !inFile(c.symbolId) && c.renamedTo && inFile(c.renamedTo)
|
|
4609
|
+
);
|
|
4610
|
+
const movesOut = current.symbolChanges.filter(
|
|
4611
|
+
(c) => inFile(c.symbolId) && c.renamedTo && !inFile(c.renamedTo)
|
|
4612
|
+
);
|
|
4613
|
+
const keptIn = movesIn.filter((c) => afterIds.has(c.renamedTo));
|
|
4614
|
+
const lostIn = movesIn.filter((c) => !afterIds.has(c.renamedTo)).map((c) => {
|
|
4615
|
+
const { renamedTo: _to, after: _after, arityAfter: _arity, ...rest } = c;
|
|
4616
|
+
return { ...rest, changeType: "removed" };
|
|
4617
|
+
});
|
|
4618
|
+
const movedTargets = new Set(keptIn.map((c) => c.renamedTo));
|
|
4619
|
+
const movedSources = new Set(movesOut.map((c) => c.symbolId));
|
|
4620
|
+
const others = current.symbolChanges.filter(
|
|
4621
|
+
(c) => !inFile(c.symbolId) && !(c.renamedTo && inFile(c.renamedTo))
|
|
4622
|
+
);
|
|
4623
|
+
const local = pairRenames(
|
|
4624
|
+
current.laneId,
|
|
4625
|
+
diff.removed.filter((s) => !movedSources.has(s.id)),
|
|
4626
|
+
diff.added.filter((s) => !movedTargets.has(s.id)),
|
|
4627
|
+
{ before: () => baseBlob?.content, after: () => next },
|
|
4628
|
+
diff.suppressedSymbols
|
|
4629
|
+
);
|
|
4630
|
+
const file = {
|
|
4631
|
+
path,
|
|
4632
|
+
status: baseBlob ? oldPath !== path ? "R" : "M" : "A",
|
|
4633
|
+
hunks: hunksBetween(baseBlob?.content ?? "", next)
|
|
4634
|
+
};
|
|
4635
|
+
if (oldPath !== path) file.oldPath = oldPath;
|
|
4636
|
+
const projected = {
|
|
4637
|
+
...current,
|
|
4638
|
+
computedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4639
|
+
files: [...current.files.filter((f) => f.path !== path), ...baseBlob?.content === next ? [] : [file]],
|
|
4640
|
+
symbolChanges: keepReexported(
|
|
4641
|
+
[...others, ...keptIn, ...lostIn, ...movesOut, ...diff.changes, ...local],
|
|
4642
|
+
view
|
|
4643
|
+
),
|
|
4644
|
+
// Lane-wide, as the full computation does: a call that left another file cancels one arriving here.
|
|
4645
|
+
referencesAdded: cache2?.changeSet === current ? laneRefs(new Map(cache2.fileRefs).set(path, diff).values()) : [
|
|
4646
|
+
...current.referencesAdded.filter((r) => r.file !== path),
|
|
4647
|
+
...subtractRefs(diff.refs, diff.baseRefKeys)
|
|
4648
|
+
],
|
|
4649
|
+
special: [...current.special.filter((s) => s.file !== path), ...diff.special]
|
|
4650
|
+
};
|
|
4651
|
+
return sortSet(projected);
|
|
4652
|
+
}
|
|
4653
|
+
|
|
4654
|
+
export {
|
|
4655
|
+
rulesConfigFrom,
|
|
4656
|
+
decide,
|
|
4657
|
+
compileGlob,
|
|
4658
|
+
claimTargetsOverlap,
|
|
4659
|
+
pairKey,
|
|
4660
|
+
detectClashes,
|
|
4661
|
+
parseCodeowners,
|
|
4662
|
+
ownersFor,
|
|
4663
|
+
planItemSize,
|
|
4664
|
+
planMerge,
|
|
4665
|
+
DEFAULT_PRICING,
|
|
4666
|
+
costOf,
|
|
4667
|
+
withOverrides,
|
|
4668
|
+
isSkippedPath,
|
|
4669
|
+
parseClaimTarget,
|
|
4670
|
+
includedPath,
|
|
4671
|
+
createChangeContext,
|
|
4672
|
+
emptyChangeSet,
|
|
4673
|
+
computeChangeSet,
|
|
4674
|
+
projectEdit
|
|
4675
|
+
};
|
|
4676
|
+
/*! Bundled license information:
|
|
4677
|
+
|
|
4678
|
+
smol-toml/dist/error.js:
|
|
4679
|
+
smol-toml/dist/primitive.js:
|
|
4680
|
+
smol-toml/dist/date.js:
|
|
4681
|
+
smol-toml/dist/extract.js:
|
|
4682
|
+
smol-toml/dist/util.js:
|
|
4683
|
+
smol-toml/dist/struct.js:
|
|
4684
|
+
smol-toml/dist/parse.js:
|
|
4685
|
+
smol-toml/dist/stringify.js:
|
|
4686
|
+
smol-toml/dist/index.js:
|
|
4687
|
+
(*!
|
|
4688
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
4689
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
4690
|
+
*
|
|
4691
|
+
* Redistribution and use in source and binary forms, with or without
|
|
4692
|
+
* modification, are permitted provided that the following conditions are met:
|
|
4693
|
+
*
|
|
4694
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
4695
|
+
* list of conditions and the following disclaimer.
|
|
4696
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
4697
|
+
* this list of conditions and the following disclaimer in the
|
|
4698
|
+
* documentation and/or other materials provided with the distribution.
|
|
4699
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
4700
|
+
* may be used to endorse or promote products derived from this software without
|
|
4701
|
+
* specific prior written permission.
|
|
4702
|
+
*
|
|
4703
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
4704
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
4705
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
4706
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
4707
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
4708
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
4709
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
4710
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
4711
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
4712
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
4713
|
+
*)
|
|
4714
|
+
*/
|