Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4562fd0

Browse filesBrowse files
author
Kanchalai Tanglertsampan
committed
Store scanning information whether JSXText is just an all whitespaces
1 parent 17417e9 commit 4562fd0
Copy full SHA for 4562fd0

4 files changed

+12-5Lines changed: 12 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13318,8 +13318,13 @@ namespace ts {
1331813318
for (const child of (parent as JsxElement).children) {
1331913319
// In React, JSX text that contains only whitespaces will be ignored so we don't want to type-check that
1332013320
// because then type of children property will have constituent of string type.
13321-
if (child.kind !== SyntaxKind.JsxTextAllWhiteSpaces) {
13322-
childrenTypes.push(child.kind === SyntaxKind.JsxText ? stringType : checkExpression(child as Expression, checkMode));
13321+
if (child.kind === SyntaxKind.JsxText) {
13322+
if (!child.containsOnlyWhiteSpaces) {
13323+
childrenTypes.push(stringType);
13324+
}
13325+
}
13326+
else {
13327+
childrenTypes.push(checkExpression(child, checkMode));
1332313328
}
1332413329
}
1332513330
childrenPropSymbol.type = getUnionType(childrenTypes, /*subtypeReduction*/ false);
Collapse file

‎src/compiler/parser.ts‎

Copy file name to clipboardExpand all lines: src/compiler/parser.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3825,7 +3825,8 @@ namespace ts {
38253825
}
38263826

38273827
function parseJsxText(): JsxText {
3828-
const node = <JsxText>createNode(currentToken, scanner.getStartPos());
3828+
const node = <JsxText>createNode(SyntaxKind.JsxText, scanner.getStartPos());
3829+
node.containsOnlyWhiteSpaces = currentToken === SyntaxKind.JsxTextAllWhiteSpaces;
38293830
currentToken = scanner.scanJsxToken();
38303831
return finishNode(node);
38313832
}
Collapse file

‎src/compiler/scanner.ts‎

Copy file name to clipboardExpand all lines: src/compiler/scanner.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,6 @@ namespace ts {
17291729
// firstNonWhitespace = 0 to indicate that we want leading whitspace,
17301730

17311731
while (pos < end) {
1732-
pos++;
17331732
char = text.charCodeAt(pos);
17341733
if (char === CharacterCodes.openBrace) {
17351734
break;
@@ -1754,6 +1753,7 @@ namespace ts {
17541753
else if (!isWhiteSpaceSingleLine(char)) {
17551754
firstNonWhitespace = pos;
17561755
}
1756+
pos++;
17571757
}
17581758

17591759
return firstNonWhitespace === -1 ? SyntaxKind.JsxTextAllWhiteSpaces : SyntaxKind.JsxText;
Collapse file

‎src/compiler/types.ts‎

Copy file name to clipboardExpand all lines: src/compiler/types.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,8 @@
15721572
}
15731573

15741574
export interface JsxText extends Node {
1575-
kind: SyntaxKind.JsxText;
1575+
kind: SyntaxKind.JsxText,
1576+
containsOnlyWhiteSpaces: boolean,
15761577
parent?: JsxElement;
15771578
}
15781579

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.