Skip to content

Commit 4fa2312

Browse files
author
Kanchalai Tanglertsampan
committed
Fixing consuming whitespace in children
1 parent 4562fd0 commit 4fa2312

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13327,7 +13327,9 @@ namespace ts {
1332713327
childrenTypes.push(checkExpression(child, checkMode));
1332813328
}
1332913329
}
13330-
childrenPropSymbol.type = getUnionType(childrenTypes, /*subtypeReduction*/ false);
13330+
childrenPropSymbol.type = childrenTypes.length === 1 ?
13331+
childrenTypes[0] :
13332+
createArrayType(getUnionType(childrenTypes, /*subtypeReduction*/ false));
1333113333
attributesTable.set(jsxChildrenPropertyName, childrenPropSymbol);
1333213334
containsSynthesizedJsxChildren = true;
1333313335
}

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,7 @@ namespace ts {
24572457
let indentation: number;
24582458
for (const line of lines) {
24592459
for (let i = 0; i < line.length && (indentation === undefined || i < indentation); i++) {
2460-
if (!isWhiteSpace(line.charCodeAt(i))) {
2460+
if (!isWhiteSpaceLike(line.charCodeAt(i))) {
24612461
if (indentation === undefined || i < indentation) {
24622462
indentation = i;
24632463
break;

src/compiler/scanner.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ namespace ts {
366366
return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
367367
}
368368

369-
export function isWhiteSpace(ch: number): boolean {
369+
export function isWhiteSpaceLike(ch: number): boolean {
370370
return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
371371
}
372372

@@ -510,7 +510,7 @@ namespace ts {
510510
break;
511511

512512
default:
513-
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
513+
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
514514
pos++;
515515
continue;
516516
}
@@ -691,7 +691,7 @@ namespace ts {
691691
}
692692
break scan;
693693
default:
694-
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
694+
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
695695
if (hasPendingCommentRange && isLineBreak(ch)) {
696696
pendingHasTrailingNewLine = true;
697697
}
@@ -1750,7 +1750,7 @@ namespace ts {
17501750
if (isLineBreak(char) && firstNonWhitespace === 0) {
17511751
firstNonWhitespace = -1;
17521752
}
1753-
else if (!isWhiteSpaceSingleLine(char)) {
1753+
else if (!isWhiteSpaceLike(char)) {
17541754
firstNonWhitespace = pos;
17551755
}
17561756
pos++;

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,8 +1572,8 @@
15721572
}
15731573

15741574
export interface JsxText extends Node {
1575-
kind: SyntaxKind.JsxText,
1576-
containsOnlyWhiteSpaces: boolean,
1575+
kind: SyntaxKind.JsxText;
1576+
containsOnlyWhiteSpaces: boolean;
15771577
parent?: JsxElement;
15781578
}
15791579

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace ts.formatting {
5454
let current = position;
5555
while (current > 0) {
5656
const char = sourceFile.text.charCodeAt(current);
57-
if (!isWhiteSpace(char)) {
57+
if (!isWhiteSpaceLike(char)) {
5858
break;
5959
}
6060
current--;

src/services/textChanges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ namespace ts.textChanges {
608608
if (force || !isTrivia(s)) {
609609
this.lastNonTriviaPosition = this.writer.getTextPos();
610610
let i = 0;
611-
while (isWhiteSpace(s.charCodeAt(s.length - i - 1))) {
611+
while (isWhiteSpaceLike(s.charCodeAt(s.length - i - 1))) {
612612
i++;
613613
}
614614
// trim trailing whitespaces

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ namespace ts {
13811381
}
13821382

13831383
export function getFirstNonSpaceCharacterPosition(text: string, position: number) {
1384-
while (isWhiteSpace(text.charCodeAt(position))) {
1384+
while (isWhiteSpaceLike(text.charCodeAt(position))) {
13851385
position += 1;
13861386
}
13871387
return position;

0 commit comments

Comments
 (0)