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

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);
}
});

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);

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 : ""),
});
}