Fix-ups around formatting and assertions

This commit is contained in:
Ryan Cavanaugh
2016-10-14 12:08:41 -07:00
parent 4304eab654
commit eb4bb4a9e0
4 changed files with 8 additions and 7 deletions

View File

@@ -624,10 +624,11 @@ namespace ts.formatting {
return inheritedIndentation;
}
if (isToken(child)) {
// JSX text shouldn't affect indenting
if (isToken(child) && child.kind !== SyntaxKind.JsxText) {
// if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules
const tokenInfo = formattingScanner.readTokenInfo(child);
Debug.assert(tokenInfo.token.end === child.end);
Debug.assert(tokenInfo.token.end === child.end, "Token end is child end");
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, child);
return inheritedIndentation;
}

View File

@@ -31,7 +31,7 @@ namespace ts.formatting {
}
export function getFormattingScanner(sourceFile: SourceFile, startPos: number, endPos: number): FormattingScanner {
Debug.assert(scanner === undefined);
Debug.assert(scanner === undefined, "Scanner should be undefined");
scanner = sourceFile.languageVariant === LanguageVariant.JSX ? jsxScanner : standardScanner;
scanner.setText(sourceFile.text);
@@ -62,7 +62,7 @@ namespace ts.formatting {
};
function advance(): void {
Debug.assert(scanner !== undefined);
Debug.assert(scanner !== undefined, "Scanner should be present");
lastTokenInfo = undefined;
const isStarted = scanner.getStartPos() !== startPos;

View File

@@ -35,8 +35,8 @@ namespace ts.formatting {
}
private GetRuleBucketIndex(row: number, column: number): number {
Debug.assert(row <= SyntaxKind.LastKeyword && column <= SyntaxKind.LastKeyword, "Must compute formatting context from tokens");
const rulesBucketIndex = (row * this.mapRowLength) + column;
// Debug.Assert(rulesBucketIndex < this.map.Length, "Trying to access an index outside the array.");
return rulesBucketIndex;
}

View File

@@ -750,7 +750,7 @@ namespace ts {
return find(startNode || sourceFile);
function findRightmostToken(n: Node): Node {
if (isToken(n) || n.kind === SyntaxKind.JsxText) {
if (isToken(n)) {
return n;
}
@@ -761,7 +761,7 @@ namespace ts {
}
function find(n: Node): Node {
if (isToken(n) || n.kind === SyntaxKind.JsxText) {
if (isToken(n)) {
return n;
}