diff --git a/src/utils/infer-names.ts b/src/utils/infer-names.ts index 4134d5c..08f685a 100644 --- a/src/utils/infer-names.ts +++ b/src/utils/infer-names.ts @@ -12,12 +12,11 @@ export const inferVarTemplateName = (node: ts.Node): string[] => { return [lowerFirst(inferNewExpressionVar(node))] } else if (ts.isCallExpression(node)) { const methodName = getMethodName(node) - const name = MethodCallRegex.exec(methodName)?.groups?.name - if (!name) { + if (!methodName) { return } - return getUniqueVariants(name).map(lowerFirst) + return getUniqueVariants(methodName).map(lowerFirst) } } @@ -27,7 +26,7 @@ export const inferForVarTemplate = (node: ts.Node): string[] => { return } - const clean = subjectName?.replace(/^(?:all)?(.+?)(?:List)?$/, "$1") + const clean = subjectName.replace(/^(?:all)?(.+?)(?:List)?$/, "$1") return getUniqueVariants(clean) .map(pluralize.singular) @@ -46,14 +45,20 @@ function getForExpressionName(node: ts.Node) { return node.text } else if (ts.isPropertyAccessExpression(node)) { return node.name.text + } else if (ts.isCallExpression(node)) { + return getMethodName(node) } } function getMethodName(node: ts.CallExpression) { - if (ts.isIdentifier(node.expression)) { - return node.expression.text - } else if (ts.isPropertyAccessExpression(node.expression)) { - return node.expression.name.text + return MethodCallRegex.exec(getText())?.groups?.name + + function getText() { + if (ts.isIdentifier(node.expression)) { + return node.expression.text + } else if (ts.isPropertyAccessExpression(node.expression)) { + return node.expression.name.text + } } }