Skip to content

Commit

Permalink
fix(api): find nearest signature recursively
Browse files Browse the repository at this point in the history
fixes #9
  • Loading branch information
mxsdev committed Nov 7, 2022
1 parent db02e7b commit ec3b53b
Show file tree
Hide file tree
Showing 6 changed files with 2,280 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/api/src/tree.ts
Expand Up @@ -56,6 +56,7 @@ import {
isReadonlyTupleType,
getSymbolExports,
isNamespace,
getSignaturesOfType,
} from "./util"

const maxDepthExceeded: TypeInfo = { kind: "max_depth", id: getEmptyTypeId() }
Expand Down Expand Up @@ -693,7 +694,10 @@ function resolveSignature(
const isConstructCallExpression =
node?.parent.kind === ts.SyntaxKind.NewExpression

const signature = getResolvedSignature(ctx, node)
const signature =
getSignaturesOfType(ctx, type).length > 0
? getResolvedSignature(ctx, node)
: undefined

const signatureTypeArguments = signature
? getSignatureTypeArguments(ctx, signature, node)
Expand Down
14 changes: 9 additions & 5 deletions packages/api/src/util.ts
Expand Up @@ -673,11 +673,15 @@ export function getCallLikeExpression(
{ ts }: TypescriptContext,
node: ts.Node
) {
return ts.isCallLikeExpression(node)
? node
: ts.isCallLikeExpression(node.parent)
? node.parent
: undefined
while (node && !ts.isSourceFile(node)) {
if (ts.isCallLikeExpression(node)) {
return node
}

node = node.parent
}

return undefined
}

/**
Expand Down

0 comments on commit ec3b53b

Please sign in to comment.