-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read properties of undefined (reading 'getName') #21
Comments
While the exception is caught and printed, this is output SVG: ...
if (classOrIf instanceof SimpleAST.Type) {
- name = classOrIf.getSymbol().getName();
+ name = classOrIf.getSymbol() ? classOrIf.getSymbol().getName() : undefined;
- if (name === "__type") {
+ if (name === "__type" || name === undefined) {
name = classOrIf.getAliasSymbol().getName();
}
... no exceptions were thrown, resulting in: Based on my analysis, when Seems like we have two issues, retrieving a |
Would be nice if you could provide a PR for the first issue. |
Thank you for your response @demike. I have submitted a PR to fix the first issue. I have this snippet in my workshop: // parser.ts
/* introduce new function getMethodsAndProperties */
function getMethodsAndProperties(typeNode: SimpleAST.TypeNode) {
console.log(`Node kind name ${typeNode.getKindName()}`);
let propertyDeclarations: SimpleAST.PropertySignature[] = [];
let methodDeclarations: SimpleAST.MethodSignature[] = [];
if (typeNode instanceof SimpleAST.TypeLiteralNode) {
propertyDeclarations = typeNode.getProperties();
methodDeclarations = typeNode.getMethods();
} else if (typeNode instanceof SimpleAST.IntersectionTypeNode) {
const childNodes = typeNode.getTypeNodes();
childNodes.forEach((tn, i) => {
const pm = getMethodsAndProperties(tn);
if (! pm) {
return;
}
propertyDeclarations = propertyDeclarations.concat(pm.propertyDeclarations);
methodDeclarations = methodDeclarations.concat(pm.methodDeclarations);
});
} else if (typeNode instanceof SimpleAST.MappedTypeNode) {
const typeParameter = typeNode.getTypeParameter();
const constraint = typeParameter?.getConstraint();
console.log("MappedType constraint kind name:", constraint?.getKindName());
// typeNode.getChildren().forEach((child, i) => {
// console.log(`Child #${i} kind ${child.getKindName()} text ${child.getText()}`);
// // Type Parameter
// // AsKeyword
// if (child instanceof SimpleAST.TemplateLiteralTypeNode) {
// console.log("Child TemplateLiteralNode");
// console.log(child);
// child.forEachChild((ll) => {
// console.log(`LL ${ll.getText()}`);
// });
// child.forEachDescendant((dd) => {
// console.log(`DD ${dd}`);
// });
// }
// // Syntax List
// });
return;
} else {
return;
}
return {
propertyDeclarations,
methodDeclarations
}
}
export function parseTypes(typeDeclaration: SimpleAST.TypeAliasDeclaration) {
const name = getClassOrInterfaceName(typeDeclaration) || 'undefined';
const t = typeDeclaration.getType();
const typeNode = typeDeclaration.getTypeNode();
let propertyDeclarations: SimpleAST.PropertySignature[] = [];
let methodDeclarations: SimpleAST.MethodSignature[] = [];
if(typeNode instanceof SimpleAST.TypeLiteralNode) {
propertyDeclarations = typeNode.getProperties();
methodDeclarations = typeNode.getMethods();
} else if (typeNode instanceof SimpleAST.IntersectionTypeNode) {
const res = getMethodsAndProperties(typeNode);
if (! res) {
return;
}
propertyDeclarations = res.propertyDeclarations;
methodDeclarations = res.methodDeclarations;
} else {
// no structured type --> lets skip that (for now)
return;
}
...
} With this change, |
Hi there,
While trying to run
tsuml2 --glob test.ts
, the following exception was thrownTypeError: Cannot read properties of undefined (reading 'getName')
. Here is a reproducible example:The text was updated successfully, but these errors were encountered: