[clean] quieter logging
This commit is contained in:
@@ -33,7 +33,6 @@ export async function sliceAndWriteCalls(calls, folderPath) {
|
|||||||
const { slicedCode } = getSliceAndInfoSync(fileSource, (moduleExports) => {
|
const { slicedCode } = getSliceAndInfoSync(fileSource, (moduleExports) => {
|
||||||
return [...callBox.entries()].flatMap(([methodName, methodArgsList]) => {
|
return [...callBox.entries()].flatMap(([methodName, methodArgsList]) => {
|
||||||
const methodNameNormed = methodName.substring(1);
|
const methodNameNormed = methodName.substring(1);
|
||||||
console.log("Calls for ", methodNameNormed, methodArgsList);
|
|
||||||
return methodArgsList.map(methodArgsList => {
|
return methodArgsList.map(methodArgsList => {
|
||||||
const methodObj = (methodNameNormed === '') ? moduleExports : moduleExports[methodNameNormed];
|
const methodObj = (methodNameNormed === '') ? moduleExports : moduleExports[methodNameNormed];
|
||||||
if(methodObj === undefined) {
|
if(methodObj === undefined) {
|
||||||
@@ -85,7 +84,7 @@ function driver(folderPath = './candidates/braces') {
|
|||||||
const libraryTypesRecorder = new LibraryTypesRecorder(project.getTypeChecker());
|
const libraryTypesRecorder = new LibraryTypesRecorder(project.getTypeChecker());
|
||||||
// const project = tsc.createProgram([FILE_PATH],);
|
// const project = tsc.createProgram([FILE_PATH],);
|
||||||
const checker = project.getTypeChecker();
|
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) {
|
for (const sourceFile of sourceFiles) {
|
||||||
const filePath = sourceFile.getFilePath();
|
const filePath = sourceFile.getFilePath();
|
||||||
console.log(`[analyzer] Processing file: ${filePath}`);
|
console.log(`[analyzer] Processing file: ${filePath}`);
|
||||||
@@ -99,7 +98,7 @@ function driver(folderPath = './candidates/braces') {
|
|||||||
const callMap = libraryTypesRecorder.generateAllArgumentsForRecordedCalls();
|
const callMap = libraryTypesRecorder.generateAllArgumentsForRecordedCalls();
|
||||||
|
|
||||||
|
|
||||||
logCallList(callMap, folderPath);
|
// logCallList(callMap, folderPath);
|
||||||
sliceAndWriteCalls(callMap, folderPath).then(() => {
|
sliceAndWriteCalls(callMap, folderPath).then(() => {
|
||||||
console.log("Slicing and writing calls done");
|
console.log("Slicing and writing calls done");
|
||||||
});
|
});
|
||||||
|
@@ -72,7 +72,7 @@ export class LibraryTypesRecorder {
|
|||||||
*/
|
*/
|
||||||
instantiateFakerOnType(type,level=1) {
|
instantiateFakerOnType(type,level=1) {
|
||||||
if(level>LEVEL_LIMIT) return undefined;
|
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();
|
const literalValue = type.getLiteralValue();
|
||||||
if(type.isBooleanLiteral()){
|
if(type.isBooleanLiteral()){
|
||||||
return type.getText() === 'true';
|
return type.getText() === 'true';
|
||||||
@@ -102,11 +102,11 @@ export class LibraryTypesRecorder {
|
|||||||
const declarations = prop.getDeclarations();
|
const declarations = prop.getDeclarations();
|
||||||
let propType = prop.getDeclaredType();
|
let propType = prop.getDeclaredType();
|
||||||
if (declarations.length !== 1) {
|
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 {
|
} else {
|
||||||
propType = this.checker.getTypeOfSymbolAtLocation(prop, declarations[0]);
|
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);
|
newObj[propName] = this.instantiateFakerOnType(propType,level+1);
|
||||||
}
|
}
|
||||||
// TODO - handle functions
|
// TODO - handle functions
|
||||||
@@ -117,7 +117,6 @@ export class LibraryTypesRecorder {
|
|||||||
return simpleFaker.helpers.arrayElement(types.map(t => this.instantiateFakerOnType(t)));
|
return simpleFaker.helpers.arrayElement(types.map(t => this.instantiateFakerOnType(t)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.warn("Unknown type to instantiate", type.getText());
|
|
||||||
if (type.isAny()) {
|
if (type.isAny()) {
|
||||||
return simpleFaker.helpers.arrayElement([
|
return simpleFaker.helpers.arrayElement([
|
||||||
simpleFaker.string.sample(),
|
simpleFaker.string.sample(),
|
||||||
@@ -127,6 +126,7 @@ export class LibraryTypesRecorder {
|
|||||||
[]
|
[]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
console.warn("Unknown type to instantiate", type.getText());
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ export function getImportCallsAndArgumentTypes(importDecls, checker, mainFilePat
|
|||||||
// the declaration is callExpression. Verify its based an identifier aliasing import or require
|
// the declaration is callExpression. Verify its based an identifier aliasing import or require
|
||||||
const importExpr = importDecl.getExpression();
|
const importExpr = importDecl.getExpression();
|
||||||
const type = checker.getTypeAtLocation(importExpr);
|
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);
|
// console.log(importExpr);
|
||||||
if (importExpr.isKind(SyntaxKind.Identifier)) {
|
if (importExpr.isKind(SyntaxKind.Identifier)) {
|
||||||
// import is a require or import
|
// import is a require or import
|
||||||
@@ -51,7 +51,9 @@ export function getImportCallsAndArgumentTypes(importDecls, checker, mainFilePat
|
|||||||
// const importArgs = importDecl.getArguments();
|
// const importArgs = importDecl.getArguments();
|
||||||
|
|
||||||
const parent = importDecl.getParent();
|
const parent = importDecl.getParent();
|
||||||
|
if(!parent?.isKind(SyntaxKind.VariableDeclaration)) {
|
||||||
console.log("Parent of import call", parent?.getKindName(), parent?.getText());
|
console.log("Parent of import call", parent?.getKindName(), parent?.getText());
|
||||||
|
}
|
||||||
if (parent?.isKind(SyntaxKind.VariableDeclaration)) {
|
if (parent?.isKind(SyntaxKind.VariableDeclaration)) {
|
||||||
// this is a variable declaration
|
// this is a variable declaration
|
||||||
const varDecl = parent;
|
const varDecl = parent;
|
||||||
@@ -72,10 +74,10 @@ export function getImportCallsAndArgumentTypes(importDecls, checker, mainFilePat
|
|||||||
console.warn("Nested binding pattern not handled yet", destructuredElementName.getText());
|
console.warn("Nested binding pattern not handled yet", destructuredElementName.getText());
|
||||||
} else {
|
} else {
|
||||||
console.error("Unexpected destructured element", destructuredElementName.getText());
|
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
|
// 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());
|
console.warn("Skipping import reference from other file", referenceSourceFile.getFilePath());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
console.log("Compare path", comparePath === '');
|
|
||||||
// const filePath = referenceSourceFile.getFilePath();
|
// const filePath = referenceSourceFile.getFilePath();
|
||||||
// console.log("Refset for import",filePath);
|
// console.log("Refset for import",filePath);
|
||||||
for (const ref of importRef.getReferences()) {
|
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())){
|
if(callExpression?.getExpression().getDescendantsOfKind(SyntaxKind.Identifier).some(id=>id===ref.getNode())){
|
||||||
// asserted that the call expression is using the importNode
|
// asserted that the call expression is using the importNode
|
||||||
if(callExpression.getExpression().isKind(SyntaxKind.PropertyAccessExpression)){
|
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();
|
// ref.getNode().getText();
|
||||||
const expressionImportSection = callExpression.getExpression().getText().split('.');
|
const expressionImportSection = callExpression.getExpression().getText().split('.');
|
||||||
expressionImportSection.shift();
|
expressionImportSection.shift();
|
||||||
@@ -244,7 +245,6 @@ function recordImportedIdentifierUsage(checker, importNode, mainFilePath, librar
|
|||||||
console.warn("Skipping import reference from other file", referenceSourceFile.getFilePath());
|
console.warn("Skipping import reference from other file", referenceSourceFile.getFilePath());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
console.log("Compare path", comparePath === '');
|
|
||||||
// const filePath = referenceSourceFile.getFilePath();
|
// const filePath = referenceSourceFile.getFilePath();
|
||||||
// console.log("Refset for import",filePath);
|
// console.log("Refset for import",filePath);
|
||||||
for (const ref of importRef.getReferences()) {
|
for (const ref of importRef.getReferences()) {
|
||||||
|
Reference in New Issue
Block a user