Skip to content

Commit eb4bb4a

Browse files
committed
Fix-ups around formatting and assertions
1 parent 4304eab commit eb4bb4a

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/services/formatting/formatting.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,11 @@ namespace ts.formatting {
624624
return inheritedIndentation;
625625
}
626626

627-
if (isToken(child)) {
627+
// JSX text shouldn't affect indenting
628+
if (isToken(child) && child.kind !== SyntaxKind.JsxText) {
628629
// if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules
629630
const tokenInfo = formattingScanner.readTokenInfo(child);
630-
Debug.assert(tokenInfo.token.end === child.end);
631+
Debug.assert(tokenInfo.token.end === child.end, "Token end is child end");
631632
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, child);
632633
return inheritedIndentation;
633634
}

src/services/formatting/formattingScanner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace ts.formatting {
3131
}
3232

3333
export function getFormattingScanner(sourceFile: SourceFile, startPos: number, endPos: number): FormattingScanner {
34-
Debug.assert(scanner === undefined);
34+
Debug.assert(scanner === undefined, "Scanner should be undefined");
3535
scanner = sourceFile.languageVariant === LanguageVariant.JSX ? jsxScanner : standardScanner;
3636

3737
scanner.setText(sourceFile.text);
@@ -62,7 +62,7 @@ namespace ts.formatting {
6262
};
6363

6464
function advance(): void {
65-
Debug.assert(scanner !== undefined);
65+
Debug.assert(scanner !== undefined, "Scanner should be present");
6666

6767
lastTokenInfo = undefined;
6868
const isStarted = scanner.getStartPos() !== startPos;

src/services/formatting/rulesMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace ts.formatting {
3535
}
3636

3737
private GetRuleBucketIndex(row: number, column: number): number {
38+
Debug.assert(row <= SyntaxKind.LastKeyword && column <= SyntaxKind.LastKeyword, "Must compute formatting context from tokens");
3839
const rulesBucketIndex = (row * this.mapRowLength) + column;
39-
// Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array.");
4040
return rulesBucketIndex;
4141
}
4242

src/services/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ namespace ts {
750750
return find(startNode || sourceFile);
751751

752752
function findRightmostToken(n: Node): Node {
753-
if (isToken(n) || n.kind === SyntaxKind.JsxText) {
753+
if (isToken(n)) {
754754
return n;
755755
}
756756

@@ -761,7 +761,7 @@ namespace ts {
761761
}
762762

763763
function find(n: Node): Node {
764-
if (isToken(n) || n.kind === SyntaxKind.JsxText) {
764+
if (isToken(n)) {
765765
return n;
766766
}
767767

0 commit comments

Comments
 (0)