export-just-namespace supports TSDeclareFunction too (#534)

This commit is contained in:
Nathan Shively-Sanders
2022-09-13 10:07:17 -07:00
committed by GitHub
parent 9ff4fd36b6
commit 4e6f2cdbeb
2 changed files with 11 additions and 2 deletions

View File

@@ -58,6 +58,7 @@ function isJustNamespace(statements: TSESTree.ProgramStatement[], exportEqualsNa
break;
case AST_NODE_TYPES.ClassDeclaration:
case AST_NODE_TYPES.FunctionDeclaration:
case AST_NODE_TYPES.TSDeclareFunction:
case AST_NODE_TYPES.TSTypeAliasDeclaration:
case AST_NODE_TYPES.TSInterfaceDeclaration:
if (nameMatches(statement.id)) {
@@ -70,8 +71,8 @@ function isJustNamespace(statements: TSESTree.ProgramStatement[], exportEqualsNa
return anyNamespace;
function nameMatches(nameNode: TSESTree.Node | undefined): boolean {
return nameNode !== undefined && nameNode.type === AST_NODE_TYPES.Identifier && nameNode.name === exportEqualsName;
function nameMatches(nameNode: TSESTree.Node | undefined | null): boolean {
return !!nameNode && nameNode.type === AST_NODE_TYPES.Identifier && nameNode.name === exportEqualsName;
}
}

View File

@@ -58,5 +58,13 @@ class Stuff {}
namespace Stuff {}
export = Stuff;
`,
`export = First
namespace First {}
declare function First()
`,
`declare namespace Second {}
export = Second
declare function Second<U, S>(s: U): S
`
],
});