assertloom 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +346 -2
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.js +14 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/openai.d.ts +9 -0
- package/dist/ai/openai.js +57 -0
- package/dist/ai/openai.js.map +1 -0
- package/dist/ai/pricing.d.ts +27 -0
- package/dist/ai/pricing.js +76 -0
- package/dist/ai/pricing.js.map +1 -0
- package/dist/ai/prompts.d.ts +27 -0
- package/dist/ai/prompts.js +89 -0
- package/dist/ai/prompts.js.map +1 -0
- package/dist/ai/provider.d.ts +26 -0
- package/dist/ai/provider.js +4 -0
- package/dist/ai/provider.js.map +1 -0
- package/dist/ai/redact.d.ts +5 -0
- package/dist/ai/redact.js +31 -0
- package/dist/ai/redact.js.map +1 -0
- package/dist/analyzer/dependencies.d.ts +16 -0
- package/dist/analyzer/dependencies.js +168 -0
- package/dist/analyzer/dependencies.js.map +1 -0
- package/dist/analyzer/format.d.ts +3 -0
- package/dist/analyzer/format.js +14 -0
- package/dist/analyzer/format.js.map +1 -0
- package/dist/analyzer/functions.d.ts +4 -0
- package/dist/analyzer/functions.js +274 -0
- package/dist/analyzer/functions.js.map +1 -0
- package/dist/analyzer/index.d.ts +5 -0
- package/dist/analyzer/index.js +29 -0
- package/dist/analyzer/index.js.map +1 -0
- package/dist/analyzer/parser.d.ts +11 -0
- package/dist/analyzer/parser.js +38 -0
- package/dist/analyzer/parser.js.map +1 -0
- package/dist/analyzer/usage.d.ts +16 -0
- package/dist/analyzer/usage.js +159 -0
- package/dist/analyzer/usage.js.map +1 -0
- package/dist/cli/commands/analyze.d.ts +2 -0
- package/dist/cli/commands/analyze.js +49 -0
- package/dist/cli/commands/analyze.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +3 -0
- package/dist/cli/commands/generate.js +200 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/run.d.ts +4 -0
- package/dist/cli/commands/run.js +53 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +16 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/program.d.ts +2 -0
- package/dist/cli/program.js +18 -0
- package/dist/cli/program.js.map +1 -0
- package/dist/cli/report.d.ts +3 -0
- package/dist/cli/report.js +36 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/validateFile.d.ts +5 -0
- package/dist/cli/validateFile.js +43 -0
- package/dist/cli/validateFile.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +8 -0
- package/dist/errors.js.map +1 -0
- package/dist/generator/diff.d.ts +5 -0
- package/dist/generator/diff.js +56 -0
- package/dist/generator/diff.js.map +1 -0
- package/dist/generator/importPlan.d.ts +15 -0
- package/dist/generator/importPlan.js +62 -0
- package/dist/generator/importPlan.js.map +1 -0
- package/dist/generator/index.d.ts +5 -0
- package/dist/generator/index.js +6 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/mocks.d.ts +48 -0
- package/dist/generator/mocks.js +356 -0
- package/dist/generator/mocks.js.map +1 -0
- package/dist/generator/schema.d.ts +40 -0
- package/dist/generator/schema.js +15 -0
- package/dist/generator/schema.js.map +1 -0
- package/dist/generator/testGenerator.d.ts +33 -0
- package/dist/generator/testGenerator.js +80 -0
- package/dist/generator/testGenerator.js.map +1 -0
- package/dist/generator/testWriter.d.ts +22 -0
- package/dist/generator/testWriter.js +93 -0
- package/dist/generator/testWriter.js.map +1 -0
- package/dist/generator/validate.d.ts +31 -0
- package/dist/generator/validate.js +180 -0
- package/dist/generator/validate.js.map +1 -0
- package/dist/repair/classifyFailure.d.ts +11 -0
- package/dist/repair/classifyFailure.js +26 -0
- package/dist/repair/classifyFailure.js.map +1 -0
- package/dist/repair/index.d.ts +2 -0
- package/dist/repair/index.js +3 -0
- package/dist/repair/index.js.map +1 -0
- package/dist/repair/repairLoop.d.ts +74 -0
- package/dist/repair/repairLoop.js +219 -0
- package/dist/repair/repairLoop.js.map +1 -0
- package/dist/repair/schema.d.ts +17 -0
- package/dist/repair/schema.js +14 -0
- package/dist/repair/schema.js.map +1 -0
- package/dist/runner/coverage.d.ts +5 -0
- package/dist/runner/coverage.js +42 -0
- package/dist/runner/coverage.js.map +1 -0
- package/dist/runner/index.d.ts +4 -0
- package/dist/runner/index.js +4 -0
- package/dist/runner/index.js.map +1 -0
- package/dist/runner/jestConfig.d.ts +11 -0
- package/dist/runner/jestConfig.js +103 -0
- package/dist/runner/jestConfig.js.map +1 -0
- package/dist/runner/jestRunner.d.ts +14 -0
- package/dist/runner/jestRunner.js +140 -0
- package/dist/runner/jestRunner.js.map +1 -0
- package/dist/runner/networkGuard.d.ts +4 -0
- package/dist/runner/networkGuard.js +55 -0
- package/dist/runner/networkGuard.js.map +1 -0
- package/dist/runner/project.d.ts +30 -0
- package/dist/runner/project.js +86 -0
- package/dist/runner/project.js.map +1 -0
- package/dist/runner/results.d.ts +32 -0
- package/dist/runner/results.js +58 -0
- package/dist/runner/results.js.map +1 -0
- package/dist/runner/types.d.ts +39 -0
- package/dist/runner/types.js +2 -0
- package/dist/runner/types.js.map +1 -0
- package/dist/types/index.d.ts +95 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import traverse from "@babel/traverse";
|
|
2
|
+
import { isMockableGlobal } from "./usage.js";
|
|
3
|
+
function slice(code, node) {
|
|
4
|
+
if (!node || node.start == null || node.end == null)
|
|
5
|
+
return undefined;
|
|
6
|
+
return code.slice(node.start, node.end);
|
|
7
|
+
}
|
|
8
|
+
function typeText(code, annotation) {
|
|
9
|
+
if (annotation?.type === "TSTypeAnnotation")
|
|
10
|
+
return slice(code, annotation.typeAnnotation);
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
function patternText(code, node) {
|
|
14
|
+
const end = node.typeAnnotation?.start ?? node.end ?? 0;
|
|
15
|
+
return code.slice(node.start ?? 0, end).replace(/\?$/, "").trim();
|
|
16
|
+
}
|
|
17
|
+
function parameterInfo(code, param) {
|
|
18
|
+
switch (param.type) {
|
|
19
|
+
case "Identifier":
|
|
20
|
+
return { name: param.name, type: typeText(code, param.typeAnnotation), optional: !!param.optional, rest: false };
|
|
21
|
+
case "AssignmentPattern": {
|
|
22
|
+
const left = parameterInfo(code, param.left);
|
|
23
|
+
return { ...left, optional: true, defaultValue: slice(code, param.right) };
|
|
24
|
+
}
|
|
25
|
+
case "RestElement": {
|
|
26
|
+
const type = typeText(code, param.typeAnnotation) ?? typeText(code, param.argument.typeAnnotation);
|
|
27
|
+
const name = param.argument.type === "Identifier" ? param.argument.name : patternText(code, param.argument);
|
|
28
|
+
return { name, type, optional: true, rest: true };
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
return {
|
|
32
|
+
name: patternText(code, param),
|
|
33
|
+
type: typeText(code, param.typeAnnotation),
|
|
34
|
+
optional: !!param.optional,
|
|
35
|
+
rest: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function unwrap(node) {
|
|
40
|
+
while (node &&
|
|
41
|
+
(node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "ParenthesizedExpression")) {
|
|
42
|
+
node = node.expression;
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
function asFunction(node) {
|
|
47
|
+
const inner = unwrap(node);
|
|
48
|
+
return inner?.type === "FunctionExpression" || inner?.type === "ArrowFunctionExpression" ? inner : undefined;
|
|
49
|
+
}
|
|
50
|
+
function propertyName(node) {
|
|
51
|
+
if (node.type === "Identifier")
|
|
52
|
+
return node.name;
|
|
53
|
+
if (node.type === "StringLiteral")
|
|
54
|
+
return node.value;
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
function collectCandidates(body) {
|
|
58
|
+
const candidates = [];
|
|
59
|
+
const byLocalName = new Map();
|
|
60
|
+
const addCandidate = (name, node, exportedAs = []) => {
|
|
61
|
+
const existing = candidates.find((c) => c.node === node);
|
|
62
|
+
if (existing) {
|
|
63
|
+
for (const e of exportedAs)
|
|
64
|
+
if (!existing.exportedAs.includes(e))
|
|
65
|
+
existing.exportedAs.push(e);
|
|
66
|
+
return existing;
|
|
67
|
+
}
|
|
68
|
+
const candidate = { name, node, exportedAs };
|
|
69
|
+
candidates.push(candidate);
|
|
70
|
+
if (name !== "default")
|
|
71
|
+
byLocalName.set(name, candidate);
|
|
72
|
+
return candidate;
|
|
73
|
+
};
|
|
74
|
+
const addDeclaration = (stmt, exported) => {
|
|
75
|
+
if (stmt?.type === "FunctionDeclaration" && stmt.id) {
|
|
76
|
+
addCandidate(stmt.id.name, stmt, exported ? [stmt.id.name] : []);
|
|
77
|
+
}
|
|
78
|
+
else if (stmt?.type === "VariableDeclaration") {
|
|
79
|
+
for (const decl of stmt.declarations) {
|
|
80
|
+
const fn = asFunction(decl.init);
|
|
81
|
+
if (fn && decl.id.type === "Identifier")
|
|
82
|
+
addCandidate(decl.id.name, fn, exported ? [decl.id.name] : []);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const pendingExports = [];
|
|
87
|
+
/** Top-level `const name = { ... }` objects, for `module.exports = name` and `exports.x = name.x`. */
|
|
88
|
+
const objects = new Map();
|
|
89
|
+
const pendingObjects = [];
|
|
90
|
+
const pendingMembers = [];
|
|
91
|
+
const addCommonJsObject = (node) => {
|
|
92
|
+
if (node.type !== "ObjectExpression")
|
|
93
|
+
return;
|
|
94
|
+
for (const prop of node.properties) {
|
|
95
|
+
if (prop.type === "ObjectMethod" && prop.kind === "method") {
|
|
96
|
+
const key = propertyName(prop.key);
|
|
97
|
+
if (key)
|
|
98
|
+
addCandidate(key, prop, [key]);
|
|
99
|
+
}
|
|
100
|
+
else if (prop.type === "ObjectProperty") {
|
|
101
|
+
const key = propertyName(prop.key);
|
|
102
|
+
if (!key)
|
|
103
|
+
continue;
|
|
104
|
+
const fn = asFunction(prop.value);
|
|
105
|
+
if (fn)
|
|
106
|
+
addCandidate(key, fn, [key]);
|
|
107
|
+
else if (prop.value.type === "Identifier")
|
|
108
|
+
pendingExports.push({ local: prop.value.name, exported: key });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
for (const stmt of body) {
|
|
113
|
+
switch (stmt.type) {
|
|
114
|
+
case "FunctionDeclaration":
|
|
115
|
+
addDeclaration(stmt, false);
|
|
116
|
+
break;
|
|
117
|
+
case "VariableDeclaration":
|
|
118
|
+
addDeclaration(stmt, false);
|
|
119
|
+
for (const decl of stmt.declarations) {
|
|
120
|
+
if (decl.id.type === "Identifier" && decl.init?.type === "ObjectExpression")
|
|
121
|
+
objects.set(decl.id.name, decl.init);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
case "ExportNamedDeclaration":
|
|
125
|
+
if (stmt.declaration) {
|
|
126
|
+
addDeclaration(stmt.declaration, stmt.exportKind !== "type");
|
|
127
|
+
}
|
|
128
|
+
else if (!stmt.source && stmt.exportKind !== "type") {
|
|
129
|
+
for (const spec of stmt.specifiers) {
|
|
130
|
+
if (spec.type !== "ExportSpecifier" || spec.exportKind === "type")
|
|
131
|
+
continue;
|
|
132
|
+
const local = propertyName(spec.local);
|
|
133
|
+
const exported = propertyName(spec.exported);
|
|
134
|
+
if (local && exported)
|
|
135
|
+
pendingExports.push({ local, exported });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
case "ExportDefaultDeclaration": {
|
|
140
|
+
const decl = stmt.declaration;
|
|
141
|
+
if (decl.type === "FunctionDeclaration") {
|
|
142
|
+
addCandidate(decl.id?.name ?? "default", decl, ["default"]);
|
|
143
|
+
}
|
|
144
|
+
else if (decl.type === "Identifier") {
|
|
145
|
+
pendingExports.push({ local: decl.name, exported: "default" });
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const fn = asFunction(decl);
|
|
149
|
+
if (fn)
|
|
150
|
+
addCandidate(fn.type === "FunctionExpression" && fn.id ? fn.id.name : "default", fn, ["default"]);
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case "ExpressionStatement": {
|
|
155
|
+
const expr = stmt.expression;
|
|
156
|
+
if (expr.type !== "AssignmentExpression" || expr.operator !== "=" || expr.left.type !== "MemberExpression")
|
|
157
|
+
break;
|
|
158
|
+
const { object, property } = expr.left;
|
|
159
|
+
const isModuleExports = object.type === "Identifier" && object.name === "module" && propertyName(property) === "exports";
|
|
160
|
+
if (isModuleExports) {
|
|
161
|
+
const fn = asFunction(expr.right);
|
|
162
|
+
if (fn)
|
|
163
|
+
addCandidate(fn.type === "FunctionExpression" && fn.id ? fn.id.name : "default", fn, ["default"]);
|
|
164
|
+
else if (expr.right.type === "Identifier") {
|
|
165
|
+
pendingExports.push({ local: expr.right.name, exported: "default" });
|
|
166
|
+
pendingObjects.push(expr.right.name);
|
|
167
|
+
}
|
|
168
|
+
else
|
|
169
|
+
addCommonJsObject(expr.right);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
const isExportsObject = (object.type === "Identifier" && object.name === "exports") ||
|
|
173
|
+
(object.type === "MemberExpression" &&
|
|
174
|
+
object.object.type === "Identifier" &&
|
|
175
|
+
object.object.name === "module" &&
|
|
176
|
+
propertyName(object.property) === "exports");
|
|
177
|
+
const key = !expr.left.computed ? propertyName(property) : undefined;
|
|
178
|
+
if (!isExportsObject || !key)
|
|
179
|
+
break;
|
|
180
|
+
const fn = asFunction(expr.right);
|
|
181
|
+
if (fn)
|
|
182
|
+
addCandidate(key, fn, [key]);
|
|
183
|
+
else if (expr.right.type === "Identifier")
|
|
184
|
+
pendingExports.push({ local: expr.right.name, exported: key });
|
|
185
|
+
else if (expr.right.type === "MemberExpression" && expr.right.object.type === "Identifier" && !expr.right.computed) {
|
|
186
|
+
const member = propertyName(expr.right.property);
|
|
187
|
+
if (member)
|
|
188
|
+
pendingMembers.push({ object: expr.right.object.name, property: member, exported: key });
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (const name of pendingObjects) {
|
|
195
|
+
const object = objects.get(name);
|
|
196
|
+
if (object)
|
|
197
|
+
addCommonJsObject(object);
|
|
198
|
+
}
|
|
199
|
+
for (const { object, property, exported } of pendingMembers) {
|
|
200
|
+
const node = objects.get(object);
|
|
201
|
+
if (node?.type !== "ObjectExpression")
|
|
202
|
+
continue;
|
|
203
|
+
for (const prop of node.properties) {
|
|
204
|
+
if (prop.type !== "ObjectProperty" || propertyName(prop.key) !== property)
|
|
205
|
+
continue;
|
|
206
|
+
const fn = asFunction(prop.value);
|
|
207
|
+
if (fn)
|
|
208
|
+
addCandidate(exported, fn, [exported]);
|
|
209
|
+
else if (prop.value.type === "Identifier")
|
|
210
|
+
pendingExports.push({ local: prop.value.name, exported });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const { local, exported } of pendingExports) {
|
|
214
|
+
const candidate = byLocalName.get(local);
|
|
215
|
+
if (candidate && !candidate.exportedAs.includes(exported))
|
|
216
|
+
candidate.exportedAs.push(exported);
|
|
217
|
+
}
|
|
218
|
+
return candidates;
|
|
219
|
+
}
|
|
220
|
+
export function extractFunctions(ast, code, scan) {
|
|
221
|
+
const candidates = collectCandidates(ast.program.body);
|
|
222
|
+
const byNode = new Map(candidates.map((c) => [c.node, c]));
|
|
223
|
+
const results = [];
|
|
224
|
+
traverse(ast, {
|
|
225
|
+
Function(path) {
|
|
226
|
+
const candidate = byNode.get(path.node);
|
|
227
|
+
if (!candidate)
|
|
228
|
+
return;
|
|
229
|
+
const node = candidate.node;
|
|
230
|
+
const programScope = path.scope.getProgramParent();
|
|
231
|
+
const dependencies = new Set();
|
|
232
|
+
const globals = new Set();
|
|
233
|
+
let throws = false;
|
|
234
|
+
path.traverse({
|
|
235
|
+
"Identifier|JSXIdentifier"(idPath) {
|
|
236
|
+
if (isMockableGlobal(idPath))
|
|
237
|
+
globals.add(idPath.node.name);
|
|
238
|
+
if (!idPath.isReferencedIdentifier())
|
|
239
|
+
return;
|
|
240
|
+
const name = idPath.node.name;
|
|
241
|
+
const source = scan.bindings.get(name);
|
|
242
|
+
if (source && idPath.scope.getBinding(name) === programScope.getBinding(name))
|
|
243
|
+
dependencies.add(source);
|
|
244
|
+
},
|
|
245
|
+
"CallExpression|ImportExpression"(callPath) {
|
|
246
|
+
const source = scan.callSites.get(callPath.node);
|
|
247
|
+
if (source)
|
|
248
|
+
dependencies.add(source);
|
|
249
|
+
},
|
|
250
|
+
ThrowStatement(throwPath) {
|
|
251
|
+
if (throwPath.getFunctionParent()?.node === node)
|
|
252
|
+
throws = true;
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
results.push({
|
|
256
|
+
name: candidate.name,
|
|
257
|
+
exported: candidate.exportedAs.length > 0,
|
|
258
|
+
exportedAs: candidate.exportedAs,
|
|
259
|
+
kind: node.type === "ArrowFunctionExpression" ? "arrow" : node.type === "FunctionDeclaration" ? "declaration" : "expression",
|
|
260
|
+
async: node.async,
|
|
261
|
+
generator: !!node.generator,
|
|
262
|
+
parameters: node.params.filter((p) => !(p.type === "Identifier" && p.name === "this")).map((p) => parameterInfo(code, p)),
|
|
263
|
+
returnType: typeText(code, node.returnType),
|
|
264
|
+
typeParameters: slice(code, node.typeParameters),
|
|
265
|
+
throws,
|
|
266
|
+
dependencies: [...dependencies].sort(),
|
|
267
|
+
globals: [...globals].sort(),
|
|
268
|
+
line: node.loc?.start.line ?? 0,
|
|
269
|
+
});
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
return results.sort((a, b) => a.line - b.line);
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzH,UAAU,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC;gBAC3C,cAAc,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC;gBAChD,MAAM;gBACN,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,IAAI,EAAE;gBACtC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE;gBAC5B,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC;aAChC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FileAnalysis, SourceFile } from "../types/index.js";
|
|
2
|
+
export { ParseError, parseSource } from "./parser.js";
|
|
3
|
+
/** Statically analyzes source code. Target code is parsed, never executed. */
|
|
4
|
+
export declare function analyzeSource(code: string, source: Pick<SourceFile, "inputPath" | "extension" | "language">): FileAnalysis;
|
|
5
|
+
export declare function analyzeFile(source: SourceFile): Promise<FileAnalysis>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { scanImports, summarizeDependencies } from "./dependencies.js";
|
|
3
|
+
import { extractFunctions } from "./functions.js";
|
|
4
|
+
import { parseSource } from "./parser.js";
|
|
5
|
+
import { collectImportUsage } from "./usage.js";
|
|
6
|
+
export { ParseError, parseSource } from "./parser.js";
|
|
7
|
+
/** Statically analyzes source code. Target code is parsed, never executed. */
|
|
8
|
+
export function analyzeSource(code, source) {
|
|
9
|
+
const ast = parseSource(code, source.extension);
|
|
10
|
+
const scan = scanImports(ast);
|
|
11
|
+
const usesEsm = scan.imports.some((i) => i.kind === "import" || i.kind === "re-export") ||
|
|
12
|
+
ast.program.body.some((s) => s.type === "ExportNamedDeclaration" || s.type === "ExportDefaultDeclaration");
|
|
13
|
+
const usesCommonJs = scan.usesCommonJsExports || scan.imports.some((i) => i.kind === "require");
|
|
14
|
+
const { importUsage, globals } = collectImportUsage(ast);
|
|
15
|
+
return {
|
|
16
|
+
file: source.inputPath.replaceAll("\\", "/"),
|
|
17
|
+
language: source.language,
|
|
18
|
+
moduleSystem: usesEsm && usesCommonJs ? "mixed" : usesEsm ? "esm" : usesCommonJs ? "commonjs" : "none",
|
|
19
|
+
functions: extractFunctions(ast, code, scan),
|
|
20
|
+
imports: scan.imports,
|
|
21
|
+
importUsage,
|
|
22
|
+
globals,
|
|
23
|
+
dependencies: summarizeDependencies(scan.imports),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function analyzeFile(source) {
|
|
27
|
+
return analyzeSource(await readFile(source.absolutePath, "utf8"), source);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/analyzer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,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AC,OAAO;QACrB,WAAW;QACX,OAAO;QACP,YAAY,EAAE,qBAAqB,CAAC,IAAI,CAAC,OAAO,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAkB;IAClD,OAAO,aAAa,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ParserPlugin } from "@babel/parser";
|
|
2
|
+
import type { File } from "@babel/types";
|
|
3
|
+
import { UserError } from "../errors.js";
|
|
4
|
+
import type { SupportedExtension } from "../types/index.js";
|
|
5
|
+
export declare class ParseError extends UserError {
|
|
6
|
+
readonly line?: number | undefined;
|
|
7
|
+
readonly column?: number | undefined;
|
|
8
|
+
constructor(message: string, line?: number | undefined, column?: number | undefined);
|
|
9
|
+
}
|
|
10
|
+
export declare function pluginsFor(extension: SupportedExtension): ParserPlugin[];
|
|
11
|
+
export declare function parseSource(code: string, extension: SupportedExtension): File;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
import { UserError } from "../errors.js";
|
|
3
|
+
export class ParseError extends UserError {
|
|
4
|
+
line;
|
|
5
|
+
column;
|
|
6
|
+
constructor(message, line, column) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.line = line;
|
|
9
|
+
this.column = column;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function pluginsFor(extension) {
|
|
13
|
+
switch (extension) {
|
|
14
|
+
case ".ts":
|
|
15
|
+
case ".mts":
|
|
16
|
+
case ".cts":
|
|
17
|
+
return ["typescript"];
|
|
18
|
+
case ".tsx":
|
|
19
|
+
return ["typescript", "jsx"];
|
|
20
|
+
default:
|
|
21
|
+
return ["jsx"];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function parseSource(code, extension) {
|
|
25
|
+
try {
|
|
26
|
+
return parse(code, {
|
|
27
|
+
sourceType: extension === ".js" || extension === ".jsx" || extension === ".cjs" ? "unambiguous" : "module",
|
|
28
|
+
plugins: pluginsFor(extension),
|
|
29
|
+
errorRecovery: false,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const loc = error.loc;
|
|
34
|
+
const reason = error.message.replace(/\s*\(\d+:\d+\)$/, "");
|
|
35
|
+
throw new ParseError(loc ? `Syntax error at line ${loc.line}, column ${loc.column + 1}: ${reason}` : `Syntax error: ${reason}`, loc?.line, loc?.column);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/analyzer/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,MAAM,OAAO,UAAW,SAAQ,SAAS;IAG5B,IAAI;IACJ,MAAM;IAHjB,YACE,OAAe,EACN,IAAa,EACb,MAAe;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;oBAHN,IAAI;sBACJ,MAAM;IAGjB,CAAC;CACF;AAED,MAAM,UAAU,UAAU,CAAC,SAA6B;IACtD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,CAAC,YAAY,CAAC,CAAC;QACxB,KAAK,MAAM;YACT,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QAC/B;YACE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,SAA6B;IACrE,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,EAAE;YACjB,UAAU,EAAE,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ;YAC1G,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC;YAC9B,aAAa,EAAE,KAAK;SACrB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,GAAG,GAAI,KAAoD,CAAC,GAAG,CAAC;QACtE,MAAM,MAAM,GAAI,KAAe,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;QACvE,MAAM,IAAI,UAAU,CAClB,GAAG,CAAC,CAAC,CAAC,wBAAwB,GAAG,CAAC,IAAI,YAAY,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,iBAAiB,MAAM,EAAE,EACzG,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,MAAM,CACZ,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type NodePath } from "@babel/traverse";
|
|
2
|
+
import type { File } from "@babel/types";
|
|
3
|
+
import type { ImportUsage, UsageShape } from "../types/index.js";
|
|
4
|
+
/** Globals Assertloom replaces with mocks when the source uses them. */
|
|
5
|
+
export declare const MOCKABLE_GLOBALS: readonly ["fetch"];
|
|
6
|
+
export declare function emptyShape(): UsageShape;
|
|
7
|
+
/** True for a reference to a mockable global that the code does not declare itself. */
|
|
8
|
+
export declare function isMockableGlobal(path: NodePath): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Finds every runtime binding created by `import` or `require()` and records how the code uses it
|
|
11
|
+
* (calls, `new`, member access, stored results), plus references to mockable globals.
|
|
12
|
+
*/
|
|
13
|
+
export declare function collectImportUsage(ast: File): {
|
|
14
|
+
importUsage: ImportUsage[];
|
|
15
|
+
globals: string[];
|
|
16
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import traverse from "@babel/traverse";
|
|
2
|
+
/** Globals Assertloom replaces with mocks when the source uses them. */
|
|
3
|
+
export const MOCKABLE_GLOBALS = ["fetch"];
|
|
4
|
+
const MAX_DEPTH = 6;
|
|
5
|
+
export function emptyShape() {
|
|
6
|
+
return { called: false, constructed: false, instanceOf: false, members: {}, resultNames: [], createdAtLoad: false };
|
|
7
|
+
}
|
|
8
|
+
/** True for a reference to a mockable global that the code does not declare itself. */
|
|
9
|
+
export function isMockableGlobal(path) {
|
|
10
|
+
if (!path.isReferencedIdentifier() || path.node.type !== "Identifier")
|
|
11
|
+
return false;
|
|
12
|
+
const name = path.node.name;
|
|
13
|
+
return MOCKABLE_GLOBALS.includes(name) && !path.scope.hasBinding(name, { noGlobals: true });
|
|
14
|
+
}
|
|
15
|
+
function memberName(node) {
|
|
16
|
+
if (node.type !== "MemberExpression" && node.type !== "OptionalMemberExpression")
|
|
17
|
+
return undefined;
|
|
18
|
+
if (!node.computed && node.property.type === "Identifier")
|
|
19
|
+
return node.property.name;
|
|
20
|
+
if (node.property.type === "StringLiteral")
|
|
21
|
+
return node.property.value;
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const TRANSPARENT = new Set(["TSNonNullExpression", "TSAsExpression", "TSSatisfiesExpression", "ParenthesizedExpression"]);
|
|
25
|
+
/** Records how the expression at `path`, whose value is described by `shape`, is used. */
|
|
26
|
+
function follow(path, shape, depth) {
|
|
27
|
+
if (depth > MAX_DEPTH)
|
|
28
|
+
return;
|
|
29
|
+
let current = path;
|
|
30
|
+
let cur = shape;
|
|
31
|
+
for (;;) {
|
|
32
|
+
const parent = current.parentPath;
|
|
33
|
+
if (!parent)
|
|
34
|
+
return;
|
|
35
|
+
const node = parent.node;
|
|
36
|
+
if (TRANSPARENT.has(node.type)) {
|
|
37
|
+
current = parent;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if ((node.type === "MemberExpression" || node.type === "OptionalMemberExpression") && node.object === current.node) {
|
|
41
|
+
const name = memberName(node);
|
|
42
|
+
if (!name)
|
|
43
|
+
return;
|
|
44
|
+
cur = cur.members[name] ??= emptyShape();
|
|
45
|
+
current = parent;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const isCall = (node.type === "CallExpression" || node.type === "OptionalCallExpression") && node.callee === current.node;
|
|
49
|
+
const isNew = node.type === "NewExpression" && node.callee === current.node;
|
|
50
|
+
if (isCall || isNew) {
|
|
51
|
+
if (isCall)
|
|
52
|
+
cur.called = true;
|
|
53
|
+
else
|
|
54
|
+
cur.constructed = true;
|
|
55
|
+
let resultPath = parent;
|
|
56
|
+
if (resultPath.parentPath?.isAwaitExpression())
|
|
57
|
+
resultPath = resultPath.parentPath;
|
|
58
|
+
const declarator = resultPath.parentPath;
|
|
59
|
+
if (declarator?.isVariableDeclarator() && declarator.node.init === resultPath.node && declarator.node.id.type === "Identifier") {
|
|
60
|
+
const name = declarator.node.id.name;
|
|
61
|
+
const result = (cur.result ??= emptyShape());
|
|
62
|
+
if (!cur.resultNames.includes(name))
|
|
63
|
+
cur.resultNames.push(name);
|
|
64
|
+
if (declarator.scope.block.type === "Program")
|
|
65
|
+
cur.createdAtLoad = true;
|
|
66
|
+
for (const ref of declarator.scope.getBinding(name)?.referencePaths ?? [])
|
|
67
|
+
follow(ref, result, depth + 1);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const next = resultPath.parentPath?.node;
|
|
71
|
+
if (next && (next.type === "MemberExpression" || next.type === "OptionalMemberExpression") && next.object === resultPath.node) {
|
|
72
|
+
cur = cur.result ??= emptyShape();
|
|
73
|
+
current = resultPath;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (node.type === "BinaryExpression" && node.operator === "instanceof" && node.right === current.node) {
|
|
79
|
+
cur.instanceOf = true;
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function stringValue(node) {
|
|
85
|
+
if (node?.type === "StringLiteral")
|
|
86
|
+
return node.value;
|
|
87
|
+
if (node?.type === "TemplateLiteral" && node.expressions.length === 0)
|
|
88
|
+
return node.quasis[0].value.cooked ?? undefined;
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
function propertyKey(node) {
|
|
92
|
+
if (node.type === "Identifier")
|
|
93
|
+
return node.name;
|
|
94
|
+
if (node.type === "StringLiteral")
|
|
95
|
+
return node.value;
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Finds every runtime binding created by `import` or `require()` and records how the code uses it
|
|
100
|
+
* (calls, `new`, member access, stored results), plus references to mockable globals.
|
|
101
|
+
*/
|
|
102
|
+
export function collectImportUsage(ast) {
|
|
103
|
+
const importUsage = [];
|
|
104
|
+
const globals = new Set();
|
|
105
|
+
const track = (entry, binding) => {
|
|
106
|
+
const shape = emptyShape();
|
|
107
|
+
for (const ref of binding?.referencePaths ?? [])
|
|
108
|
+
follow(ref, shape, 0);
|
|
109
|
+
importUsage.push({ ...entry, shape });
|
|
110
|
+
};
|
|
111
|
+
traverse(ast, {
|
|
112
|
+
ImportDeclaration(path) {
|
|
113
|
+
if (path.node.importKind === "type" || path.node.importKind === "typeof")
|
|
114
|
+
return;
|
|
115
|
+
const source = path.node.source.value;
|
|
116
|
+
for (const s of path.node.specifiers) {
|
|
117
|
+
if (s.type === "ImportSpecifier" && (s.importKind === "type" || s.importKind === "typeof"))
|
|
118
|
+
continue;
|
|
119
|
+
const imported = s.type === "ImportDefaultSpecifier" ? "default" : s.type === "ImportNamespaceSpecifier" ? "*" : propertyKey(s.imported) ?? "";
|
|
120
|
+
track({ source, local: s.local.name, imported, style: "esm" }, path.scope.getBinding(s.local.name));
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
CallExpression(path) {
|
|
124
|
+
const callee = path.node.callee;
|
|
125
|
+
if (callee.type !== "Identifier" || callee.name !== "require" || path.scope.hasBinding("require"))
|
|
126
|
+
return;
|
|
127
|
+
const source = stringValue(path.node.arguments[0]);
|
|
128
|
+
if (!source)
|
|
129
|
+
return;
|
|
130
|
+
const declarator = path.parentPath;
|
|
131
|
+
if (declarator.isVariableDeclarator() && declarator.node.init === path.node) {
|
|
132
|
+
const id = declarator.node.id;
|
|
133
|
+
if (id.type === "Identifier") {
|
|
134
|
+
track({ source, local: id.name, imported: "*", style: "commonjs" }, declarator.scope.getBinding(id.name));
|
|
135
|
+
}
|
|
136
|
+
else if (id.type === "ObjectPattern") {
|
|
137
|
+
for (const prop of id.properties) {
|
|
138
|
+
if (prop.type !== "ObjectProperty" || prop.value.type !== "Identifier")
|
|
139
|
+
continue;
|
|
140
|
+
const imported = propertyKey(prop.key);
|
|
141
|
+
if (imported)
|
|
142
|
+
track({ source, local: prop.value.name, imported, style: "commonjs" }, declarator.scope.getBinding(prop.value.name));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// `require("x").get(...)`: follow the call itself.
|
|
148
|
+
const shape = emptyShape();
|
|
149
|
+
follow(path, shape, 0);
|
|
150
|
+
importUsage.push({ source, local: "", imported: "*", style: "commonjs", shape });
|
|
151
|
+
},
|
|
152
|
+
Identifier(path) {
|
|
153
|
+
if (isMockableGlobal(path))
|
|
154
|
+
globals.add(path.node.name);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
return { importUsage, globals: [...globals].sort() };
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/analyzer/usage.ts"],"names":[],"mappings":"AAAA,OAAO,QAA2B,MAAM,iBAAiB,CAAC;AAI1D,wEAAwE;AACxE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAO,CAAU,CAAC;AAEnD,MAAM,SAAS,GAAG,CAAC,CAA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AI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACvB,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QACnF,CAAC;QAED,UAAU,CAAC,IAAI;YACb,IAAI,gBAAgB,CAAC,IAAI,CAAC;gBAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1D,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { formatSignature } from "../../analyzer/format.js";
|
|
2
|
+
import { analyzeFile } from "../../analyzer/index.js";
|
|
3
|
+
import { validateSourceFile } from "../validateFile.js";
|
|
4
|
+
function plural(count, word, pluralWord = `${word}s`) {
|
|
5
|
+
return `${count} ${count === 1 ? word : pluralWord}`;
|
|
6
|
+
}
|
|
7
|
+
function signature(fn) {
|
|
8
|
+
const alias = fn.exportedAs.filter((name) => name !== fn.name);
|
|
9
|
+
const notes = [
|
|
10
|
+
alias.length ? `exported as ${alias.join(", ")}` : "",
|
|
11
|
+
fn.throws ? "throws" : "",
|
|
12
|
+
fn.dependencies.length || fn.globals.length ? `uses ${[...fn.dependencies, ...fn.globals.map((g) => `global ${g}`)].join(", ")}` : "",
|
|
13
|
+
].filter(Boolean);
|
|
14
|
+
return `${formatSignature(fn)}${notes.length ? ` [${notes.join("; ")}]` : ""}`;
|
|
15
|
+
}
|
|
16
|
+
function printSummary(analysis) {
|
|
17
|
+
const exported = analysis.functions.filter((f) => f.exported);
|
|
18
|
+
const internal = analysis.functions.length - exported.length;
|
|
19
|
+
const { local, external, builtin } = analysis.dependencies;
|
|
20
|
+
const language = analysis.language === "typescript" ? "TypeScript" : "JavaScript";
|
|
21
|
+
console.log(`✓ Parsed ${analysis.file} (${language}, ${analysis.moduleSystem === "none" ? "no imports/exports" : analysis.moduleSystem.toUpperCase()})`);
|
|
22
|
+
console.log(`✓ Found ${plural(exported.length, "exported function")}${internal ? ` (+${internal} internal)` : ""}`);
|
|
23
|
+
console.log(`✓ Found ${plural(local.length + external.length + builtin.length, "dependency", "dependencies")} ` +
|
|
24
|
+
`(${external.length} external, ${local.length} local, ${builtin.length} built-in)`);
|
|
25
|
+
if (exported.length) {
|
|
26
|
+
console.log("");
|
|
27
|
+
for (const fn of exported)
|
|
28
|
+
console.log(` ${signature(fn)}`);
|
|
29
|
+
}
|
|
30
|
+
if (external.length)
|
|
31
|
+
console.log(`\nExternal packages: ${external.join(", ")}`);
|
|
32
|
+
}
|
|
33
|
+
export function registerAnalyzeCommand(program) {
|
|
34
|
+
program
|
|
35
|
+
.command("analyze")
|
|
36
|
+
.description("Statically analyze a JS/TS file: exported functions, parameters, imports, and dependencies")
|
|
37
|
+
.argument("<file>", "path to a JavaScript or TypeScript source file")
|
|
38
|
+
.option("--json", "print the full analysis as JSON")
|
|
39
|
+
.action(async (file, options) => {
|
|
40
|
+
const analysis = await analyzeFile(await validateSourceFile(file));
|
|
41
|
+
if (options.json) {
|
|
42
|
+
console.log(JSON.stringify(analysis, null, 2));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
printSummary(analysis);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=analyze.js.map
|