openpetswithchatandmcp/website/analyze-massive-literals.ts
OpenPets Dev 65ac83849e Add 'website/' from commit '966aea480ffe1c340553aa878def30131d2af827'
git-subtree-dir: website
git-subtree-mainline: 8d3849caea
git-subtree-split: 966aea480f
2026-06-17 20:48:39 +00:00

37 lines
1.3 KiB
TypeScript
Executable file

import { Project, SyntaxKind, ObjectLiteralExpression, ArrayLiteralExpression, Node } from 'ts-morph';
console.log('Analyzing test file for large literal nodes...');
const project = new Project({ tsConfigFilePath: 'C:/ScriptoriumAI/scriptoriumai-ui/tsconfig.json' });
const sourceFile = project.getSourceFileOrThrow('C:/ScriptoriumAI/scriptoriumai-ui/src/__tests__/Runboard.telemetry-lockstep-parity.test.tsx');
let largestNodes = [];
sourceFile.forEachDescendant(node => {
if (Node.isObjectLiteralExpression(node) || Node.isArrayLiteralExpression(node)) {
const length = node.getWidth();
if (length > 50000) {
largestNodes.push({
kind: node.getKindName(),
length,
line: node.getStartLineNumber(),
node
});
}
}
});
largestNodes.sort((a, b) => b.length - a.length);
const finalNodes = [];
for (const n of largestNodes) {
const isChild = finalNodes.some(f => f.node.getStart() <= n.node.getStart() && f.node.getEnd() >= n.node.getEnd());
if (!isChild) {
finalNodes.push(n);
}
}
console.log('Found ' + finalNodes.length + ' massive literals');
finalNodes.slice(0, 10).forEach(n => {
console.log(n.kind + ' at line ' + n.line + ': ~' + Math.round(n.length / 1024) + ' KB');
});