@@ -175,7 +175,7 @@ namespace ts.codefix {
175
175
}
176
176
177
177
function annotateSetAccessor ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , setAccessorDeclaration : SetAccessorDeclaration , program : Program , cancellationToken : CancellationToken ) : void {
178
- const param = setAccessorDeclaration . parameters [ 0 ] ;
178
+ const param = firstOrUndefined ( setAccessorDeclaration . parameters ) ;
179
179
if ( param && isIdentifier ( setAccessorDeclaration . name ) && isIdentifier ( param . name ) ) {
180
180
const type = inferTypeForVariableFromUsage ( setAccessorDeclaration . name , program , cancellationToken ) ||
181
181
inferTypeForVariableFromUsage ( param . name , program , cancellationToken ) ;
@@ -184,12 +184,24 @@ namespace ts.codefix {
184
184
}
185
185
186
186
function annotate ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , declaration : textChanges . TypeAnnotatable , type : Type | undefined , program : Program ) : void {
187
- const checker = program . getTypeChecker ( ) ;
188
- if ( ! type || ! isTypeAccessible ( type , declaration , checker ) ) return ;
189
- const typeNode = checker . typeToTypeNode ( type , declaration ) ;
187
+ const typeNode = type && getTypeNodeIfAccessible ( type , declaration , program . getTypeChecker ( ) ) ;
190
188
if ( typeNode ) changes . insertTypeAnnotation ( sourceFile , declaration , typeNode ) ;
191
189
}
192
190
191
+ function getTypeNodeIfAccessible ( type : Type , enclosingScope : Node , checker : TypeChecker ) : TypeNode | undefined {
192
+ let typeIsAccessible = true ;
193
+ const notAccessible = ( ) => { typeIsAccessible = false ; } ;
194
+ const res = checker . typeToTypeNode ( type , enclosingScope , /*flags*/ undefined , {
195
+ trackSymbol : ( symbol , declaration , meaning ) => {
196
+ typeIsAccessible = typeIsAccessible && checker . isSymbolAccessible ( symbol , declaration , meaning , /*shouldComputeAliasToMarkVisible*/ false ) . accessibility === SymbolAccessibility . Accessible ;
197
+ } ,
198
+ reportInaccessibleThisError : notAccessible ,
199
+ reportPrivateInBaseOfClassExpression : notAccessible ,
200
+ reportInaccessibleUniqueSymbolError : notAccessible ,
201
+ } ) ;
202
+ return typeIsAccessible ? res : undefined ;
203
+ }
204
+
193
205
function getReferences ( token : PropertyName | Token < SyntaxKind . ConstructorKeyword > , program : Program , cancellationToken : CancellationToken ) : ReadonlyArray < Identifier > {
194
206
// Position shouldn't matter since token is not a SourceFile.
195
207
return mapDefined ( FindAllReferences . getReferenceEntriesForNode ( - 1 , token , program , program . getSourceFiles ( ) , cancellationToken ) , entry =>
@@ -216,43 +228,6 @@ namespace ts.codefix {
216
228
}
217
229
}
218
230
219
- function isTypeAccessible ( type : Type , enclosingDeclaration : Declaration , checker : TypeChecker ) : boolean {
220
- let typeIsAccessible = true ;
221
- const notAccessible = ( ) => { typeIsAccessible = false ; } ;
222
- const writer : EmitTextWriter = {
223
- getText : ( ) => "" ,
224
- writeKeyword : noop ,
225
- writeOperator : noop ,
226
- writePunctuation : noop ,
227
- writeSpace : noop ,
228
- writeStringLiteral : noop ,
229
- writeParameter : noop ,
230
- writeProperty : noop ,
231
- writeSymbol : noop ,
232
- write : noop ,
233
- writeTextOfNode : noop ,
234
- rawWrite : noop ,
235
- writeLiteral : noop ,
236
- getTextPos : ( ) => 0 ,
237
- getLine : ( ) => 0 ,
238
- getColumn : ( ) => 0 ,
239
- getIndent : ( ) => 0 ,
240
- isAtStartOfLine : returnFalse ,
241
- writeLine : noop ,
242
- increaseIndent : noop ,
243
- decreaseIndent : noop ,
244
- clear : ( ) => { typeIsAccessible = true ; } ,
245
- trackSymbol : ( symbol , declaration , meaning ) => {
246
- typeIsAccessible = typeIsAccessible && checker . isSymbolAccessible ( symbol , declaration , meaning , /*shouldComputeAliasToMarkVisible*/ false ) . accessibility === SymbolAccessibility . Accessible ;
247
- } ,
248
- reportInaccessibleThisError : notAccessible ,
249
- reportPrivateInBaseOfClassExpression : notAccessible ,
250
- reportInaccessibleUniqueSymbolError : notAccessible ,
251
- } ;
252
- checker . writeType ( type , enclosingDeclaration , /*flags*/ undefined , writer ) ;
253
- return typeIsAccessible ;
254
- }
255
-
256
231
namespace InferFromReference {
257
232
interface CallContext {
258
233
argumentTypes : Type [ ] ;
0 commit comments