@@ -100,31 +100,42 @@ namespace ts.SymbolDisplay {
100
100
return ScriptElementKind . unknown ;
101
101
}
102
102
103
+ function isDeprecatedDeclaration ( decl : Declaration ) {
104
+ return ! ! ( getCombinedNodeFlagsAlwaysIncludeJSDoc ( decl ) & ModifierFlags . Deprecated ) ;
105
+ }
106
+
107
+ function getNormalizedSymbolModifiers ( symbol : Symbol ) {
108
+ if ( symbol . declarations && symbol . declarations . length ) {
109
+ const [ declaration , ...declarations ] = symbol . declarations ;
110
+ // omit deprecated flag if some declarations are not deprecated
111
+ const excludeFlags = length ( declarations ) && isDeprecatedDeclaration ( declaration ) && some ( declarations , d => ! isDeprecatedDeclaration ( d ) )
112
+ ? ModifierFlags . Deprecated
113
+ : ModifierFlags . None ;
114
+ const modifiers = getNodeModifiers ( declaration , excludeFlags ) ;
115
+ if ( modifiers ) {
116
+ return modifiers . split ( "," ) ;
117
+ }
118
+ }
119
+ return [ ] ;
120
+ }
121
+
103
122
export function getSymbolModifiers ( typeChecker : TypeChecker , symbol : Symbol ) : string {
104
123
if ( ! symbol ) {
105
124
return ScriptElementKindModifier . none ;
106
125
}
107
126
108
- const modifiers = new Set < string > ( ) ;
109
- if ( symbol . declarations && symbol . declarations . length > 0 ) {
110
- const kindModifiers = getNodeModifiers ( symbol . declarations [ 0 ] ) ;
111
- if ( kindModifiers !== ScriptElementKindModifier . none ) {
112
- kindModifiers . split ( "," ) . forEach ( m => modifiers . add ( m ) ) ;
113
- }
114
- }
127
+ const modifiers = new Set ( getNormalizedSymbolModifiers ( symbol ) ) ;
115
128
if ( symbol . flags & SymbolFlags . Alias ) {
116
129
const resolvedSymbol = typeChecker . getAliasedSymbol ( symbol ) ;
117
- if ( resolvedSymbol !== symbol && resolvedSymbol . declarations && resolvedSymbol . declarations . length > 0 ) {
118
- const kindModifiers = getNodeModifiers ( resolvedSymbol . declarations [ 0 ] ) ;
119
- if ( kindModifiers !== ScriptElementKindModifier . none ) {
120
- kindModifiers . split ( "," ) . forEach ( m => modifiers . add ( m ) ) ;
121
- }
130
+ if ( resolvedSymbol !== symbol ) {
131
+ forEach ( getNormalizedSymbolModifiers ( resolvedSymbol ) , modifier => {
132
+ modifiers . add ( modifier ) ;
133
+ } ) ;
122
134
}
123
135
}
124
136
if ( symbol . flags & SymbolFlags . Optional ) {
125
137
modifiers . add ( ScriptElementKindModifier . optionalModifier ) ;
126
138
}
127
-
128
139
return modifiers . size > 0 ? arrayFrom ( modifiers . values ( ) ) . join ( "," ) : ScriptElementKindModifier . none ;
129
140
}
130
141
0 commit comments