@papicandela/mcx-core 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +20 -1
- package/package.json +1 -1
- package/src/sandbox/analyzer/analyzer.ts +34 -2
package/dist/index.js
CHANGED
|
@@ -6005,6 +6005,25 @@ var allRules = [
|
|
|
6005
6005
|
];
|
|
6006
6006
|
|
|
6007
6007
|
// src/sandbox/analyzer/analyzer.ts
|
|
6008
|
+
var CACHE_MAX_SIZE = 10;
|
|
6009
|
+
var visitorMapCache = new Map;
|
|
6010
|
+
function getVisitorMap(rules, config) {
|
|
6011
|
+
const cacheKey = JSON.stringify(config.rules);
|
|
6012
|
+
let map = visitorMapCache.get(cacheKey);
|
|
6013
|
+
if (map) {
|
|
6014
|
+
visitorMapCache.delete(cacheKey);
|
|
6015
|
+
visitorMapCache.set(cacheKey, map);
|
|
6016
|
+
return map;
|
|
6017
|
+
}
|
|
6018
|
+
map = buildVisitorMap(rules, config);
|
|
6019
|
+
if (visitorMapCache.size >= CACHE_MAX_SIZE) {
|
|
6020
|
+
const oldest = visitorMapCache.keys().next().value;
|
|
6021
|
+
if (oldest)
|
|
6022
|
+
visitorMapCache.delete(oldest);
|
|
6023
|
+
}
|
|
6024
|
+
visitorMapCache.set(cacheKey, map);
|
|
6025
|
+
return map;
|
|
6026
|
+
}
|
|
6008
6027
|
function buildVisitorMap(rules, config) {
|
|
6009
6028
|
const map = new Map;
|
|
6010
6029
|
for (const rule6 of rules) {
|
|
@@ -6093,7 +6112,7 @@ function analyze(code, config = {}) {
|
|
|
6093
6112
|
elapsed: performance.now() - start
|
|
6094
6113
|
};
|
|
6095
6114
|
}
|
|
6096
|
-
const visitorMap =
|
|
6115
|
+
const visitorMap = getVisitorMap(allRules, fullConfig);
|
|
6097
6116
|
const context = {
|
|
6098
6117
|
code,
|
|
6099
6118
|
getLine: (node) => getLineNumber(code, node.start),
|
package/package.json
CHANGED
|
@@ -36,6 +36,38 @@ import { allRules } from "./rules/index.js";
|
|
|
36
36
|
*/
|
|
37
37
|
type VisitorMap = Map<string, Array<{ rule: Rule; visitor: Rule["visitors"][string] }>>;
|
|
38
38
|
|
|
39
|
+
// Cache for visitor maps - keyed by stringified rules config (LRU with max 10 entries)
|
|
40
|
+
const CACHE_MAX_SIZE = 10;
|
|
41
|
+
const visitorMapCache = new Map<string, VisitorMap>();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get or build a visitor map (cached for performance with LRU eviction)
|
|
45
|
+
*/
|
|
46
|
+
function getVisitorMap(rules: Rule[], config: Required<AnalysisConfig>): VisitorMap {
|
|
47
|
+
// Create cache key from rules config
|
|
48
|
+
const cacheKey = JSON.stringify(config.rules);
|
|
49
|
+
|
|
50
|
+
let map = visitorMapCache.get(cacheKey);
|
|
51
|
+
if (map) {
|
|
52
|
+
// Move to end for LRU (delete and re-add)
|
|
53
|
+
visitorMapCache.delete(cacheKey);
|
|
54
|
+
visitorMapCache.set(cacheKey, map);
|
|
55
|
+
return map;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Build new map
|
|
59
|
+
map = buildVisitorMap(rules, config);
|
|
60
|
+
|
|
61
|
+
// Evict oldest if at capacity
|
|
62
|
+
if (visitorMapCache.size >= CACHE_MAX_SIZE) {
|
|
63
|
+
const oldest = visitorMapCache.keys().next().value;
|
|
64
|
+
if (oldest) visitorMapCache.delete(oldest);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
visitorMapCache.set(cacheKey, map);
|
|
68
|
+
return map;
|
|
69
|
+
}
|
|
70
|
+
|
|
39
71
|
/**
|
|
40
72
|
* Build a visitor map from rules for efficient traversal
|
|
41
73
|
*/
|
|
@@ -162,8 +194,8 @@ export function analyze(
|
|
|
162
194
|
};
|
|
163
195
|
}
|
|
164
196
|
|
|
165
|
-
//
|
|
166
|
-
const visitorMap =
|
|
197
|
+
// Get visitor map (cached for repeated calls with same config)
|
|
198
|
+
const visitorMap = getVisitorMap(allRules, fullConfig);
|
|
167
199
|
|
|
168
200
|
// Create context
|
|
169
201
|
const context: RuleContext = {
|