mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Do not consider empty jsx expressions semantically important children
This commit is contained in:
@@ -15827,10 +15827,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getSemanticJsxChildren(children: NodeArray<JsxChild>) {
|
||||
return filter(children, i => !isJsxText(i) || !i.containsOnlyTriviaWhiteSpaces);
|
||||
}
|
||||
|
||||
function elaborateJsxComponents(
|
||||
node: JsxAttributes,
|
||||
source: Type,
|
||||
@@ -24987,6 +24983,9 @@ namespace ts {
|
||||
childrenTypes.push(stringType);
|
||||
}
|
||||
}
|
||||
else if (child.kind === SyntaxKind.JsxExpression && !child.expression) {
|
||||
continue; // empty jsx expressions don't *really* count as present children
|
||||
}
|
||||
else {
|
||||
childrenTypes.push(checkExpressionForMutableLocation(child, checkMode));
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function convertJsxChildrenToChildrenPropObject(children: readonly JsxChild[]) {
|
||||
const nonWhitespaceChildren = filter(children, c => !isJsxText(c) || !c.containsOnlyTriviaWhiteSpaces);
|
||||
const nonWhitespaceChildren = getSemanticJsxChildren(children);
|
||||
if (length(nonWhitespaceChildren) === 1) {
|
||||
const result = transformJsxChildToExpression(nonWhitespaceChildren[0]);
|
||||
return result && factory.createObjectLiteralExpression([
|
||||
@@ -244,7 +244,7 @@ namespace ts {
|
||||
objectProperties = singleOrUndefined(segments) || emitHelpers().createAssignHelper(segments);
|
||||
}
|
||||
|
||||
return visitJsxOpeningLikeElementOrFragmentJSX(tagName, objectProperties, keyAttr, length(filter(children, c => !isJsxText(c) || !c.containsOnlyTriviaWhiteSpaces)), isChild, location);
|
||||
return visitJsxOpeningLikeElementOrFragmentJSX(tagName, objectProperties, keyAttr, length(getSemanticJsxChildren(children || emptyArray)), isChild, location);
|
||||
}
|
||||
|
||||
function visitJsxOpeningLikeElementOrFragmentJSX(tagName: Expression, objectProperties: Expression, keyAttr: JsxAttribute | undefined, childrenLength: number, isChild: boolean, location: TextRange) {
|
||||
@@ -336,7 +336,7 @@ namespace ts {
|
||||
getImplicitJsxFragmentReference(),
|
||||
childrenProps || factory.createObjectLiteralExpression([]),
|
||||
/*keyAttr*/ undefined,
|
||||
length(filter(children, c => !isJsxText(c) || !c.containsOnlyTriviaWhiteSpaces)),
|
||||
length(getSemanticJsxChildren(children)),
|
||||
isChild,
|
||||
location
|
||||
);
|
||||
|
||||
@@ -3621,6 +3621,19 @@ namespace ts {
|
||||
return -1;
|
||||
}
|
||||
|
||||
export function getSemanticJsxChildren(children: readonly JsxChild[]) {
|
||||
return filter(children, i => {
|
||||
switch (i.kind) {
|
||||
case SyntaxKind.JsxExpression:
|
||||
return !!i.expression;
|
||||
case SyntaxKind.JsxText:
|
||||
return !i.containsOnlyTriviaWhiteSpaces;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function createDiagnosticCollection(): DiagnosticCollection {
|
||||
let nonFileDiagnostics = [] as Diagnostic[] as SortedArray<Diagnostic>; // See GH#19873
|
||||
const filesWithDiagnostics = [] as string[] as SortedArray<string>;
|
||||
|
||||
Reference in New Issue
Block a user