Skip to content

Commit

Permalink
fix(core): wrong external paths for grouped references
Browse files Browse the repository at this point in the history
  • Loading branch information
elyukai committed Mar 1, 2022
1 parent 99b56c0 commit 3e08cd1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ const traverseAbsoluteParentModules = (currentModule: ts.Symbol, checker: ts.Typ
}
}

const outerMostGroupName = (group: ParentGroup): string => {
if (group.parentGroup) {
return outerMostGroupName(group.parentGroup)
}
else {
return group.name
}
}

const propertyNameToString = (propertyName: ts.PropertyName): string =>
ts.isComputedPropertyName(propertyName)
? propertyName.expression.getText()
Expand Down Expand Up @@ -411,11 +420,13 @@ const nodeToAst = (node: ts.Node, checker: ts.TypeChecker, typeArguments: { [nam
// such as "Test.Collection" in "Test.Collection.Plain", inside left the left is "Test"
: node.typeName.right.escapedText.toString()

if (name in typeArguments) {
const parentGroup = symbol ? traverseAbsoluteParentModules(symbol, checker) : undefined

if (parentGroup === undefined && name in typeArguments) {
return typeArguments[name]!
}

const parentGroup = symbol ? traverseAbsoluteParentModules(symbol, checker) : undefined
const outerMostReference = parentGroup ? outerMostGroupName(parentGroup) : name

const importNodes = node.getSourceFile().statements.filter(ts.isImportDeclaration)

Expand All @@ -424,7 +435,7 @@ const nodeToAst = (node: ts.Node, checker: ts.TypeChecker, typeArguments: { [nam

if (namedBindings && ts.isNamedImports(namedBindings)) {
return namedBindings.elements.some(
namedBinding => namedBinding.name.escapedText === name
namedBinding => namedBinding.name.escapedText === outerMostReference
)
}
else {
Expand All @@ -441,7 +452,7 @@ const nodeToAst = (node: ts.Node, checker: ts.TypeChecker, typeArguments: { [nam
jsDoc,
name,
parentGroup,
externalFilePath
externalFilePath,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ else {
program
.getSourceFiles()
.filter(file => tsFiles.includes(file.fileName))
// .filter(file => file.fileName.includes("_Prerequisite"))
// .filter(file => file.fileName.includes("Curse"))
.forEach(file => {
const relativePath = relative(typesRootPath, file.fileName)
const dir = dirname(relativePath)
Expand Down

0 comments on commit 3e08cd1

Please sign in to comment.