Skip to content

Commit

Permalink
Also exclude class with decorators
Browse files Browse the repository at this point in the history
Since decorators can introduce arbitrary properties
  • Loading branch information
sandersn committed Jul 26, 2023
1 parent 19e4a47 commit ce47269
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31683,10 +31683,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (file) {
if (compilerOptions.checkJs === undefined && file.checkJsDirective === undefined && (file.scriptKind === ScriptKind.JS || file.scriptKind === ScriptKind.JSX)) {
const declarationFile = forEach(suggestion?.declarations, getSourceFileOfNode);
const suggestionHasNoExtends = !suggestion?.valueDeclaration || !isClassLike(suggestion.valueDeclaration) || suggestion.valueDeclaration.heritageClauses?.length
const suggestionHasNoExtendsOrDecorators = !suggestion?.valueDeclaration
|| !isClassLike(suggestion.valueDeclaration)
|| suggestion.valueDeclaration.heritageClauses?.length
|| classOrConstructorParameterIsDecorated(/*useLegacyDecorators*/ false, suggestion.valueDeclaration);
return !(file !== declarationFile && !!declarationFile && isGlobalSourceFile(declarationFile))
&& !(excludeClasses && suggestion && suggestion.flags & SymbolFlags.Class && suggestionHasNoExtends)
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword && suggestionHasNoExtends);
&& !(excludeClasses && suggestion && suggestion.flags & SymbolFlags.Class && suggestionHasNoExtendsOrDecorators)
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword && suggestionHasNoExtendsOrDecorators);
}
}
return false;
Expand Down
24 changes: 23 additions & 1 deletion tests/cases/fourslash/codeFixSpellingJs9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
//// const person = new Person();
//// person.[|getFavoriteColour|]();
//// person.[|getFavoriteColoxr|]();
//// function deco() { }
//// @deco
//// class Art {
//// style = true
//// }
//// const a = new Art()
//// a.[|stylo|]
//// @deco
//// class Double extends Art { }
//// const db = new Double()
//// db.[|stylo|]
verify.codeFixAll({
fixId: "fixSpelling",
fixAllDescription: "Fix all detected spelling errors",
Expand All @@ -48,5 +59,16 @@ class Person {
const person = new Person();
person.getFavoriteColor();
person.getFavoriteColor();`,
person.getFavoriteColor();
function deco() { }
@deco
class Art {
style = true
}
const a = new Art()
a.stylo
@deco
class Double extends Art { }
const db = new Double()
db.stylo`,
});

0 comments on commit ce47269

Please sign in to comment.