Skip to content

Commit adc3234

Browse files
committed
Don't insert a blank line after extracted locals at the start of the file
1 parent 129d192 commit adc3234

37 files changed

Lines changed: 4 additions & 38 deletions

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ namespace ts.codefix {
279279
changeTracker.insertNodeAfter(sourceFile, lastImportDeclaration, importDecl);
280280
}
281281
else {
282-
changeTracker.insertNodeAtTopOfFile(sourceFile, importDecl);
282+
changeTracker.insertNodeAtTopOfFile(sourceFile, importDecl, /*blankLineBetween*/ true);
283283
}
284284
});
285285

src/services/refactors/extractSymbol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ namespace ts.refactor.extractSymbol {
10771077
// Declare
10781078
const nodeToInsertBefore = getNodeToInsertConstantBefore(node, scope);
10791079
if (nodeToInsertBefore.pos === 0) {
1080-
changeTracker.insertNodeAtTopOfFile(context.file, newVariableStatement);
1080+
changeTracker.insertNodeAtTopOfFile(context.file, newVariableStatement, /*blankLineBetween*/ false);
10811081
}
10821082
else {
10831083
changeTracker.insertNodeBefore(context.file, nodeToInsertBefore, newVariableStatement, /*blankLineBetween*/ false);

src/services/textChanges.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ namespace ts.textChanges {
332332
return this;
333333
}
334334

335-
public insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement): void {
335+
public insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement, blankLineBetween: boolean): void {
336336
const pos = getInsertionPositionAtSourceFileTop(sourceFile);
337337
this.insertNodeAt(sourceFile, pos, newNode, {
338338
prefix: pos === 0 ? undefined : this.newLineCharacter,
339-
suffix: isLineBreak(sourceFile.text.charCodeAt(pos)) ? this.newLineCharacter : this.newLineCharacter + this.newLineCharacter,
339+
suffix: (isLineBreak(sourceFile.text.charCodeAt(pos)) ? "" : this.newLineCharacter) + (blankLineBetween ? this.newLineCharacter : ""),
340340
});
341341
}
342342

tests/baselines/reference/extractConstant/extractConstant_ArrowFunction_Block.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const f = () => {
1111
};
1212
// ==SCOPE::Extract to constant in global scope==
1313
const newLocal = 2 + 1;
14-
1514
const f = () => {
1615
return /*RENAME*/newLocal;
1716
};

tests/baselines/reference/extractConstant/extractConstant_ArrowFunction_Block.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const f = () => {
1111
};
1212
// ==SCOPE::Extract to constant in global scope==
1313
const newLocal = 2 + 1;
14-
1514
const f = () => {
1615
return /*RENAME*/newLocal;
1716
};

tests/baselines/reference/extractConstant/extractConstant_ArrowFunction_Expression.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
const f = () => /*[#|*/2 + 1/*|]*/;
33
// ==SCOPE::Extract to constant in global scope==
44
const newLocal = 2 + 1;
5-
65
const f = () => /*RENAME*/newLocal;

tests/baselines/reference/extractConstant/extractConstant_ArrowFunction_Expression.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
const f = () => /*[#|*/2 + 1/*|]*/;
33
// ==SCOPE::Extract to constant in global scope==
44
const newLocal = 2 + 1;
5-
65
const f = () => /*RENAME*/newLocal;

tests/baselines/reference/extractConstant/extractConstant_Class.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class C {
44
}
55
// ==SCOPE::Extract to constant in global scope==
66
const newLocal = 1;
7-
87
class C {
98
x = /*RENAME*/newLocal;
109
}

tests/baselines/reference/extractConstant/extractConstant_Class.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class C {
1010
}
1111
// ==SCOPE::Extract to constant in global scope==
1212
const newLocal = 1;
13-
1413
class C {
1514
x = /*RENAME*/newLocal;
1615
}

tests/baselines/reference/extractConstant/extractConstant_ClassInsertionPosition1.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class C {
2121
}
2222
// ==SCOPE::Extract to constant in global scope==
2323
const newLocal = 1;
24-
2524
class C {
2625
a = 1;
2726
b = 2;

0 commit comments

Comments
 (0)