Don't insert a blank line after extracted locals at the start of the file

This commit is contained in:
Andrew Casey
2017-12-15 15:49:27 -08:00
parent 129d1924be
commit adc3234e46
37 changed files with 4 additions and 38 deletions
+1 -1
View File
@@ -279,7 +279,7 @@ namespace ts.codefix {
changeTracker.insertNodeAfter(sourceFile, lastImportDeclaration, importDecl);
}
else {
changeTracker.insertNodeAtTopOfFile(sourceFile, importDecl);
changeTracker.insertNodeAtTopOfFile(sourceFile, importDecl, /*blankLineBetween*/ true);
}
});
+1 -1
View File
@@ -1077,7 +1077,7 @@ namespace ts.refactor.extractSymbol {
// Declare
const nodeToInsertBefore = getNodeToInsertConstantBefore(node, scope);
if (nodeToInsertBefore.pos === 0) {
changeTracker.insertNodeAtTopOfFile(context.file, newVariableStatement);
changeTracker.insertNodeAtTopOfFile(context.file, newVariableStatement, /*blankLineBetween*/ false);
}
else {
changeTracker.insertNodeBefore(context.file, nodeToInsertBefore, newVariableStatement, /*blankLineBetween*/ false);
+2 -2
View File
@@ -332,11 +332,11 @@ namespace ts.textChanges {
return this;
}
public insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement): void {
public insertNodeAtTopOfFile(sourceFile: SourceFile, newNode: Statement, blankLineBetween: boolean): void {
const pos = getInsertionPositionAtSourceFileTop(sourceFile);
this.insertNodeAt(sourceFile, pos, newNode, {
prefix: pos === 0 ? undefined : this.newLineCharacter,
suffix: isLineBreak(sourceFile.text.charCodeAt(pos)) ? this.newLineCharacter : this.newLineCharacter + this.newLineCharacter,
suffix: (isLineBreak(sourceFile.text.charCodeAt(pos)) ? "" : this.newLineCharacter) + (blankLineBetween ? this.newLineCharacter : ""),
});
}
@@ -11,7 +11,6 @@ const f = () => {
};
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
const f = () => {
return /*RENAME*/newLocal;
};
@@ -11,7 +11,6 @@ const f = () => {
};
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
const f = () => {
return /*RENAME*/newLocal;
};
@@ -2,5 +2,4 @@
const f = () => /*[#|*/2 + 1/*|]*/;
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
const f = () => /*RENAME*/newLocal;
@@ -2,5 +2,4 @@
const f = () => /*[#|*/2 + 1/*|]*/;
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
const f = () => /*RENAME*/newLocal;
@@ -4,7 +4,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
x = /*RENAME*/newLocal;
}
@@ -10,7 +10,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
x = /*RENAME*/newLocal;
}
@@ -21,7 +21,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
a = 1;
b = 2;
@@ -33,7 +33,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
a = 1;
b = 2;
@@ -21,7 +21,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
a = 1;
M1() { }
@@ -33,7 +33,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
a = 1;
M1() { }
@@ -21,7 +21,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
M1() { }
a = 1;
@@ -33,7 +33,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
M1() { }
a = 1;
@@ -9,7 +9,6 @@ function F() {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
function F() {
let x = /*RENAME*/newLocal;
}
@@ -9,7 +9,6 @@ function F() {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
function F() {
let x = /*RENAME*/newLocal;
}
@@ -13,7 +13,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
M() {
let x = /*RENAME*/newLocal;
@@ -21,7 +21,6 @@ class C {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
class C {
M() {
let x = /*RENAME*/newLocal;
@@ -9,7 +9,6 @@ namespace N {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = 1;
namespace N {
let x = /*RENAME*/newLocal;
}
@@ -9,6 +9,5 @@ const x = /*[#|*/2 + 1/*|]*/;
/*! Copyright */
const newLocal = 2 + 1;
const x = /*RENAME*/newLocal;
@@ -9,6 +9,5 @@ const x = /*[#|*/2 + 1/*|]*/;
/*! Copyright */
const newLocal = 2 + 1;
const x = /*RENAME*/newLocal;
@@ -10,7 +10,6 @@ const x = /*[#|*/2 + 1/*|]*/;
/*! Copyright */
const newLocal = 2 + 1;
/* About x */
const x = /*RENAME*/newLocal;
@@ -10,7 +10,6 @@ const x = /*[#|*/2 + 1/*|]*/;
/*! Copyright */
const newLocal = 2 + 1;
/* About x */
const x = /*RENAME*/newLocal;
@@ -10,7 +10,6 @@ var q = /*b*/ //c
const newLocal = 1 /*e*/ //f
/*g*/ + /*h*/ //i
/*j*/ 2;
// a
var q = /*b*/ //c
/*d*/ /*RENAME*/newLocal /*k*/ //l
@@ -10,7 +10,6 @@ var q = /*b*/ //c
const newLocal = 1 /*e*/ //f
/*g*/ + /*h*/ //i
/*j*/ 2;
// a
var q = /*b*/ //c
/*d*/ /*RENAME*/newLocal /*k*/ //l
@@ -11,7 +11,6 @@ namespace X {
}
// ==SCOPE::Extract to constant in global scope==
const newLocal = X.j * X.j;
namespace X {
export const j = 10;
export const y = /*RENAME*/newLocal;
@@ -17,7 +17,6 @@ function F() {
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
function F() {
for (let j = 0; j < 10; j++) {
const x = /*RENAME*/newLocal;
@@ -17,7 +17,6 @@ function F() {
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
function F() {
for (let j = 0; j < 10; j++) {
const x = /*RENAME*/newLocal;
@@ -29,7 +29,6 @@ function F0() {
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
function F0() {
function F1() {
function F2(x = /*RENAME*/newLocal) {
@@ -29,7 +29,6 @@ function F0() {
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
function F0() {
function F1() {
function F2(x = /*RENAME*/newLocal) {
@@ -6,7 +6,6 @@ class C {
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
class C {
x = /*RENAME*/newLocal;
}
@@ -14,7 +14,6 @@ class C {
// ==SCOPE::Extract to constant in global scope==
const newLocal = 2 + 1;
class C {
x = /*RENAME*/newLocal;
}
@@ -2,5 +2,4 @@
let x = /*[#|*/1/*|]*/;
// ==SCOPE::Extract to constant in enclosing scope==
const newLocal = 1;
let x = /*RENAME*/newLocal;
@@ -2,5 +2,4 @@
let x = /*[#|*/1/*|]*/;
// ==SCOPE::Extract to constant in enclosing scope==
const newLocal = 1;
let x = /*RENAME*/newLocal;
@@ -9,6 +9,5 @@ const x = /*[#|*/2 + 1/*|]*/;
/// <reference path="path.js"/>
const newLocal = 2 + 1;
const x = /*RENAME*/newLocal;
@@ -9,6 +9,5 @@ const x = /*[#|*/2 + 1/*|]*/;
/// <reference path="path.js"/>
const newLocal = 2 + 1;
const x = /*RENAME*/newLocal;