Skip to content

Commit 2ae7b10

Browse files
committed
WIP
1 parent 84899c3 commit 2ae7b10

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/services/codefixes/importFixes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ namespace ts.codefix {
345345
return createChangeTracker().insertNodeInListAfter(
346346
sourceFile,
347347
importList.elements[importList.elements.length - 1],
348-
newImportSpecifier).getChanges()
348+
newImportSpecifier).getChanges();
349349
// return {
350350
// newText: `,${oneImportPerLine ? context.newLineCharacter : " "}${newImportText}`,
351351
// span: { start: insertPoint, length: 0 }

src/services/textChanges.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ namespace ts.textChanges {
366366
})
367367
}
368368
}
369+
return this;
369370
}
370371

371372
public getChanges(): FileTextChanges[] {
@@ -435,23 +436,35 @@ namespace ts.textChanges {
435436
// however keep indentation if it is was forced
436437
text = posStartsLine || change.options.indentation !== undefined ? text : text.replace(/^\s+/, "");
437438

438-
if (options.insertLeadingNewLine) {
439-
text = this.newLineCharacter + text;
440-
}
439+
let prefix = "";
441440
if (change.prefix) {
442-
text = change.prefix + text;
441+
prefix = change.prefix;
443442
}
444-
if (change.separatorBefore) {
445-
text = tokenToString(change.separatorBefore.kind) + text;
443+
else {
444+
if (change.separatorBefore) {
445+
prefix += tokenToString(change.separatorBefore.kind);
446+
}
447+
if (options.insertLeadingNewLine) {
448+
prefix += this.newLineCharacter;
449+
}
446450
}
447-
if (change.separatorAfter) {
448-
text = text + tokenToString(change.separatorAfter.kind);
451+
if (prefix) {
452+
text = prefix + text;
449453
}
454+
let suffix = "";
450455
if (change.suffix) {
451-
text = text + change.suffix;
456+
suffix = change.suffix;
452457
}
453-
if (options.insertTrailingNewLine) {
454-
text = text + this.newLineCharacter;
458+
else {
459+
if (change.separatorAfter) {
460+
suffix += tokenToString(change.separatorAfter.kind);
461+
}
462+
if (options.insertTrailingNewLine) {
463+
suffix = suffix + this.newLineCharacter;
464+
}
465+
}
466+
if (suffix) {
467+
text += suffix;
455468
}
456469
return text;
457470
}
@@ -558,9 +571,13 @@ namespace ts.textChanges {
558571
constructor(newLine: string) {
559572
this.writer = createTextWriter(newLine);
560573
this.onEmitNode = (hint, node, printCallback) => {
561-
setPos(node, this.lastNonTriviaPosition);
574+
if (node) {
575+
setPos(node, this.lastNonTriviaPosition);
576+
}
562577
printCallback(hint, node);
563-
setEnd(node, this.lastNonTriviaPosition);
578+
if (node) {
579+
setEnd(node, this.lastNonTriviaPosition);
580+
}
564581
};
565582
this.onBeforeEmitNodeArray = nodes => {
566583
if (nodes) {

0 commit comments

Comments
 (0)