mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix preserveNewlines printer option when a list child has the same start or end as its parent
This commit is contained in:
@@ -4301,6 +4301,7 @@ namespace ts {
|
||||
return getEffectiveLines(
|
||||
includeComments => getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter(
|
||||
firstChild.pos,
|
||||
parentNode.pos,
|
||||
currentSourceFile!,
|
||||
includeComments));
|
||||
}
|
||||
@@ -4358,6 +4359,7 @@ namespace ts {
|
||||
return getEffectiveLines(
|
||||
includeComments => getLinesBetweenPositionAndNextNonWhitespaceCharacter(
|
||||
lastChild.end,
|
||||
parentNode.end,
|
||||
currentSourceFile!,
|
||||
includeComments));
|
||||
}
|
||||
|
||||
@@ -4776,19 +4776,19 @@ namespace ts {
|
||||
return positionIsSynthesized(range.pos) ? -1 : skipTrivia(sourceFile.text, range.pos, /*stopAfterLineBreak*/ false, includeComments);
|
||||
}
|
||||
|
||||
export function getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter(pos: number, sourceFile: SourceFile, includeComments?: boolean) {
|
||||
export function getLinesBetweenPositionAndPrecedingNonWhitespaceCharacter(pos: number, stopPos: number, sourceFile: SourceFile, includeComments?: boolean) {
|
||||
const startPos = skipTrivia(sourceFile.text, pos, /*stopAfterLineBreak*/ false, includeComments);
|
||||
const prevPos = getPreviousNonWhitespacePosition(startPos, sourceFile);
|
||||
const prevPos = getPreviousNonWhitespacePosition(startPos, stopPos, sourceFile);
|
||||
return getLinesBetweenPositions(sourceFile, prevPos || 0, startPos);
|
||||
}
|
||||
|
||||
export function getLinesBetweenPositionAndNextNonWhitespaceCharacter(pos: number, sourceFile: SourceFile, includeComments?: boolean) {
|
||||
export function getLinesBetweenPositionAndNextNonWhitespaceCharacter(pos: number, stopPos: number, sourceFile: SourceFile, includeComments?: boolean) {
|
||||
const nextPos = skipTrivia(sourceFile.text, pos, /*stopAfterLineBreak*/ false, includeComments);
|
||||
return getLinesBetweenPositions(sourceFile, pos, nextPos);
|
||||
return getLinesBetweenPositions(sourceFile, pos, Math.min(stopPos, nextPos));
|
||||
}
|
||||
|
||||
function getPreviousNonWhitespacePosition(pos: number, sourceFile: SourceFile) {
|
||||
while (pos-- > 0) {
|
||||
function getPreviousNonWhitespacePosition(pos: number, stopPos = 0, sourceFile: SourceFile) {
|
||||
while (pos-- > stopPos) {
|
||||
if (!isWhiteSpaceLike(sourceFile.text.charCodeAt(pos))) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// #37813
|
||||
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////function foo() {
|
||||
//// /*1*/var x: number
|
||||
////
|
||||
//// x = 10;
|
||||
//// return x;/*2*/
|
||||
////}
|
||||
|
||||
goTo.select("1", "2");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract Symbol",
|
||||
actionName: "function_scope_1",
|
||||
actionDescription: "Extract to function in global scope",
|
||||
newContent:
|
||||
`function foo() {
|
||||
return /*RENAME*/newFunction();
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
var x: number;
|
||||
|
||||
x = 10;
|
||||
return x;
|
||||
}
|
||||
`
|
||||
});
|
||||
Reference in New Issue
Block a user