37 lines
1.3 KiB
TypeScript
Executable file
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');
|
|
});
|
|
|