mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
More did-you-mean errors on classes in plain JS (#49827)
This commit is contained in:
parent
da8b54d831
commit
982f8be6f2
@ -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;
|
||||
|
||||
@ -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`,
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user