mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
chore: make isJsxAttr required
This commit is contained in:
parent
d38096ab90
commit
c36fe2339a
@ -13245,7 +13245,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
let suggestion: string | undefined;
|
||||
if (propName !== undefined && (suggestion = getSuggestionForNonexistentProperty(propName as string, objectType))) {
|
||||
if (propName !== undefined && (suggestion = getSuggestionForNonexistentProperty(propName as string, objectType, false))) {
|
||||
if (suggestion !== undefined) {
|
||||
error(accessExpression.argumentExpression, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, propName as string, typeToString(objectType), suggestion);
|
||||
}
|
||||
@ -16335,7 +16335,7 @@ namespace ts {
|
||||
|
||||
const name = propDeclaration.name!;
|
||||
if (isIdentifier(name)) {
|
||||
suggestion = getSuggestionForNonexistentProperty(name, errorTarget);
|
||||
suggestion = getSuggestionForNonexistentProperty(name, errorTarget, false);
|
||||
}
|
||||
}
|
||||
if (suggestion !== undefined) {
|
||||
@ -24852,7 +24852,7 @@ namespace ts {
|
||||
relatedInfo = createDiagnosticForNode(propNode, Diagnostics.Did_you_forget_to_use_await);
|
||||
}
|
||||
else {
|
||||
const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType);
|
||||
const suggestion = getSuggestedSymbolForNonexistentProperty(propNode, containingType, false);
|
||||
if (suggestion !== undefined) {
|
||||
const suggestedName = symbolName(suggestion);
|
||||
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_2, declarationNameToString(propNode), typeToString(containingType), suggestedName);
|
||||
@ -24875,12 +24875,12 @@ namespace ts {
|
||||
return prop !== undefined && prop.valueDeclaration && hasSyntacticModifier(prop.valueDeclaration, ModifierFlags.Static);
|
||||
}
|
||||
|
||||
function getSuggestedSymbolForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type, isJSX = false): Symbol | undefined {
|
||||
return getSpellingSuggestionForName(isString(name) ? name : idText(name), getPropertiesOfType(containingType), SymbolFlags.Value, isJSX);
|
||||
function getSuggestedSymbolForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type, isJsxAttr: boolean): Symbol | undefined {
|
||||
return getSpellingSuggestionForName(isString(name) ? name : idText(name), getPropertiesOfType(containingType), SymbolFlags.Value, isJsxAttr);
|
||||
}
|
||||
|
||||
function getSuggestionForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type, isJSX = false): string | undefined {
|
||||
const suggestion = getSuggestedSymbolForNonexistentProperty(name, containingType, isJSX);
|
||||
function getSuggestionForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type, isJsxAttr: boolean): string | undefined {
|
||||
const suggestion = getSuggestedSymbolForNonexistentProperty(name, containingType, isJsxAttr);
|
||||
return suggestion && symbolName(suggestion);
|
||||
}
|
||||
|
||||
@ -24892,7 +24892,7 @@ namespace ts {
|
||||
// Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
|
||||
// So the table *contains* `x` but `x` isn't actually in scope.
|
||||
// However, resolveNameHelper will continue and call this callback again, so we'll eventually get a correct suggestion.
|
||||
return symbol || getSpellingSuggestionForName(unescapeLeadingUnderscores(name), arrayFrom(symbols.values()), meaning);
|
||||
return symbol || getSpellingSuggestionForName(unescapeLeadingUnderscores(name), arrayFrom(symbols.values()), meaning, false);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@ -24903,7 +24903,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getSuggestedSymbolForNonexistentModule(name: Identifier, targetModule: Symbol): Symbol | undefined {
|
||||
return targetModule.exports && getSpellingSuggestionForName(idText(name), getExportsOfModuleAsArray(targetModule), SymbolFlags.ModuleMember);
|
||||
return targetModule.exports && getSpellingSuggestionForName(idText(name), getExportsOfModuleAsArray(targetModule), SymbolFlags.ModuleMember, false);
|
||||
}
|
||||
|
||||
function getSuggestionForNonexistentExport(name: Identifier, targetModule: Symbol): string | undefined {
|
||||
@ -24953,8 +24953,8 @@ namespace ts {
|
||||
* (0.4 allows 1 substitution/transposition for every 5 characters,
|
||||
* and 1 insertion/deletion at 3 characters)
|
||||
*/
|
||||
function getSpellingSuggestionForName(name: string, symbols: Symbol[], meaning: SymbolFlags, isJSX = false): Symbol | undefined {
|
||||
return getSpellingSuggestion(name, symbols, getCandidateName, isJSX);
|
||||
function getSpellingSuggestionForName(name: string, symbols: Symbol[], meaning: SymbolFlags, isJsxAttr: boolean): Symbol | undefined {
|
||||
return getSpellingSuggestion(name, symbols, getCandidateName, isJsxAttr);
|
||||
function getCandidateName(candidate: Symbol) {
|
||||
const candidateName = symbolName(candidate);
|
||||
if (startsWith(candidateName, "\"")) {
|
||||
|
||||
@ -1194,7 +1194,7 @@ namespace ts {
|
||||
createDiagnostics: (message: DiagnosticMessage, arg0: string, arg1?: string) => Diagnostic,
|
||||
unknownOptionErrorText?: string
|
||||
) {
|
||||
const possibleOption = getSpellingSuggestion(unknownOption, diagnostics.optionDeclarations, getOptionName);
|
||||
const possibleOption = getSpellingSuggestion(unknownOption, diagnostics.optionDeclarations, getOptionName, false);
|
||||
return possibleOption ?
|
||||
createDiagnostics(diagnostics.unknownDidYouMeanDiagnostic, unknownOptionErrorText || unknownOption, possibleOption.name) :
|
||||
createDiagnostics(diagnostics.unknownOptionDiagnostic, unknownOptionErrorText || unknownOption);
|
||||
|
||||
@ -1817,7 +1817,7 @@ namespace ts {
|
||||
* (0.4 allows 1 substitution/transposition for every 5 characters,
|
||||
* and 1 insertion/deletion at 3 characters)
|
||||
*/
|
||||
export function getSpellingSuggestion<T>(name: string, candidates: T[], getName: (candidate: T) => string | undefined, isJSX = false): T | undefined {
|
||||
export function getSpellingSuggestion<T>(name: string, candidates: T[], getName: (candidate: T) => string | undefined, isJsxAttr: boolean): T | undefined {
|
||||
const maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
|
||||
let bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result isn't better than this, don't bother.
|
||||
let bestCandidate: T | undefined;
|
||||
@ -1825,7 +1825,7 @@ namespace ts {
|
||||
const nameLowerCase = name.toLowerCase();
|
||||
for (const candidate of candidates) {
|
||||
const candidateName = getName(candidate);
|
||||
if (isJSX) {
|
||||
if (isJsxAttr) {
|
||||
const htmlFor = name === "for" && candidateName === "htmlFor";
|
||||
const className = name === "class" && candidateName === "className";
|
||||
if (htmlFor || className) {
|
||||
|
||||
@ -2784,7 +2784,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
const unqualifiedLibName = removeSuffix(removePrefix(libName, "lib."), ".d.ts");
|
||||
const suggestion = getSpellingSuggestion(unqualifiedLibName, libs, identity);
|
||||
const suggestion = getSpellingSuggestion(unqualifiedLibName, libs, identity, false);
|
||||
const message = suggestion ? Diagnostics.Cannot_find_lib_definition_for_0_Did_you_mean_1 : Diagnostics.Cannot_find_lib_definition_for_0;
|
||||
fileProcessingDiagnostics.add(createFileDiagnostic(
|
||||
file,
|
||||
|
||||
@ -4009,8 +4009,8 @@ namespace ts {
|
||||
*/
|
||||
/* @internal */ tryGetMemberInModuleExportsAndProperties(memberName: string, moduleSymbol: Symbol): Symbol | undefined;
|
||||
getApparentType(type: Type): Type;
|
||||
/* @internal */ getSuggestedSymbolForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type, isJSX?: boolean): Symbol | undefined;
|
||||
/* @internal */ getSuggestionForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type): string | undefined;
|
||||
/* @internal */ getSuggestedSymbolForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type, isJsxAttr: boolean): Symbol | undefined;
|
||||
/* @internal */ getSuggestionForNonexistentProperty(name: Identifier | PrivateIdentifier | string, containingType: Type, isJsxAttr: boolean): string | undefined;
|
||||
/* @internal */ getSuggestedSymbolForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): Symbol | undefined;
|
||||
/* @internal */ getSuggestionForNonexistentSymbol(location: Node, name: string, meaning: SymbolFlags): string | undefined;
|
||||
/* @internal */ getSuggestedSymbolForNonexistentModule(node: Identifier, target: Symbol): Symbol | undefined;
|
||||
|
||||
@ -51,7 +51,7 @@ namespace ts.codefix {
|
||||
if (parent.flags & NodeFlags.OptionalChain) {
|
||||
containingType = checker.getNonNullableType(containingType);
|
||||
}
|
||||
suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, containingType);
|
||||
suggestedSymbol = checker.getSuggestedSymbolForNonexistentProperty(node, containingType, false);
|
||||
}
|
||||
else if (isImportSpecifier(parent) && parent.name === node) {
|
||||
Debug.assertNode(node, isIdentifier, "Expected an identifier for spelling (import)");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user