Insert a line break before a function at EOF if needed
This is a pre-existing issue that became more obvious after refining trivia handling.
This commit is contained in:
parent
98f04e6cfd
commit
2ea4cfe23b
|
@ -4526,7 +4526,7 @@ namespace ts.projectSystem {
|
|||
{
|
||||
start: { line: 3, offset: 2 },
|
||||
end: { line: 3, offset: 2 },
|
||||
newText: "\nfunction newFunction() {\n 1;\n}\n",
|
||||
newText: "\n\nfunction newFunction() {\n 1;\n}\n",
|
||||
},
|
||||
]
|
||||
}
|
||||
|
|
|
@ -785,7 +785,10 @@ namespace ts.refactor.extractSymbol {
|
|||
changeTracker.insertNodeBefore(context.file, nodeToInsertBefore, newFunction, { suffix: context.newLineCharacter + context.newLineCharacter });
|
||||
}
|
||||
else {
|
||||
changeTracker.insertNodeBefore(context.file, scope.getLastToken(), newFunction, { prefix: context.newLineCharacter, suffix: context.newLineCharacter });
|
||||
changeTracker.insertNodeBefore(context.file, scope.getLastToken(), newFunction, {
|
||||
prefix: isLineBreak(file.text.charCodeAt(scope.getLastToken().pos)) ? context.newLineCharacter : context.newLineCharacter + context.newLineCharacter,
|
||||
suffix: context.newLineCharacter
|
||||
});
|
||||
}
|
||||
|
||||
const newNodes: Node[] = [];
|
||||
|
|
|
@ -89,6 +89,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(x: number, a: number, foo: () => void) {
|
||||
let y = 5;
|
||||
let z = x;
|
||||
|
|
|
@ -49,6 +49,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
let a1: A.I = { x: 1 };
|
||||
return a1.x + 10;
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(y: number, z: number) {
|
||||
let a1 = { x: 1 };
|
||||
y = 10;
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction<U1a, T1a, U2a, T2a, U3a>(t1a: T1a, t2a: T2a, u1a: U1a, u2a: U2a, u3a: U3a) {
|
||||
t1a.toString();
|
||||
t2a.toString();
|
||||
|
|
|
@ -33,6 +33,7 @@ function F<T>(t1: T) {
|
|||
/*RENAME*/newFunction<T, T>(t1, t2);
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction<T, T>(t1: T, t2: T) {
|
||||
t1.toString();
|
||||
t2.toString();
|
||||
|
|
|
@ -30,6 +30,7 @@ function F<T>(t1: T) {
|
|||
/*RENAME*/newFunction<T, U>(t2);
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction<T, U extends T[]>(t2: U) {
|
||||
t2.toString();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ function F<T>() {
|
|||
function F<T>() {
|
||||
const array: T[] = /*RENAME*/newFunction<T>();
|
||||
}
|
||||
|
||||
function newFunction<T>(): T[] {
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ class C<T1, T2> {
|
|||
/*RENAME*/newFunction<T1>(t1);
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction<T1>(t1: T1) {
|
||||
t1.toString();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ class C {
|
|||
/*RENAME*/newFunction<T1>(t1);
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction<T1>(t1: T1) {
|
||||
t1.toString();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ function F<T, U extends T[], V extends U[]>(v: V) {
|
|||
function F<T, U extends T[], V extends U[]>(v: V) {
|
||||
/*RENAME*/newFunction<T, U, V>(v);
|
||||
}
|
||||
|
||||
function newFunction<T, U extends T[], V extends U[]>(v: V) {
|
||||
v.toString();
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(x: number, foo: () => void) {
|
||||
let y = 5;
|
||||
let z = x;
|
||||
|
|
|
@ -22,6 +22,7 @@ const _ = class {
|
|||
return /*RENAME*/newFunction();
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
let a1 = { x: 1 };
|
||||
return a1.x + 10;
|
||||
|
|
|
@ -22,6 +22,7 @@ const _ = class {
|
|||
return /*RENAME*/newFunction();
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
let a1 = { x: 1 };
|
||||
return a1.x + 10;
|
||||
|
|
|
@ -20,6 +20,7 @@ function foo() {
|
|||
x = /*RENAME*/newFunction(x);
|
||||
return;
|
||||
}
|
||||
|
||||
function newFunction(x) {
|
||||
x++;
|
||||
return x;
|
||||
|
|
|
@ -20,6 +20,7 @@ function foo() {
|
|||
x = /*RENAME*/newFunction(x);
|
||||
return;
|
||||
}
|
||||
|
||||
function newFunction(x: number) {
|
||||
x++;
|
||||
return x;
|
||||
|
|
|
@ -26,6 +26,7 @@ function test() {
|
|||
return /*RENAME*/newFunction();
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ function test() {
|
|||
return /*RENAME*/newFunction();
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace NS {
|
|||
}
|
||||
function M3() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ function Outer() {
|
|||
}
|
||||
function M3() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ function Outer() {
|
|||
}
|
||||
function M3() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class C {
|
|||
}
|
||||
M3() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class C {
|
|||
}
|
||||
M3() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ class C {
|
|||
constructor() { }
|
||||
M3() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ class C {
|
|||
constructor() { }
|
||||
M3() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ class C {
|
|||
M3() { }
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ class C {
|
|||
M3() { }
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function* newFunction(z: number, foo: () => void) {
|
||||
let y = 5;
|
||||
yield z;
|
||||
|
|
|
@ -14,6 +14,7 @@ function F<T>() {
|
|||
function F<T>() {
|
||||
/*RENAME*/newFunction<T>();
|
||||
}
|
||||
|
||||
function newFunction<T>() {
|
||||
let t: T;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace N {
|
|||
f = /*RENAME*/newFunction(f);
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(f: () => number) {
|
||||
f = function(): number {
|
||||
return N.value;
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace N {
|
|||
/*RENAME*/newFunction();
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
var c = class {
|
||||
M() {
|
||||
|
|
|
@ -14,6 +14,7 @@ function F() {
|
|||
function F() {
|
||||
/*RENAME*/newFunction();
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
function G() { }
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ function F() {
|
|||
function F() {
|
||||
/*RENAME*/newFunction();
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
function G() { }
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function newFunction(z: number, z1: any, foo: () => void) {
|
||||
let y = 5;
|
||||
if (z) {
|
||||
|
|
|
@ -89,6 +89,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(x: number, a: number) {
|
||||
let y = 5;
|
||||
let z = x;
|
||||
|
|
|
@ -93,6 +93,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(x: number, a: number) {
|
||||
let y = 5;
|
||||
let z = x;
|
||||
|
|
|
@ -103,6 +103,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(x: number, a: number) {
|
||||
let y = 5;
|
||||
let z = x;
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace A {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
let a1: A.I = { x: 1 };
|
||||
return a1.x + 10;
|
||||
|
|
|
@ -12,6 +12,7 @@ var q = /*b*/ //c
|
|||
var q = /*b*/ //c
|
||||
/*d*/ /*RENAME*/newFunction() /*k*/ //l
|
||||
/*m*/; /*n*/ //o
|
||||
|
||||
function newFunction() {
|
||||
return 1 /*e*/ //f
|
||||
/*g*/ + /*h*/ //i
|
||||
|
|
|
@ -12,6 +12,7 @@ var q = /*b*/ //c
|
|||
var q = /*b*/ //c
|
||||
/*d*/ /*RENAME*/newFunction() /*k*/ //l
|
||||
/*m*/; /*n*/ //o
|
||||
|
||||
function newFunction() {
|
||||
return 1 /*e*/ //f
|
||||
/*g*/ + /*h*/ //i
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace X {
|
|||
export const j = 10;
|
||||
export const y = /*RENAME*/newFunction();
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return X.j * X.j;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ function f() {
|
|||
let x = /*RENAME*/newFunction();
|
||||
return { x };
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
let x;
|
||||
return x;
|
||||
|
|
|
@ -21,6 +21,7 @@ function f() {
|
|||
let x = /*RENAME*/newFunction();
|
||||
return { x };
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
let x;
|
||||
return x;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a) {
|
||||
const x = 1;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
const x = 1;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
const x: number = 1;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
let x: 0o10 | 10 | 0b10 = 10;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
let x: "a" | 'b' = 'a';
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a) {
|
||||
let x = 1;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
let x = 1;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
let x: number = 1;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
let x: /*A*/ "a" /*B*/ | /*C*/ 'b' /*D*/ = 'a';
|
||||
a++;
|
||||
|
|
|
@ -30,6 +30,7 @@ function f() {
|
|||
({ x, y, a } = /*RENAME*/newFunction(a));
|
||||
a; x; y;
|
||||
}
|
||||
|
||||
function newFunction(a) {
|
||||
const x = 1;
|
||||
let y = 2;
|
||||
|
|
|
@ -30,6 +30,7 @@ function f() {
|
|||
({ x, y, a } = /*RENAME*/newFunction(a));
|
||||
a; x; y;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
const x = 1;
|
||||
let y = 2;
|
||||
|
|
|
@ -30,6 +30,7 @@ function f() {
|
|||
({ x, y, a } = /*RENAME*/newFunction(a));
|
||||
a; x; y;
|
||||
}
|
||||
|
||||
function newFunction(a) {
|
||||
var x = 1;
|
||||
let y = 2;
|
||||
|
|
|
@ -30,6 +30,7 @@ function f() {
|
|||
({ x, y, a } = /*RENAME*/newFunction(a));
|
||||
a; x; y;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
var x = 1;
|
||||
let y = 2;
|
||||
|
|
|
@ -30,6 +30,7 @@ function f() {
|
|||
({ x, y, a } = /*RENAME*/newFunction(a));
|
||||
a; x; y;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
let x: number = 1;
|
||||
let y = 2;
|
||||
|
|
|
@ -33,6 +33,7 @@ function f() {
|
|||
({ x, y, z, a } = /*RENAME*/newFunction(a));
|
||||
a; x; y; z;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
let x: number | undefined = 1;
|
||||
let y: undefined | number = 2;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a) {
|
||||
var x = 1;
|
||||
a++;
|
||||
|
|
|
@ -27,6 +27,7 @@ function f() {
|
|||
({ x, a } = /*RENAME*/newFunction(a));
|
||||
a; x;
|
||||
}
|
||||
|
||||
function newFunction(a: number) {
|
||||
var x = 1;
|
||||
a++;
|
||||
|
|
|
@ -12,6 +12,7 @@ edit.applyRefactor({
|
|||
newContent: `function f() {
|
||||
/*RENAME*/newFunction();
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
namespace N { }
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ edit.applyRefactor({
|
|||
newContent: `function f(x: number): number {
|
||||
return /*RENAME*/newFunction(x);
|
||||
}
|
||||
|
||||
function newFunction(x: number) {
|
||||
switch (x) {
|
||||
case 0:
|
||||
|
|
|
@ -13,6 +13,7 @@ edit.applyRefactor({
|
|||
newContent:
|
||||
`// newFunction
|
||||
/*RENAME*/newFunction_1();
|
||||
|
||||
function newFunction_1() {
|
||||
1 + 1;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ edit.applyRefactor({
|
|||
newContent:
|
||||
`export {}; // Make this a module
|
||||
(x => x)(/*RENAME*/newFunction())(1);
|
||||
|
||||
function newFunction(): (x: any) => any {
|
||||
return x => x;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ edit.applyRefactor({
|
|||
({ __return, i } = /*RENAME*/newFunction(i));
|
||||
return __return;
|
||||
}
|
||||
|
||||
function newFunction(i) {
|
||||
return { __return: i++, i };
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ edit.applyRefactor({
|
|||
var i = 10;
|
||||
i = /*RENAME*/newFunction(i);
|
||||
}
|
||||
|
||||
function newFunction(i: number) {
|
||||
i++;
|
||||
return i;
|
||||
|
|
|
@ -18,6 +18,7 @@ edit.applyRefactor({
|
|||
const x = { m: 1 };
|
||||
/*RENAME*/newFunction(x);
|
||||
}
|
||||
|
||||
function newFunction(x: { m: number; }) {
|
||||
x.m = 3;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ edit.applyRefactor({
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newFunction(m: number, j: string, k: { x: string; }) {
|
||||
return m + j + k;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ edit.applyRefactor({
|
|||
let x = 0;
|
||||
console.log(/*RENAME*/newFunction(a, x));
|
||||
}
|
||||
|
||||
function newFunction(a: number[], x: number): any {
|
||||
return a[x];
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ edit.applyRefactor({
|
|||
newContent:
|
||||
`function fn(x = /*RENAME*/newFunction()) {
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
return 3;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue