Skip to content

Commit c79ec7b

Browse files
authored
fix(45225): do not show add missing member QF for libraries files (microsoft#45231)
1 parent 7e8bba6 commit c79ec7b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/services/codefixes/fixAddMissingMember.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace ts.codefix {
171171
if (isIdentifier(token) && isCallExpression(parent.parent)) {
172172
const moduleDeclaration = find(symbol.declarations, isModuleDeclaration);
173173
const moduleDeclarationSourceFile = moduleDeclaration?.getSourceFile();
174-
if (moduleDeclaration && moduleDeclarationSourceFile && !program.isSourceFileFromExternalLibrary(moduleDeclarationSourceFile)) {
174+
if (moduleDeclaration && moduleDeclarationSourceFile && !isSourceFileFromLibrary(program, moduleDeclarationSourceFile)) {
175175
return { kind: InfoKind.Function, token, call: parent.parent, sourceFile, modifierFlags: ModifierFlags.Export, parentDeclaration: moduleDeclaration };
176176
}
177177

@@ -180,7 +180,7 @@ namespace ts.codefix {
180180
return;
181181
}
182182

183-
if (moduleSourceFile && !program.isSourceFileFromExternalLibrary(moduleSourceFile)) {
183+
if (moduleSourceFile && !isSourceFileFromLibrary(program, moduleSourceFile)) {
184184
return { kind: InfoKind.Function, token, call: parent.parent, sourceFile: moduleSourceFile, modifierFlags: ModifierFlags.Export, parentDeclaration: moduleSourceFile };
185185
}
186186
}
@@ -193,7 +193,7 @@ namespace ts.codefix {
193193

194194
// Prefer to change the class instead of the interface if they are merged
195195
const classOrInterface = classDeclaration || find(symbol.declarations, isInterfaceDeclaration);
196-
if (classOrInterface && !program.isSourceFileFromExternalLibrary(classOrInterface.getSourceFile())) {
196+
if (classOrInterface && !isSourceFileFromLibrary(program, classOrInterface.getSourceFile())) {
197197
const makeStatic = ((leftExpressionType as TypeReference).target || leftExpressionType) !== checker.getDeclaredTypeOfSymbol(symbol);
198198
if (makeStatic && (isPrivateIdentifier(token) || isInterfaceDeclaration(classOrInterface))) {
199199
return undefined;
@@ -207,12 +207,16 @@ namespace ts.codefix {
207207
}
208208

209209
const enumDeclaration = find(symbol.declarations, isEnumDeclaration);
210-
if (enumDeclaration && !isPrivateIdentifier(token) && !program.isSourceFileFromExternalLibrary(enumDeclaration.getSourceFile())) {
210+
if (enumDeclaration && !isPrivateIdentifier(token) && !isSourceFileFromLibrary(program, enumDeclaration.getSourceFile())) {
211211
return { kind: InfoKind.Enum, token, parentDeclaration: enumDeclaration };
212212
}
213213
return undefined;
214214
}
215215

216+
function isSourceFileFromLibrary(program: Program, node: SourceFile) {
217+
return program.isSourceFileFromExternalLibrary(node) || program.isSourceFileDefaultLibrary(node);
218+
}
219+
216220
function getActionsForMissingMemberDeclaration(context: CodeFixContext, info: ClassOrInterfaceInfo): CodeFixAction[] | undefined {
217221
return info.isJSFile ? singleElementArray(createActionForAddMissingMemberInJavascriptFile(context, info)) :
218222
createActionsForAddMissingMemberInTypeScriptFile(context, info);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////declare let p: Promise<string>;
4+
////async function f() {
5+
//// p.toLowerCase();
6+
////}
7+
8+
verify.not.codeFixAvailable("fixMissingMember");

0 commit comments

Comments
 (0)