@@ -367,7 +367,7 @@ namespace ts {
367
367
return computeLineAndCharacterOfPosition ( getLineStarts ( sourceFile ) , position ) ;
368
368
}
369
369
370
- export function isWhiteSpace ( ch : number ) : boolean {
370
+ export function isWhiteSpaceLike ( ch : number ) : boolean {
371
371
return isWhiteSpaceSingleLine ( ch ) || isLineBreak ( ch ) ;
372
372
}
373
373
@@ -512,7 +512,7 @@ namespace ts {
512
512
break ;
513
513
514
514
default :
515
- if ( ch > CharacterCodes . maxAsciiCharacter && ( isWhiteSpace ( ch ) ) ) {
515
+ if ( ch > CharacterCodes . maxAsciiCharacter && ( isWhiteSpaceLike ( ch ) ) ) {
516
516
pos ++ ;
517
517
continue ;
518
518
}
@@ -694,7 +694,7 @@ namespace ts {
694
694
}
695
695
break scan;
696
696
default :
697
- if ( ch > CharacterCodes . maxAsciiCharacter && ( isWhiteSpace ( ch ) ) ) {
697
+ if ( ch > CharacterCodes . maxAsciiCharacter && ( isWhiteSpaceLike ( ch ) ) ) {
698
698
if ( hasPendingCommentRange && isLineBreak ( ch ) ) {
699
699
pendingHasTrailingNewLine = true ;
700
700
}
@@ -1727,8 +1727,12 @@ namespace ts {
1727
1727
return token = SyntaxKind . OpenBraceToken ;
1728
1728
}
1729
1729
1730
+ // First non-whitespace character on this line.
1731
+ let firstNonWhitespace = 0 ;
1732
+ // These initial values are special because the first line is:
1733
+ // firstNonWhitespace = 0 to indicate that we want leading whitspace,
1734
+
1730
1735
while ( pos < end ) {
1731
- pos ++ ;
1732
1736
char = text . charCodeAt ( pos ) ;
1733
1737
if ( char === CharacterCodes . openBrace ) {
1734
1738
break ;
@@ -1740,8 +1744,23 @@ namespace ts {
1740
1744
}
1741
1745
break ;
1742
1746
}
1747
+
1748
+ // FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
1749
+ // i.e (- : whitespace)
1750
+ // <div>----
1751
+ // </div> becomes <div></div>
1752
+ //
1753
+ // <div>----</div> becomes <div>----</div>
1754
+ if ( isLineBreak ( char ) && firstNonWhitespace === 0 ) {
1755
+ firstNonWhitespace = - 1 ;
1756
+ }
1757
+ else if ( ! isWhiteSpaceLike ( char ) ) {
1758
+ firstNonWhitespace = pos ;
1759
+ }
1760
+ pos ++ ;
1743
1761
}
1744
- return token = SyntaxKind . JsxText ;
1762
+
1763
+ return firstNonWhitespace === - 1 ? SyntaxKind . JsxTextAllWhiteSpaces : SyntaxKind . JsxText ;
1745
1764
}
1746
1765
1747
1766
// Scans a JSX identifier; these differ from normal identifiers in that
0 commit comments