Skip to content

Commit 30ec63f

Browse files
committed
WIP
1 parent d6e7fcd commit 30ec63f

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/languages/ts.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,14 @@ export default (options = {}) => {
143143
const comment = comments[comment_index];
144144

145145
if (comment && before(comment.loc.start, loc)) {
146-
context.newline();
147146
write_comment(comment, context);
147+
148+
if (comment.loc.end.line < loc.line) {
149+
context.newline();
150+
} else {
151+
context.write(' ');
152+
}
153+
148154
comment_index += 1;
149155
} else {
150156
break;
@@ -260,6 +266,7 @@ export default (options = {}) => {
260266
}
261267

262268
if (node.loc) {
269+
context.newline();
263270
flush_comments_until(context, node.loc.end);
264271
}
265272
}
@@ -521,22 +528,8 @@ export default (options = {}) => {
521528
_(node, context, visit) {
522529
const is_statement = /(Statement|Declaration)$/.test(node.type);
523530

524-
while (comment_index < comments.length) {
525-
const comment = comments[comment_index];
526-
527-
if (before(comment.loc.start, node.loc.start)) {
528-
write_comment(comment, context);
529-
530-
if (comment.loc.start.line < node.loc.start.line) {
531-
context.newline();
532-
} else {
533-
context.write(' ');
534-
}
535-
536-
comment_index += 1;
537-
} else {
538-
break;
539-
}
531+
if (node.loc) {
532+
flush_comments_until(context, node.loc.start);
540533
}
541534

542535
visit(node);

0 commit comments

Comments
 (0)