@@ -12,7 +12,7 @@ namespace ts.codefix {
12
12
registerCodeFix ( {
13
13
errorCodes,
14
14
getCodeActions ( context ) {
15
- const info = getInfo ( context . sourceFile , context . span . start , context . program . getTypeChecker ( ) ) ;
15
+ const info = getInfo ( context . sourceFile , context . span . start , context . program . getTypeChecker ( ) , context . program ) ;
16
16
if ( ! info ) return undefined ;
17
17
18
18
if ( info . kind === InfoKind . Enum ) {
@@ -37,7 +37,7 @@ namespace ts.codefix {
37
37
38
38
return createCombinedCodeActions ( textChanges . ChangeTracker . with ( context , changes => {
39
39
eachDiagnostic ( context , errorCodes , diag => {
40
- const info = getInfo ( diag . file , diag . start , checker ) ;
40
+ const info = getInfo ( diag . file , diag . start , checker , context . program ) ;
41
41
if ( ! info || ! addToSeen ( seen , getNodeId ( info . parentDeclaration ) + "#" + info . token . text ) ) {
42
42
return ;
43
43
}
@@ -113,7 +113,7 @@ namespace ts.codefix {
113
113
}
114
114
type Info = EnumInfo | ClassOrInterfaceInfo ;
115
115
116
- function getInfo ( tokenSourceFile : SourceFile , tokenPos : number , checker : TypeChecker ) : Info | undefined {
116
+ function getInfo ( tokenSourceFile : SourceFile , tokenPos : number , checker : TypeChecker , program : Program ) : Info | undefined {
117
117
// The identifier of the missing property. eg:
118
118
// this.missing = 1;
119
119
// ^^^^^^^
@@ -131,15 +131,15 @@ namespace ts.codefix {
131
131
132
132
// Prefer to change the class instead of the interface if they are merged
133
133
const classOrInterface = find ( symbol . declarations , isClassLike ) || find ( symbol . declarations , isInterfaceDeclaration ) ;
134
- if ( classOrInterface ) {
134
+ if ( classOrInterface && ! program . isSourceFileFromExternalLibrary ( classOrInterface . getSourceFile ( ) ) ) {
135
135
const makeStatic = ( ( leftExpressionType as TypeReference ) . target || leftExpressionType ) !== checker . getDeclaredTypeOfSymbol ( symbol ) ;
136
136
const declSourceFile = classOrInterface . getSourceFile ( ) ;
137
137
const inJs = isSourceFileJS ( declSourceFile ) ;
138
138
const call = tryCast ( parent . parent , isCallExpression ) ;
139
139
return { kind : InfoKind . ClassOrInterface , token, parentDeclaration : classOrInterface , makeStatic, declSourceFile, inJs, call } ;
140
140
}
141
141
const enumDeclaration = find ( symbol . declarations , isEnumDeclaration ) ;
142
- if ( enumDeclaration ) {
142
+ if ( enumDeclaration && ! program . isSourceFileFromExternalLibrary ( enumDeclaration . getSourceFile ( ) ) ) {
143
143
return { kind : InfoKind . Enum , token, parentDeclaration : enumDeclaration } ;
144
144
}
145
145
return undefined ;
0 commit comments