[clean] quieter logging

This commit is contained in:
2025-08-07 17:12:04 +01:00
parent ab9a517592
commit f3491f32c0
3 changed files with 12 additions and 13 deletions

View File

@@ -33,7 +33,6 @@ export async function sliceAndWriteCalls(calls, folderPath) {
const { slicedCode } = getSliceAndInfoSync(fileSource, (moduleExports) => {
return [...callBox.entries()].flatMap(([methodName, methodArgsList]) => {
const methodNameNormed = methodName.substring(1);
console.log("Calls for ", methodNameNormed, methodArgsList);
return methodArgsList.map(methodArgsList => {
const methodObj = (methodNameNormed === '') ? moduleExports : moduleExports[methodNameNormed];
if(methodObj === undefined) {
@@ -85,7 +84,7 @@ function driver(folderPath = './candidates/braces') {
const libraryTypesRecorder = new LibraryTypesRecorder(project.getTypeChecker());
// const project = tsc.createProgram([FILE_PATH],);
const checker = project.getTypeChecker();
console.log(`Source files found: ${sourceFiles.length}`, ...sourceFiles.map(sf => sf.getFilePath()));
console.log(`Source files found: ${sourceFiles.length}`);
for (const sourceFile of sourceFiles) {
const filePath = sourceFile.getFilePath();
console.log(`[analyzer] Processing file: ${filePath}`);
@@ -99,7 +98,7 @@ function driver(folderPath = './candidates/braces') {
const callMap = libraryTypesRecorder.generateAllArgumentsForRecordedCalls();
logCallList(callMap, folderPath);
// logCallList(callMap, folderPath);
sliceAndWriteCalls(callMap, folderPath).then(() => {
console.log("Slicing and writing calls done");
});

View File

@@ -72,7 +72,7 @@ export class LibraryTypesRecorder {
*/
instantiateFakerOnType(type,level=1) {
if(level>LEVEL_LIMIT) return undefined;
console.log("Instantiating faker on type", type.getText(), level);
// console.log("Instantiating faker on type", type.getText(), level);
const literalValue = type.getLiteralValue();
if(type.isBooleanLiteral()){
return type.getText() === 'true';
@@ -102,11 +102,11 @@ export class LibraryTypesRecorder {
const declarations = prop.getDeclarations();
let propType = prop.getDeclaredType();
if (declarations.length !== 1) {
console.warn("Multiple declarations for property", propName, "in type", type.getText());
// console.warn("Multiple declarations for property", propName, "in type", type.getText());
} else {
propType = this.checker.getTypeOfSymbolAtLocation(prop, declarations[0]);
}
console.log("Instantiating faker on property", propName, "of type", propType.getText(), "in type", type.getText());
// console.log("Instantiating faker on property", propName, "of type", propType.getText(), "in type", type.getText());
newObj[propName] = this.instantiateFakerOnType(propType,level+1);
}
// TODO - handle functions
@@ -117,7 +117,6 @@ export class LibraryTypesRecorder {
return simpleFaker.helpers.arrayElement(types.map(t => this.instantiateFakerOnType(t)));
}
else {
console.warn("Unknown type to instantiate", type.getText());
if (type.isAny()) {
return simpleFaker.helpers.arrayElement([
simpleFaker.string.sample(),
@@ -127,6 +126,7 @@ export class LibraryTypesRecorder {
[]
]);
}
console.warn("Unknown type to instantiate", type.getText());
return undefined;
}

View File

@@ -26,7 +26,7 @@ export function getImportCallsAndArgumentTypes(importDecls, checker, mainFilePat
// the declaration is callExpression. Verify its based an identifier aliasing import or require
const importExpr = importDecl.getExpression();
const type = checker.getTypeAtLocation(importExpr);
console.log("Type of import expression", checker.getTypeText(type));
// console.log("Type of import expression", checker.getTypeText(type));
// console.log(importExpr);
if (importExpr.isKind(SyntaxKind.Identifier)) {
// import is a require or import
@@ -51,7 +51,9 @@ export function getImportCallsAndArgumentTypes(importDecls, checker, mainFilePat
// const importArgs = importDecl.getArguments();
const parent = importDecl.getParent();
if(!parent?.isKind(SyntaxKind.VariableDeclaration)) {
console.log("Parent of import call", parent?.getKindName(), parent?.getText());
}
if (parent?.isKind(SyntaxKind.VariableDeclaration)) {
// this is a variable declaration
const varDecl = parent;
@@ -72,10 +74,10 @@ export function getImportCallsAndArgumentTypes(importDecls, checker, mainFilePat
console.warn("Nested binding pattern not handled yet", destructuredElementName.getText());
} else {
console.error("Unexpected destructured element", destructuredElementName.getText());
// console.log("Variable name", varName);
}
}
}
console.log("Variable name", varName);
// check if declaration is identifier or object pattern
}
}
@@ -157,7 +159,6 @@ function recordNamespaceImportIdentifierUsage(checker, importNode, mainFilePath,
console.warn("Skipping import reference from other file", referenceSourceFile.getFilePath());
continue;
}
console.log("Compare path", comparePath === '');
// const filePath = referenceSourceFile.getFilePath();
// console.log("Refset for import",filePath);
for (const ref of importRef.getReferences()) {
@@ -176,7 +177,7 @@ function recordNamespaceImportIdentifierUsage(checker, importNode, mainFilePath,
if(callExpression?.getExpression().getDescendantsOfKind(SyntaxKind.Identifier).some(id=>id===ref.getNode())){
// asserted that the call expression is using the importNode
if(callExpression.getExpression().isKind(SyntaxKind.PropertyAccessExpression)){
console.log("Used a submethod of import", ref.getNode().getText(),callExpression.getExpression().getText());
// console.log("Used a submethod of import", ref.getNode().getText(),callExpression.getExpression().getText());
// ref.getNode().getText();
const expressionImportSection = callExpression.getExpression().getText().split('.');
expressionImportSection.shift();
@@ -244,7 +245,6 @@ function recordImportedIdentifierUsage(checker, importNode, mainFilePath, librar
console.warn("Skipping import reference from other file", referenceSourceFile.getFilePath());
continue;
}
console.log("Compare path", comparePath === '');
// const filePath = referenceSourceFile.getFilePath();
// console.log("Refset for import",filePath);
for (const ref of importRef.getReferences()) {