Skip to content

Commit

Permalink
removed extra new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
azizghuloum committed Nov 25, 2024
1 parent 0e0e612 commit 87bba6b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/pprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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 = "/*>>>*/";
Expand Down
2 changes: 0 additions & 2 deletions tests/arrow-function-1.ts.expanded
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions tests/splice-1.ts.expanded
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion tests/splice-2.ts.expanded
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const foo_3 = (x_5) => {
x_5;

x_5;
};
================================
Expand Down
1 change: 0 additions & 1 deletion tests/test-1.ts.expanded
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const x_3 = 12;

x_3;
================================
DONE
1 change: 0 additions & 1 deletion tests/test-2.ts.expanded
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const x_3 = 12;

x_3 + x_3;
================================
DONE
1 change: 0 additions & 1 deletion tests/using-syntax-rules-2.ts.expanded
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
x_8 + x_8;

const x_8 = 12;
================================
DONE
1 change: 0 additions & 1 deletion tests/using-syntax-rules-3.ts.expanded
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(foo_8) => x_6 + x_6;

const x_6 = 12;
================================
DONE
1 change: 0 additions & 1 deletion tests/using-syntax-rules-4.ts.expanded
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
x_7 + ((foo_9, foo_11) => foo_11 + foo_9);

const x_7 = 12;
================================
DONE

0 comments on commit 87bba6b

Please sign in to comment.