mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Fix 53482 : Preserve newline/space behavior (#53732)
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
This commit is contained in:
parent
e4f8c378c0
commit
178198be04
@ -4875,7 +4875,10 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
|
||||
}
|
||||
|
||||
function emitEmbeddedStatement(parent: Node, node: Statement) {
|
||||
if (isBlock(node) || getEmitFlags(parent) & EmitFlags.SingleLine) {
|
||||
if (isBlock(node) ||
|
||||
getEmitFlags(parent) & EmitFlags.SingleLine ||
|
||||
preserveSourceNewlines && !getLeadingLineTerminatorCount(parent, node, ListFormat.None)
|
||||
) {
|
||||
writeSpace();
|
||||
emit(node);
|
||||
}
|
||||
|
||||
84
tests/cases/fourslash/preserveSpace.ts
Normal file
84
tests/cases/fourslash/preserveSpace.ts
Normal file
@ -0,0 +1,84 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////function foo() {
|
||||
//// /*1*/if (true) console.log(1);
|
||||
//// else console.log(1);
|
||||
//// if (true)
|
||||
//// console.log(1);
|
||||
//// else
|
||||
//// console.log(1);
|
||||
////
|
||||
//// do console.log(1);
|
||||
//// while (false);
|
||||
//// do
|
||||
//// console.log(1);
|
||||
//// while (false);
|
||||
////
|
||||
//// while (true) console.log(1);
|
||||
//// while (true)
|
||||
//// console.log(1);
|
||||
////
|
||||
//// for (let i = 1; i < 4; i++) console.log(1); // 1,2,3
|
||||
//// for (let i = 1; i < 4; i++)
|
||||
//// console.log(1); // 1,2,3
|
||||
////
|
||||
//// for (let i in [1, 2, 3]) console.log(1);
|
||||
//// for (let i in [1, 2, 3])
|
||||
//// console.log(1);
|
||||
////
|
||||
//// for (let i of [1, 2, 3]) console.log(1);
|
||||
//// for (let i of [1, 2, 3])
|
||||
//// console.log(1);
|
||||
////
|
||||
//// with ([1, 2, 3]) console.log(toString());
|
||||
//// with ([1, 2, 3])
|
||||
//// console.log(toString());/*2*/
|
||||
////}
|
||||
|
||||
goTo.select("1", "2");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract Symbol",
|
||||
actionName: "function_scope_1",
|
||||
actionDescription: "Extract to function in global scope",
|
||||
newContent:
|
||||
`function foo() {
|
||||
/*RENAME*/newFunction();
|
||||
}
|
||||
|
||||
function newFunction() {
|
||||
if (true) console.log(1);
|
||||
else console.log(1);
|
||||
if (true)
|
||||
console.log(1);
|
||||
|
||||
else
|
||||
console.log(1);
|
||||
|
||||
do console.log(1);
|
||||
while (false);
|
||||
do
|
||||
console.log(1);
|
||||
while (false);
|
||||
|
||||
while (true) console.log(1);
|
||||
while (true)
|
||||
console.log(1);
|
||||
|
||||
for (let i = 1; i < 4; i++) console.log(1); // 1,2,3
|
||||
for (let i = 1; i < 4; i++)
|
||||
console.log(1); // 1,2,3
|
||||
|
||||
for (let i in [1, 2, 3]) console.log(1);
|
||||
for (let i in [1, 2, 3])
|
||||
console.log(1);
|
||||
|
||||
for (let i of [1, 2, 3]) console.log(1);
|
||||
for (let i of [1, 2, 3])
|
||||
console.log(1);
|
||||
|
||||
with ([1, 2, 3]) console.log(toString());
|
||||
with ([1, 2, 3])
|
||||
console.log(toString());
|
||||
}
|
||||
`
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user