optiprune 1.8.17 → 2.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/dist/ast-utils.d.ts +149 -0
- package/dist/ast-utils.js +36 -0
- package/dist/ast-utils.js.map +1 -0
- package/dist/engine.js +11 -13
- package/dist/engine.js.map +1 -1
- package/dist/framework-plugins.js +33 -14
- package/dist/framework-plugins.js.map +1 -1
- package/dist/fs-utils.js +1 -1
- package/dist/fs-utils.js.map +1 -1
- package/dist/graph.d.ts +6 -1
- package/dist/graph.js +55 -6
- package/dist/graph.js.map +1 -1
- package/dist/index.js +73 -57
- package/dist/index.js.map +1 -1
- package/dist/instrument.d.ts +4 -0
- package/dist/instrument.js +105 -17
- package/dist/instrument.js.map +1 -1
- package/dist/layer2.js +13 -16
- package/dist/layer2.js.map +1 -1
- package/dist/layer6.d.ts +2 -1
- package/dist/layer6.js +27 -15
- package/dist/layer6.js.map +1 -1
- package/dist/layer7.js +59 -42
- package/dist/layer7.js.map +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +137 -36
- package/dist/parser.js.map +1 -1
- package/dist/plugins/angular-plugin.js +1 -1
- package/dist/plugins/angular-plugin.js.map +1 -1
- package/dist/plugins/astro-plugin.js +1 -1
- package/dist/plugins/astro-plugin.js.map +1 -1
- package/dist/plugins/babel-plugin.js +1 -1
- package/dist/plugins/babel-plugin.js.map +1 -1
- package/dist/plugins/esbuild-plugin.js +1 -1
- package/dist/plugins/esbuild-plugin.js.map +1 -1
- package/dist/plugins/nestjs-plugin.js +1 -1
- package/dist/plugins/nestjs-plugin.js.map +1 -1
- package/dist/plugins/nextjs-plugin.js +1 -1
- package/dist/plugins/nextjs-plugin.js.map +1 -1
- package/dist/plugins/nuxtjs-plugin.js +1 -1
- package/dist/plugins/nuxtjs-plugin.js.map +1 -1
- package/dist/plugins/svelte-plugin.js +1 -1
- package/dist/plugins/svelte-plugin.js.map +1 -1
- package/dist/plugins/vuejs-plugin.js +1 -1
- package/dist/plugins/vuejs-plugin.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -11
- package/dist/instrumentation-plugin.d.ts +0 -6
- package/dist/instrumentation-plugin.js +0 -84
- package/dist/instrumentation-plugin.js.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export interface ParseDiagnostic {
|
|
|
17
17
|
location?: Range;
|
|
18
18
|
recovered: boolean;
|
|
19
19
|
}
|
|
20
|
+
export interface ExportMember {
|
|
21
|
+
name: string;
|
|
22
|
+
location?: Range;
|
|
23
|
+
}
|
|
20
24
|
export interface ExportRecord {
|
|
21
25
|
name: string;
|
|
22
26
|
exportedAs: string;
|
|
@@ -27,6 +31,7 @@ export interface ExportRecord {
|
|
|
27
31
|
isTypeOnly?: boolean;
|
|
28
32
|
isExternalContract?: boolean;
|
|
29
33
|
localReferences?: string[];
|
|
34
|
+
members?: ExportMember[];
|
|
30
35
|
}
|
|
31
36
|
export interface DependencyEdge {
|
|
32
37
|
source: string;
|
|
@@ -61,6 +66,7 @@ export interface ModuleRecord {
|
|
|
61
66
|
scannedDirectories: string[];
|
|
62
67
|
dynamicImportCandidates: DynamicImportCandidate[];
|
|
63
68
|
localSymbolMap?: Record<string, string[]>;
|
|
69
|
+
localTypeMap?: Record<string, string>;
|
|
64
70
|
}
|
|
65
71
|
export interface WorkspacePackage {
|
|
66
72
|
name: string;
|
|
@@ -101,7 +107,7 @@ export interface DynamicImportCandidate {
|
|
|
101
107
|
contextCode: string;
|
|
102
108
|
}
|
|
103
109
|
export interface Finding {
|
|
104
|
-
rule: "unreachable-file" | "unused-export" | "unreachable-statement" | "constant-condition" | "contradictory-guard" | "schema-impossible-guard" | "parse-recovery" | "unresolved-import" | "unknown-dynamic-import" | "no-entry-points" | "unreachable-dynamic-path" | "protected-contract";
|
|
110
|
+
rule: "unreachable-file" | "unused-export" | "unused-member" | "unreachable-statement" | "constant-condition" | "contradictory-guard" | "schema-impossible-guard" | "parse-recovery" | "unresolved-import" | "unknown-dynamic-import" | "no-entry-points" | "unreachable-dynamic-path" | "protected-contract";
|
|
105
111
|
severity: Severity;
|
|
106
112
|
confidence: Confidence;
|
|
107
113
|
message: string;
|
|
@@ -222,6 +228,7 @@ export interface AnalysisContext {
|
|
|
222
228
|
hasReachableUnknownDynamicBoundary: boolean;
|
|
223
229
|
components: StronglyConnectedComponent[];
|
|
224
230
|
usedExports: Set<string>;
|
|
231
|
+
usedMembers: Set<string>;
|
|
225
232
|
candidateBranches: CandidateBranch[];
|
|
226
233
|
dynamicImportCandidates: DynamicImportCandidate[];
|
|
227
234
|
monorepo?: MonorepoGraph;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAuTA,MAAM,CAAC,MAAM,eAAe,GAA2B;IACrD,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,CAAC;IACT,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC,CAAC,EAAE,yCAAyC;CACpD,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "optiprune",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Resilient static dead-code analyzer for TypeScript and JavaScript workspaces.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -76,22 +76,15 @@
|
|
|
76
76
|
"release": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && npm ci && npm run build"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@babel/cli": "^8.0.4",
|
|
80
|
-
"@babel/core": "^8.0.1",
|
|
81
|
-
"@babel/helper-plugin-utils": "^8.0.1",
|
|
82
|
-
"@babel/parser": "^7.29.7",
|
|
83
|
-
"@babel/plugin-proposal-decorators": "^8.0.2",
|
|
84
|
-
"@babel/plugin-transform-typescript": "^8.0.1",
|
|
85
|
-
"@babel/preset-env": "^8.0.2",
|
|
86
|
-
"@babel/traverse": "^8.0.4",
|
|
87
|
-
"@babel/types": "^8.0.4",
|
|
88
|
-
"@swc/core": "^1.15.47",
|
|
89
79
|
"commander": "^15.0.0",
|
|
90
80
|
"esbuild": "^0.28.1",
|
|
91
81
|
"fast-glob": "^3.3.3",
|
|
92
82
|
"js-yaml": "^5.2.2",
|
|
93
83
|
"pathe": "2.0.3",
|
|
94
84
|
"quickjs-emscripten": "^0.32.0",
|
|
85
|
+
"yuku-ast": "^0.8.3",
|
|
86
|
+
"yuku-codegen": "^0.8.3",
|
|
87
|
+
"yuku-parser": "^0.8.3",
|
|
95
88
|
"z3-solver": "^5.0.0"
|
|
96
89
|
},
|
|
97
90
|
"devDependencies": {
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as t from "@babel/types";
|
|
2
|
-
import { declare } from "@babel/helper-plugin-utils";
|
|
3
|
-
/**
|
|
4
|
-
* A Babel plugin to instrument code for concolic execution.
|
|
5
|
-
* It injects tracing hooks around conditional branches and function calls.
|
|
6
|
-
*/
|
|
7
|
-
export default declare((api) => {
|
|
8
|
-
api.assertVersion("^7.0.0 || ^8.0.0-0");
|
|
9
|
-
return {
|
|
10
|
-
name: "optiprune-instrumentation",
|
|
11
|
-
visitor: {
|
|
12
|
-
Program: {
|
|
13
|
-
enter(path, state) {
|
|
14
|
-
const { filename, coverageVariable } = state.opts;
|
|
15
|
-
const fileId = t.stringLiteral(filename);
|
|
16
|
-
// Initialize coverage variable at the beginning of the program
|
|
17
|
-
const initCoverage = t.expressionStatement(t.callExpression(t.memberExpression(t.identifier(coverageVariable), t.identifier("init")), [fileId]));
|
|
18
|
-
// Mark the injected node to prevent re-instrumentation
|
|
19
|
-
initCoverage.expression.callee._concolicInstrumented = true;
|
|
20
|
-
path.node.body.unshift(initCoverage);
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
// Instrument IfStatement
|
|
24
|
-
IfStatement(path, state) {
|
|
25
|
-
const { filename, coverageVariable } = state.opts;
|
|
26
|
-
const fileId = t.stringLiteral(filename);
|
|
27
|
-
const line = t.numericLiteral(path.node.loc?.start.line || 0);
|
|
28
|
-
const traceCall = t.callExpression(t.memberExpression(t.identifier(coverageVariable), t.identifier("traceBranch")), [
|
|
29
|
-
fileId,
|
|
30
|
-
line,
|
|
31
|
-
path.node.test,
|
|
32
|
-
]);
|
|
33
|
-
traceCall.callee._concolicInstrumented = true;
|
|
34
|
-
// Wrap the test condition with the tracing call
|
|
35
|
-
path.node.test = t.sequenceExpression([traceCall, path.node.test]);
|
|
36
|
-
},
|
|
37
|
-
// Instrument FunctionDeclaration and FunctionExpression
|
|
38
|
-
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression"(path, state) {
|
|
39
|
-
const { filename, coverageVariable } = state.opts;
|
|
40
|
-
const fileId = t.stringLiteral(filename);
|
|
41
|
-
const line = t.numericLiteral(path.node.loc?.start.line || 0);
|
|
42
|
-
const node = path.node;
|
|
43
|
-
const functionName = t.stringLiteral(node.id && t.isIdentifier(node.id) ? node.id.name : "anonymous");
|
|
44
|
-
const traceCall = t.expressionStatement(t.callExpression(t.memberExpression(t.identifier(coverageVariable), t.identifier("traceFunction")), [
|
|
45
|
-
fileId,
|
|
46
|
-
line,
|
|
47
|
-
functionName,
|
|
48
|
-
]));
|
|
49
|
-
traceCall.expression.callee._concolicInstrumented = true;
|
|
50
|
-
if (t.isBlockStatement(path.node.body)) {
|
|
51
|
-
path.node.body.body.unshift(traceCall);
|
|
52
|
-
}
|
|
53
|
-
else { // ArrowFunctionExpression with implicit return
|
|
54
|
-
path.node.body = t.blockStatement([
|
|
55
|
-
traceCall,
|
|
56
|
-
t.returnStatement(path.node.body),
|
|
57
|
-
]);
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
// Instrument CallExpression
|
|
61
|
-
CallExpression(path, state) {
|
|
62
|
-
// Avoid re-instrumenting our own injected calls
|
|
63
|
-
if (path.node.callee._concolicInstrumented) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const { filename, coverageVariable } = state.opts;
|
|
67
|
-
const fileId = t.stringLiteral(filename);
|
|
68
|
-
const line = t.numericLiteral(path.node.loc?.start.line || 0);
|
|
69
|
-
const calleeName = t.stringLiteral(t.isIdentifier(path.node.callee) ? path.node.callee.name : "unknown");
|
|
70
|
-
// Create a helper function call that traces and then executes the original call
|
|
71
|
-
const tracedCall = t.callExpression(t.memberExpression(t.identifier(coverageVariable), t.identifier("traceAndExecuteCall")), [
|
|
72
|
-
fileId,
|
|
73
|
-
line,
|
|
74
|
-
calleeName,
|
|
75
|
-
path.node.callee, // Pass the original callee
|
|
76
|
-
t.arrayExpression(path.node.arguments.map(arg => t.cloneNode(arg))) // Pass cloned arguments
|
|
77
|
-
]);
|
|
78
|
-
tracedCall.callee._concolicInstrumented = true;
|
|
79
|
-
path.replaceWith(tracedCall);
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
//# sourceMappingURL=instrumentation-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation-plugin.js","sourceRoot":"","sources":["../src/instrumentation-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AASrD;;;GAGG;AACH,eAAgB,OAAe,CAAC,CAAC,GAAQ,EAAE,EAAE;IAC3C,GAAG,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;IAExC,OAAO;QACL,IAAI,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