Fixing consuming whitespace in children

This commit is contained in:
Kanchalai Tanglertsampan
2017-04-12 12:08:12 -07:00
parent 4562fd089c
commit 4fa23127fc
7 changed files with 13 additions and 11 deletions

View File

@@ -13327,7 +13327,9 @@ namespace ts {
childrenTypes.push(checkExpression(child, checkMode));
}
}
childrenPropSymbol.type = getUnionType(childrenTypes, /*subtypeReduction*/ false);
childrenPropSymbol.type = childrenTypes.length === 1 ?
childrenTypes[0] :
createArrayType(getUnionType(childrenTypes, /*subtypeReduction*/ false));
attributesTable.set(jsxChildrenPropertyName, childrenPropSymbol);
containsSynthesizedJsxChildren = true;
}

View File

@@ -2457,7 +2457,7 @@ namespace ts {
let indentation: number;
for (const line of lines) {
for (let i = 0; i < line.length && (indentation === undefined || i < indentation); i++) {
if (!isWhiteSpace(line.charCodeAt(i))) {
if (!isWhiteSpaceLike(line.charCodeAt(i))) {
if (indentation === undefined || i < indentation) {
indentation = i;
break;

View File

@@ -366,7 +366,7 @@ namespace ts {
return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
}
export function isWhiteSpace(ch: number): boolean {
export function isWhiteSpaceLike(ch: number): boolean {
return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
}
@@ -510,7 +510,7 @@ namespace ts {
break;
default:
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
pos++;
continue;
}
@@ -691,7 +691,7 @@ namespace ts {
}
break scan;
default:
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
if (hasPendingCommentRange && isLineBreak(ch)) {
pendingHasTrailingNewLine = true;
}
@@ -1750,7 +1750,7 @@ namespace ts {
if (isLineBreak(char) && firstNonWhitespace === 0) {
firstNonWhitespace = -1;
}
else if (!isWhiteSpaceSingleLine(char)) {
else if (!isWhiteSpaceLike(char)) {
firstNonWhitespace = pos;
}
pos++;

View File

@@ -1572,8 +1572,8 @@
}
export interface JsxText extends Node {
kind: SyntaxKind.JsxText,
containsOnlyWhiteSpaces: boolean,
kind: SyntaxKind.JsxText;
containsOnlyWhiteSpaces: boolean;
parent?: JsxElement;
}

View File

@@ -54,7 +54,7 @@ namespace ts.formatting {
let current = position;
while (current > 0) {
const char = sourceFile.text.charCodeAt(current);
if (!isWhiteSpace(char)) {
if (!isWhiteSpaceLike(char)) {
break;
}
current--;

View File

@@ -608,7 +608,7 @@ namespace ts.textChanges {
if (force || !isTrivia(s)) {
this.lastNonTriviaPosition = this.writer.getTextPos();
let i = 0;
while (isWhiteSpace(s.charCodeAt(s.length - i - 1))) {
while (isWhiteSpaceLike(s.charCodeAt(s.length - i - 1))) {
i++;
}
// trim trailing whitespaces

View File

@@ -1381,7 +1381,7 @@ namespace ts {
}
export function getFirstNonSpaceCharacterPosition(text: string, position: number) {
while (isWhiteSpace(text.charCodeAt(position))) {
while (isWhiteSpaceLike(text.charCodeAt(position))) {
position += 1;
}
return position;