Skip to content

Commit ce47269

Browse files
committed
Also exclude class with decorators
Since decorators can introduce arbitrary properties
1 parent 19e4a47 commit ce47269

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31683,10 +31683,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3168331683
if (file) {
3168431684
if (compilerOptions.checkJs === undefined && file.checkJsDirective === undefined && (file.scriptKind === ScriptKind.JS || file.scriptKind === ScriptKind.JSX)) {
3168531685
const declarationFile = forEach(suggestion?.declarations, getSourceFileOfNode);
31686-
const suggestionHasNoExtends = !suggestion?.valueDeclaration || !isClassLike(suggestion.valueDeclaration) || suggestion.valueDeclaration.heritageClauses?.length
31686+
const suggestionHasNoExtendsOrDecorators = !suggestion?.valueDeclaration
31687+
|| !isClassLike(suggestion.valueDeclaration)
31688+
|| suggestion.valueDeclaration.heritageClauses?.length
31689+
|| classOrConstructorParameterIsDecorated(/*useLegacyDecorators*/ false, suggestion.valueDeclaration);
3168731690
return !(file !== declarationFile && !!declarationFile && isGlobalSourceFile(declarationFile))
31688-
&& !(excludeClasses && suggestion && suggestion.flags & SymbolFlags.Class && suggestionHasNoExtends)
31689-
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword && suggestionHasNoExtends);
31691+
&& !(excludeClasses && suggestion && suggestion.flags & SymbolFlags.Class && suggestionHasNoExtendsOrDecorators)
31692+
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword && suggestionHasNoExtendsOrDecorators);
3169031693
}
3169131694
}
3169231695
return false;

tests/cases/fourslash/codeFixSpellingJs9.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
//// const person = new Person();
2424
//// person.[|getFavoriteColour|]();
2525
//// person.[|getFavoriteColoxr|]();
26+
//// function deco() { }
27+
//// @deco
28+
//// class Art {
29+
//// style = true
30+
//// }
31+
//// const a = new Art()
32+
//// a.[|stylo|]
33+
//// @deco
34+
//// class Double extends Art { }
35+
//// const db = new Double()
36+
//// db.[|stylo|]
2637
verify.codeFixAll({
2738
fixId: "fixSpelling",
2839
fixAllDescription: "Fix all detected spelling errors",
@@ -48,5 +59,16 @@ class Person {
4859
4960
const person = new Person();
5061
person.getFavoriteColor();
51-
person.getFavoriteColor();`,
62+
person.getFavoriteColor();
63+
function deco() { }
64+
@deco
65+
class Art {
66+
style = true
67+
}
68+
const a = new Art()
69+
a.stylo
70+
@deco
71+
class Double extends Art { }
72+
const db = new Double()
73+
db.stylo`,
5274
});

0 commit comments

Comments
 (0)