diff --git a/src/pprint.ts b/src/pprint.ts index 7ede7d3..78f9640 100644 --- a/src/pprint.ts +++ b/src/pprint.ts @@ -43,6 +43,14 @@ function loc_to_ns(loc: Loc): ns { } } + function strip_trailing_newline(x: ns): ns { + if (Array.isArray(x) && x.length == 2 && x[1] === "\n") { + return x[0]; + } else { + return x; + } + } + function ns_list(tag: list_tag, ls: ns[]): ns { switch (tag) { case "arrow_function": @@ -53,9 +61,13 @@ function loc_to_ns(loc: Loc): ns { case "program": case "statement_block": case "slice": - return ls.map((x) => [x, "\n\n"]); + return [ + ls.map(strip_trailing_newline).map((x, i) => (i === ls.length - 1 ? x : [x, "\n"])), + "\n", + ]; + default: + return ls; } - return ls; } const lp = "/*>>>*/"; diff --git a/tests/arrow-function-1.ts.expanded b/tests/arrow-function-1.ts.expanded index 95f613c..392841a 100644 --- a/tests/arrow-function-1.ts.expanded +++ b/tests/arrow-function-1.ts.expanded @@ -1,7 +1,5 @@ const f_3 = (x_9) => x_9; - const g_5 = (x_9) => f_3(x_9); - const h_7 = (x_9) => x_9((x_12) => f_3(x_12)); ================================ DONE diff --git a/tests/splice-1.ts.expanded b/tests/splice-1.ts.expanded index 1815661..f55b2ad 100644 --- a/tests/splice-1.ts.expanded +++ b/tests/splice-1.ts.expanded @@ -1,9 +1,6 @@ const t_3 = 13; - const x_5 = 17; - const y_7 = x_5 + t_3; - const q_9 = t_3 + x_5; ================================ DONE diff --git a/tests/splice-2.ts.expanded b/tests/splice-2.ts.expanded index f9c1358..c76d724 100644 --- a/tests/splice-2.ts.expanded +++ b/tests/splice-2.ts.expanded @@ -1,6 +1,5 @@ const foo_3 = (x_5) => { x_5; - x_5; }; ================================ diff --git a/tests/test-1.ts.expanded b/tests/test-1.ts.expanded index 53784be..6e60185 100644 --- a/tests/test-1.ts.expanded +++ b/tests/test-1.ts.expanded @@ -1,5 +1,4 @@ const x_3 = 12; - x_3; ================================ DONE diff --git a/tests/test-2.ts.expanded b/tests/test-2.ts.expanded index e18cd17..cc27090 100644 --- a/tests/test-2.ts.expanded +++ b/tests/test-2.ts.expanded @@ -1,5 +1,4 @@ const x_3 = 12; - x_3 + x_3; ================================ DONE diff --git a/tests/using-syntax-rules-2.ts.expanded b/tests/using-syntax-rules-2.ts.expanded index 1857bf1..6f93de3 100644 --- a/tests/using-syntax-rules-2.ts.expanded +++ b/tests/using-syntax-rules-2.ts.expanded @@ -1,5 +1,4 @@ x_8 + x_8; - const x_8 = 12; ================================ DONE diff --git a/tests/using-syntax-rules-3.ts.expanded b/tests/using-syntax-rules-3.ts.expanded index 8e40d2c..5e6927d 100644 --- a/tests/using-syntax-rules-3.ts.expanded +++ b/tests/using-syntax-rules-3.ts.expanded @@ -1,5 +1,4 @@ (foo_8) => x_6 + x_6; - const x_6 = 12; ================================ DONE diff --git a/tests/using-syntax-rules-4.ts.expanded b/tests/using-syntax-rules-4.ts.expanded index 9e7061b..6d31bc4 100644 --- a/tests/using-syntax-rules-4.ts.expanded +++ b/tests/using-syntax-rules-4.ts.expanded @@ -1,5 +1,4 @@ x_7 + ((foo_9, foo_11) => foo_11 + foo_9); - const x_7 = 12; ================================ DONE