@@ -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,12 +113,7 @@ namespace ts.codefix {
113
113
}
114
114
type Info = EnumInfo | ClassOrInterfaceInfo ;
115
115
116
- function isInNodeModulesDeclarationFile ( node : Node ) {
117
- const sourceFile = getSourceFileOfNode ( node ) ;
118
- return sourceFile . isDeclarationFile && startsWith ( sourceFile . resolvedPath , "node_modules/" ) || sourceFile . resolvedPath . indexOf ( "/node_modules/" ) !== - 1 ;
119
- }
120
-
121
- function getInfo ( tokenSourceFile : SourceFile , tokenPos : number , checker : TypeChecker ) : Info | undefined {
116
+ function getInfo ( tokenSourceFile : SourceFile , tokenPos : number , checker : TypeChecker , program : Program ) : Info | undefined {
122
117
// The identifier of the missing property. eg:
123
118
// this.missing = 1;
124
119
// ^^^^^^^
@@ -136,15 +131,15 @@ namespace ts.codefix {
136
131
137
132
// Prefer to change the class instead of the interface if they are merged
138
133
const classOrInterface = find ( symbol . declarations , isClassLike ) || find ( symbol . declarations , isInterfaceDeclaration ) ;
139
- if ( classOrInterface && ! isInNodeModulesDeclarationFile ( classOrInterface ) ) {
134
+ if ( classOrInterface && ! program . isSourceFileFromExternalLibrary ( classOrInterface . getSourceFile ( ) ) ) {
140
135
const makeStatic = ( ( leftExpressionType as TypeReference ) . target || leftExpressionType ) !== checker . getDeclaredTypeOfSymbol ( symbol ) ;
141
136
const declSourceFile = classOrInterface . getSourceFile ( ) ;
142
137
const inJs = isSourceFileJS ( declSourceFile ) ;
143
138
const call = tryCast ( parent . parent , isCallExpression ) ;
144
139
return { kind : InfoKind . ClassOrInterface , token, parentDeclaration : classOrInterface , makeStatic, declSourceFile, inJs, call } ;
145
140
}
146
141
const enumDeclaration = find ( symbol . declarations , isEnumDeclaration ) ;
147
- if ( enumDeclaration && ! isInNodeModulesDeclarationFile ( enumDeclaration ) ) {
142
+ if ( enumDeclaration && ! program . isSourceFileFromExternalLibrary ( enumDeclaration . getSourceFile ( ) ) ) {
148
143
return { kind : InfoKind . Enum , token, parentDeclaration : enumDeclaration } ;
149
144
}
150
145
return undefined ;
0 commit comments