Skip to content

Commit d6e7fcd

Browse files
committed
WIP
1 parent ddef4e2 commit d6e7fcd

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/languages/ts.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,19 @@ export default (options = {}) => {
105105

106106
/**
107107
* @param {Context} context
108-
* @param {{ line: number, column: number }} loc
108+
* @param {{ line: number, column: number }} prev
109+
* @param {{ line: number, column: number } | null} next
109110
* @returns {boolean} true if final comment is a line comment
110111
*/
111-
function flush_trailing_comments(context, loc) {
112+
function flush_trailing_comments(context, prev, next) {
112113
while (comment_index < comments.length) {
113114
const comment = comments[comment_index];
114115

115-
if (comment && comment.loc.start.line === loc.line) {
116+
if (
117+
comment &&
118+
comment.loc.start.line === prev.line &&
119+
(next === null || before(comment.loc.end, next))
120+
) {
116121
context.write(' ');
117122
write_comment(comment, context);
118123

@@ -154,10 +159,8 @@ export default (options = {}) => {
154159
* @param {boolean} pad
155160
*/
156161
function sequence(context, node, nodes, pad, separator = ',') {
157-
if (nodes.length === 0) return;
158-
159162
let multiline = false;
160-
let length = -2;
163+
let length = -1;
161164

162165
/** @type {boolean[]} */
163166
const multiline_nodes = [];
@@ -172,7 +175,8 @@ export default (options = {}) => {
172175
child_context.write(separator);
173176
}
174177

175-
if (child && flush_trailing_comments(child_context, child.loc.end)) {
178+
const next = i === nodes.length - 1 ? node.loc.end : nodes[i + 1]?.loc.start || null;
179+
if (child && flush_trailing_comments(child_context, child.loc.end, next)) {
176180
multiline = true;
177181
}
178182

@@ -187,7 +191,7 @@ export default (options = {}) => {
187191
if (multiline) {
188192
context.indent();
189193
context.newline();
190-
} else if (pad) {
194+
} else if (pad && length > 0) {
191195
context.write(' ');
192196
}
193197

@@ -219,7 +223,7 @@ export default (options = {}) => {
219223
if (multiline) {
220224
context.dedent();
221225
context.newline();
222-
} else if (pad) {
226+
} else if (pad && length > 0) {
223227
context.write(' ');
224228
}
225229
}
@@ -538,7 +542,7 @@ export default (options = {}) => {
538542
visit(node);
539543

540544
if (is_statement && node.loc) {
541-
flush_trailing_comments(context, node.loc.end);
545+
flush_trailing_comments(context, node.loc.end, null);
542546
}
543547
},
544548

test/samples/large-file/expected.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,7 @@
24252425
return bySet ? markFunction(superMatcher) : superMatcher;
24262426
}
24272427

2428-
function compile(selector, /* Internal Use Only */ match) {
2428+
function compile(selector, match /* Internal Use Only */) {
24292429
var i,
24302430
setMatchers = [],
24312431
elementMatchers = [],

test/samples/large-file/expected.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)