Skip to content

Commit 178198b

Browse files
Fix 53482 : Preserve newline/space behavior (#53732)
Co-authored-by: Andrew Branch <[email protected]>
1 parent e4f8c37 commit 178198b

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

src/compiler/emitter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4875,7 +4875,10 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
48754875
}
48764876

48774877
function emitEmbeddedStatement(parent: Node, node: Statement) {
4878-
if (isBlock(node) || getEmitFlags(parent) & EmitFlags.SingleLine) {
4878+
if (isBlock(node) ||
4879+
getEmitFlags(parent) & EmitFlags.SingleLine ||
4880+
preserveSourceNewlines && !getLeadingLineTerminatorCount(parent, node, ListFormat.None)
4881+
) {
48794882
writeSpace();
48804883
emit(node);
48814884
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////function foo() {
4+
//// /*1*/if (true) console.log(1);
5+
//// else console.log(1);
6+
//// if (true)
7+
//// console.log(1);
8+
//// else
9+
//// console.log(1);
10+
////
11+
//// do console.log(1);
12+
//// while (false);
13+
//// do
14+
//// console.log(1);
15+
//// while (false);
16+
////
17+
//// while (true) console.log(1);
18+
//// while (true)
19+
//// console.log(1);
20+
////
21+
//// for (let i = 1; i < 4; i++) console.log(1); // 1,2,3
22+
//// for (let i = 1; i < 4; i++)
23+
//// console.log(1); // 1,2,3
24+
////
25+
//// for (let i in [1, 2, 3]) console.log(1);
26+
//// for (let i in [1, 2, 3])
27+
//// console.log(1);
28+
////
29+
//// for (let i of [1, 2, 3]) console.log(1);
30+
//// for (let i of [1, 2, 3])
31+
//// console.log(1);
32+
////
33+
//// with ([1, 2, 3]) console.log(toString());
34+
//// with ([1, 2, 3])
35+
//// console.log(toString());/*2*/
36+
////}
37+
38+
goTo.select("1", "2");
39+
edit.applyRefactor({
40+
refactorName: "Extract Symbol",
41+
actionName: "function_scope_1",
42+
actionDescription: "Extract to function in global scope",
43+
newContent:
44+
`function foo() {
45+
/*RENAME*/newFunction();
46+
}
47+
48+
function newFunction() {
49+
if (true) console.log(1);
50+
else console.log(1);
51+
if (true)
52+
console.log(1);
53+
54+
else
55+
console.log(1);
56+
57+
do console.log(1);
58+
while (false);
59+
do
60+
console.log(1);
61+
while (false);
62+
63+
while (true) console.log(1);
64+
while (true)
65+
console.log(1);
66+
67+
for (let i = 1; i < 4; i++) console.log(1); // 1,2,3
68+
for (let i = 1; i < 4; i++)
69+
console.log(1); // 1,2,3
70+
71+
for (let i in [1, 2, 3]) console.log(1);
72+
for (let i in [1, 2, 3])
73+
console.log(1);
74+
75+
for (let i of [1, 2, 3]) console.log(1);
76+
for (let i of [1, 2, 3])
77+
console.log(1);
78+
79+
with ([1, 2, 3]) console.log(toString());
80+
with ([1, 2, 3])
81+
console.log(toString());
82+
}
83+
`
84+
});

0 commit comments

Comments
 (0)