mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 15:25:54 -06:00
Store scanning information whether JSXText is just an all whitespaces
This commit is contained in:
parent
17417e9a88
commit
4562fd089c
@ -13318,8 +13318,13 @@ namespace ts {
|
||||
for (const child of (parent as JsxElement).children) {
|
||||
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
|
||||
// because then type of children property will have constituent of string type.
|
||||
if (child.kind !== SyntaxKind.JsxTextAllWhiteSpaces) {
|
||||
childrenTypes.push(child.kind === SyntaxKind.JsxText ? stringType : checkExpression(child as Expression, checkMode));
|
||||
if (child.kind === SyntaxKind.JsxText) {
|
||||
if (!child.containsOnlyWhiteSpaces) {
|
||||
childrenTypes.push(stringType);
|
||||
}
|
||||
}
|
||||
else {
|
||||
childrenTypes.push(checkExpression(child, checkMode));
|
||||
}
|
||||
}
|
||||
childrenPropSymbol.type = getUnionType(childrenTypes, /*subtypeReduction*/ false);
|
||||
|
||||
@ -3825,7 +3825,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseJsxText(): JsxText {
|
||||
const node = <JsxText>createNode(currentToken, scanner.getStartPos());
|
||||
const node = <JsxText>createNode(SyntaxKind.JsxText, scanner.getStartPos());
|
||||
node.containsOnlyWhiteSpaces = currentToken === SyntaxKind.JsxTextAllWhiteSpaces;
|
||||
currentToken = scanner.scanJsxToken();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@ -1729,7 +1729,6 @@ namespace ts {
|
||||
// firstNonWhitespace = 0 to indicate that we want leading whitspace,
|
||||
|
||||
while (pos < end) {
|
||||
pos++;
|
||||
char = text.charCodeAt(pos);
|
||||
if (char === CharacterCodes.openBrace) {
|
||||
break;
|
||||
@ -1754,6 +1753,7 @@ namespace ts {
|
||||
else if (!isWhiteSpaceSingleLine(char)) {
|
||||
firstNonWhitespace = pos;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
|
||||
return firstNonWhitespace === -1 ? SyntaxKind.JsxTextAllWhiteSpaces : SyntaxKind.JsxText;
|
||||
|
||||
@ -1572,7 +1572,8 @@
|
||||
}
|
||||
|
||||
export interface JsxText extends Node {
|
||||
kind: SyntaxKind.JsxText;
|
||||
kind: SyntaxKind.JsxText,
|
||||
containsOnlyWhiteSpaces: boolean,
|
||||
parent?: JsxElement;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user