@@ -34,6 +34,55 @@ export interface IFollowAliasesResult {
3434}
3535
3636export class SymbolAnalyzer {
37+
38+ /**
39+ * This function determines which ts.Node kinds will generate an AstDeclaration.
40+ * These correspond to the definitions that we can add AEDoc to.
41+ */
42+ public static isAstDeclaration ( kind : ts . SyntaxKind ) : boolean {
43+ // (alphabetical order)
44+ switch ( kind ) {
45+ case ts . SyntaxKind . ClassDeclaration :
46+ case ts . SyntaxKind . EnumDeclaration :
47+ case ts . SyntaxKind . EnumMember :
48+ case ts . SyntaxKind . FunctionDeclaration :
49+ case ts . SyntaxKind . InterfaceDeclaration :
50+ case ts . SyntaxKind . MethodDeclaration :
51+ case ts . SyntaxKind . MethodSignature :
52+
53+ // ModuleDeclaration is used for both "module" and "namespace" declarations
54+ case ts . SyntaxKind . ModuleDeclaration :
55+ case ts . SyntaxKind . PropertyDeclaration :
56+ case ts . SyntaxKind . PropertySignature :
57+
58+ // SourceFile is used for "import * as file from 'file';"
59+ case ts . SyntaxKind . SourceFile :
60+ case ts . SyntaxKind . TypeAliasDeclaration :
61+ case ts . SyntaxKind . VariableDeclaration :
62+ return true ;
63+ }
64+ return false ;
65+ }
66+
67+ /**
68+ * This function detects the subset of isAstDeclaration() items that can use
69+ * the "export" keyword. This is part of the heuristic for recognizing ambient types.
70+ */
71+ public static isExportableAstDeclaration ( kind : ts . SyntaxKind ) : boolean {
72+ // (alphabetical order)
73+ switch ( kind ) {
74+ case ts . SyntaxKind . ClassDeclaration :
75+ case ts . SyntaxKind . EnumDeclaration :
76+ case ts . SyntaxKind . FunctionDeclaration :
77+ case ts . SyntaxKind . InterfaceDeclaration :
78+ case ts . SyntaxKind . ModuleDeclaration :
79+ case ts . SyntaxKind . TypeAliasDeclaration :
80+ case ts . SyntaxKind . VariableDeclaration :
81+ return true ;
82+ }
83+ return false ;
84+ }
85+
3786 /**
3887 * For the given symbol, follow imports and type alias to find the symbol that represents
3988 * the original definition.
@@ -96,19 +145,11 @@ export class SymbolAnalyzer {
96145 // Is the followedSymbol actually the kind of thing that can be ambient?
97146 if ( isAmbient ) {
98147 for ( const declaration of current . declarations || [ ] ) {
99- switch ( declaration . kind ) {
100- case ts . SyntaxKind . ClassDeclaration :
101- case ts . SyntaxKind . InterfaceDeclaration :
102- case ts . SyntaxKind . FunctionDeclaration :
103- case ts . SyntaxKind . ModuleDeclaration :
104- case ts . SyntaxKind . VariableDeclaration :
105- // These actually need "export" keywords
106- break ;
107- default :
108- // Everything else we assume is some kind of nested declaration that
109- // doesn't need it.
110- isAmbient = false ;
111- break ;
148+ // These actually need "export" keywords
149+ if ( ! SymbolAnalyzer . isExportableAstDeclaration ( declaration . kind ) ) {
150+ // Everything else we assume is some kind of nested declaration that
151+ // doesn't need it.
152+ isAmbient = false ;
112153 }
113154 }
114155 }
0 commit comments