Consistently ignore attributes with hyphenated names in JSX (#44873)

* Consistently skip attributes with hyphenated names in JSX

* Add regression test

* Accept new baselines

* Fix tests

* Accept new baselines
This commit is contained in:
Anders Hejlsberg
2021-07-06 13:29:51 -07:00
committed by GitHub
parent 1da18c60d6
commit 8e01a86c01
10 changed files with 227 additions and 24 deletions

View File

@@ -16794,7 +16794,7 @@ namespace ts {
function *generateJsxAttributes(node: JsxAttributes): ElaborationIterator {
if (!length(node.properties)) return;
for (const prop of node.properties) {
if (isJsxSpreadAttribute(prop)) continue;
if (isJsxSpreadAttribute(prop) || isHyphenatedJsxName(idText(prop.name))) continue;
yield { errorNode: prop.name, innerExpression: prop.initializer, nameType: getStringLiteralType(idText(prop.name)) };
}
}
@@ -17355,7 +17355,7 @@ namespace ts {
}
function isIgnoredJsxProperty(source: Type, sourceProp: Symbol) {
return getObjectFlags(source) & ObjectFlags.JsxAttributes && !isUnhyphenatedJsxName(sourceProp.escapedName);
return getObjectFlags(source) & ObjectFlags.JsxAttributes && isHyphenatedJsxName(sourceProp.escapedName);
}
function getNormalizedType(type: Type, writing: boolean): Type {
@@ -26585,8 +26585,8 @@ namespace ts {
return getJsxElementTypeAt(node) || anyType;
}
function isUnhyphenatedJsxName(name: string | __String) {
return !stringContains(name as string, "-");
function isHyphenatedJsxName(name: string | __String) {
return stringContains(name as string, "-");
}
/**
@@ -27127,7 +27127,7 @@ namespace ts {
if (getPropertyOfObjectType(targetType, name) ||
getApplicableIndexInfoForName(targetType, name) ||
isLateBoundName(name) && getIndexInfoOfType(targetType, stringType) ||
isComparingJsxAttributes && !isUnhyphenatedJsxName(name)) {
isComparingJsxAttributes && isHyphenatedJsxName(name)) {
// For JSXAttributes, if the attribute has a hyphenated name, consider that the attribute to be known.
return true;
}