Skip to content

Commit

Permalink
More did-you-mean errors on classes in plain JS (#49827)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandersn authored Sep 22, 2023
1 parent da8b54d commit 982f8be
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32306,9 +32306,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 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)
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword);
&& !(excludeClasses && suggestion && suggestion.flags & SymbolFlags.Class && suggestionHasNoExtendsOrDecorators)
&& !(!!node && excludeClasses && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.ThisKeyword && suggestionHasNoExtendsOrDecorators);
}
}
return false;
Expand Down
78 changes: 71 additions & 7 deletions tests/cases/fourslash/codeFixSpellingJs9.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,74 @@
/// <reference path='fourslash.ts' />
// @allowJs: true
// @Filename: codeFixSpellingJs9.js
//// class C {
//// numble = 1
//// mumble() {
//// return this.[|numbles|]
//// }
//// }
//// class D extends C { }
//// const c = new C()
//// c.[|numbles|] = 3
//// c.[|mumbles|]()
//// const d = new D()
//// d.[|numbles|] = 4
//// d.[|mumbles()|]
//// class Person {
//// getFavoriteColor() {
////
//// }
//// }
////
//// 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",
newFileContent:
`class C {
numble = 1
mumble() {
return this.numble
}
}
class D extends C { }
const c = new C()
c.numble = 3
c.mumble()
const d = new D()
d.numbles = 4
d.mumbles()
class Person {
getFavoriteColor() {
// @allowjs: true
// @noEmit: true
}
}
// @filename: noSuggestionWithoutDidYouMean.js
//// let a = {};
//// console.log(a.apple);
verify.noErrors()
verify.getSuggestionDiagnostics([])
const person = new Person();
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 982f8be

Please sign in to comment.