mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
Component commits: 91631435ca Fix newline inserted in empty block at end of formatting range 79b600aaa3 Clean up 19ef6b67c5 Fix refactoring mistake Co-authored-by: Andrew Branch <andrew@wheream.io>
This commit is contained in:
parent
2bed482323
commit
fbc2b677bc
@ -439,20 +439,21 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
if (previousRange! && formattingScanner.getStartPos() >= originalRange.end) {
|
||||
const token =
|
||||
const tokenInfo =
|
||||
formattingScanner.isOnEOF() ? formattingScanner.readEOFTokenRange() :
|
||||
formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(enclosingNode).token :
|
||||
undefined;
|
||||
|
||||
if (token) {
|
||||
if (tokenInfo) {
|
||||
const parent = findPrecedingToken(tokenInfo.end, sourceFile, enclosingNode)?.parent || previousParent!;
|
||||
processPair(
|
||||
token,
|
||||
sourceFile.getLineAndCharacterOfPosition(token.pos).line,
|
||||
enclosingNode,
|
||||
tokenInfo,
|
||||
sourceFile.getLineAndCharacterOfPosition(tokenInfo.pos).line,
|
||||
parent,
|
||||
previousRange,
|
||||
previousRangeStartLine!,
|
||||
previousParent!,
|
||||
enclosingNode,
|
||||
parent,
|
||||
/*dynamicIndentation*/ undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1256,8 +1256,10 @@ namespace ts {
|
||||
* Finds the rightmost token satisfying `token.end <= position`,
|
||||
* excluding `JsxText` tokens containing only whitespace.
|
||||
*/
|
||||
export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, excludeJsdoc?: boolean): Node | undefined {
|
||||
const result = find(startNode || sourceFile);
|
||||
export function findPrecedingToken(position: number, sourceFile: SourceFileLike, startNode: Node, excludeJsdoc?: boolean): Node | undefined;
|
||||
export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, excludeJsdoc?: boolean): Node | undefined;
|
||||
export function findPrecedingToken(position: number, sourceFile: SourceFileLike, startNode?: Node, excludeJsdoc?: boolean): Node | undefined {
|
||||
const result = find((startNode || sourceFile) as Node);
|
||||
Debug.assert(!(result && isWhiteSpaceOnlyJsxText(result)));
|
||||
return result;
|
||||
|
||||
@ -1322,7 +1324,7 @@ namespace ts {
|
||||
return isToken(n) && !isWhiteSpaceOnlyJsxText(n);
|
||||
}
|
||||
|
||||
function findRightmostToken(n: Node, sourceFile: SourceFile): Node | undefined {
|
||||
function findRightmostToken(n: Node, sourceFile: SourceFileLike): Node | undefined {
|
||||
if (isNonWhitespaceToken(n)) {
|
||||
return n;
|
||||
}
|
||||
@ -1339,7 +1341,7 @@ namespace ts {
|
||||
/**
|
||||
* Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
|
||||
*/
|
||||
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number, sourceFile: SourceFile, parentKind: SyntaxKind): Node | undefined {
|
||||
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number, sourceFile: SourceFileLike, parentKind: SyntaxKind): Node | undefined {
|
||||
for (let i = exclusiveStartPosition - 1; i >= 0; i--) {
|
||||
const child = children[i];
|
||||
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// if (foo) {
|
||||
//// if (bar) {/**/}
|
||||
//// }
|
||||
|
||||
goTo.marker("");
|
||||
format.onType("", "{");
|
||||
verify.currentFileContentIs(
|
||||
`if (foo) {
|
||||
if (bar) { }
|
||||
}`);
|
||||
Loading…
x
Reference in New Issue
Block a user