diff --git a/crates/tsv_svelte/src/printer/nodes/tags_doc.rs b/crates/tsv_svelte/src/printer/nodes/tags_doc.rs index 1a7c6ae4..2c7acbfd 100644 --- a/crates/tsv_svelte/src/printer/nodes/tags_doc.rs +++ b/crates/tsv_svelte/src/printer/nodes/tags_doc.rs @@ -55,26 +55,32 @@ impl<'a> Printer<'a> { ); // Choose layout matching prettier's assignment layout selection. - if d.will_break(init_doc) { - // Init has forced breaks (ternary, multi-line template, etc.) - // Keep "= init" together — init's own breaks handle formatting. - d.concat(&[ - d.text("{@const "), - id_doc, - d.text(" = "), - init_doc, - d.text("}"), - ]) - } else if Self::const_should_break_after_op(&tag.init) { + if Self::const_should_break_after_op(&tag.init) { // Binary expressions, conditional with binary test, etc. // Break-after-operator: group with line at "=" so the doc printer - // can break when the flat form exceeds print width. + // can break when the flat form exceeds print width. This takes + // precedence over the `will_break` keep-together branch below — a + // break-after-operator RHS still breaks after `=` even when it has a + // forced internal break (e.g. a conditional whose binary test carries + // a trailing line comment), matching prettier and our own TS + // assignment printer. // Prettier ref: shouldBreakAfterOperator (assignment.js:196-259) let rhs = d.concat(&[d.line(), init_doc]); let rhs_indented = d.indent(rhs); let assignment = d.group(d.concat(&[d.text(" ="), rhs_indented, d.text("}")])); d.concat(&[d.text("{@const "), id_doc, assignment]) + } else if d.will_break(init_doc) { + // Init has forced breaks (object/array/template, etc.) that aren't + // break-after-operator — keep "= init" together, init's own breaks + // handle formatting. + d.concat(&[ + d.text("{@const "), + id_doc, + d.text(" = "), + init_doc, + d.text("}"), + ]) } else { // Fluid layout: break at `=` only when the full line exceeds // print width. Uses indentIfBreak so the RHS is evaluated diff --git a/crates/tsv_ts/src/printer/calls/arg_comments.rs b/crates/tsv_ts/src/printer/calls/arg_comments.rs index 01dcfe33..c5875783 100644 --- a/crates/tsv_ts/src/printer/calls/arg_comments.rs +++ b/crates/tsv_ts/src/printer/calls/arg_comments.rs @@ -524,6 +524,9 @@ impl<'a> PartitionedComments<'a> { /// Emit trailing comments (block then line) with leading spaces to a parts vector. /// /// Used for comments that follow an argument, formatted as ` /* block */ // line`. + /// Line comments go through `line_suffix` (zero width) so they never count against + /// the argument's own group — flushing at the caller's following hardline (every + /// caller is a forced-multiline context). Prettier's `lineSuffix`. pub fn emit_trailing_comments(&self, parts: &mut Vec, printer: &Printer<'_>) { let d = printer.d(); for comment in &self.trailing_block { @@ -531,8 +534,7 @@ impl<'a> PartitionedComments<'a> { parts.push(printer.build_comment_doc(comment)); } for comment in &self.trailing_line { - parts.push(d.text(" ")); - parts.push(printer.build_comment_doc(comment)); + parts.push(printer.build_trailing_line_comment_doc(comment)); } } diff --git a/crates/tsv_ts/src/printer/calls/call_formatting.rs b/crates/tsv_ts/src/printer/calls/call_formatting.rs index e69333dd..75c13150 100644 --- a/crates/tsv_ts/src/printer/calls/call_formatting.rs +++ b/crates/tsv_ts/src/printer/calls/call_formatting.rs @@ -1094,12 +1094,15 @@ pub(super) fn build_call_doc_with_wrapping( } if pc.has_trailing_line() { - // Trailing line comments: comma, comment, hardline + // Trailing line comments: comma, comment, hardline. The comment + // goes through `line_suffix` (zero width) so it never counts + // against the argument's own group — a long trailing comment + // can't force a binary/conditional arg to break (prettier's + // `lineSuffix`). It still renders after the comma at end-of-line. force_expansion = true; arg_parts.push(d.text(",")); for comment in &pc.trailing_line { - arg_parts.push(d.text(" ")); - arg_parts.push(printer.build_comment_doc(comment)); + arg_parts.push(printer.build_trailing_line_comment_doc(comment)); } if has_blank_line { arg_parts.push(d.literalline()); @@ -1202,15 +1205,11 @@ pub(super) fn build_call_doc_with_wrapping( // comment means the call must break to multiple lines. force_expansion = true; - // Arrays/objects have their own groups that decide internal expansion. - // Use line_suffix to exclude the comment from width calculations, so - // the array/object can stay inline even when the comment exceeds print_width. - // The force_expansion above ensures the call itself expands. - if is_array_or_object_unwrapped(arg) { - arg_parts.push(d.line_suffix(comments)); - } else { - arg_parts.push(comments); - } + // A trailing line comment never counts toward width (prettier's + // `lineSuffix`), so the argument's own group (array/object, binary, + // conditional, …) can stay inline even when the comment exceeds + // print_width. The force_expansion above ensures the call expands. + arg_parts.push(d.line_suffix(comments)); has_trailing_comma_on_last = true; } else if pc.has_trailing_block() { // Trailing block comments: place relative to the source comma. diff --git a/crates/tsv_ts/src/printer/calls/new_expression.rs b/crates/tsv_ts/src/printer/calls/new_expression.rs index e72d4a84..c4db1534 100644 --- a/crates/tsv_ts/src/printer/calls/new_expression.rs +++ b/crates/tsv_ts/src/printer/calls/new_expression.rs @@ -433,9 +433,11 @@ impl<'a> Printer<'a> { arg_parts.push(self.build_comment_doc(comment)); } arg_parts.push(d.text(",")); + // Line comment via `line_suffix` (zero width) so it never forces + // the argument's own group to break; flushes at the hardline + // before the closing paren (prettier's `lineSuffix`). for comment in &pc.trailing_line { - arg_parts.push(d.text(" ")); - arg_parts.push(self.build_comment_doc(comment)); + arg_parts.push(self.build_trailing_line_comment_doc(comment)); } has_trailing_comma_on_last = true; } else if pc.has_trailing_block() { diff --git a/crates/tsv_ts/src/printer/comments.rs b/crates/tsv_ts/src/printer/comments.rs index 13f9ad56..b8838148 100644 --- a/crates/tsv_ts/src/printer/comments.rs +++ b/crates/tsv_ts/src/printer/comments.rs @@ -1368,13 +1368,34 @@ impl<'a> Printer<'a> { /// /// Used when line comments force multiline formatting (unions, tuples, etc.) pub(crate) fn build_trailing_comments_multiline(&self, start: u32, end: u32) -> Vec { + self.build_trailing_comments_multiline_ext(start, end, false) + } + + /// As `build_trailing_comments_multiline`, but when `suffix_same_line_lines` is set + /// a same-line **line** comment is routed through `line_suffix` (zero width) so it + /// can't force the preceding element to break. Only safe where the following + /// separator lands on a *new* line (so the suffix flushes at that hardline without + /// crossing the separator) — true for the union's leading-`|` form, but NOT the + /// intersection's trailing-`&` form (a same-line `//` there would otherwise comment + /// out the `&`; that case is handled as a comment-position divergence instead). + pub(crate) fn build_trailing_comments_multiline_ext( + &self, + start: u32, + end: u32, + suffix_same_line_lines: bool, + ) -> Vec { let d = self.d(); let mut parts = Vec::new(); for comment in comments_in_range(self.comments, start, end) { if self.is_same_line(start, comment.span.start) { - // Same line as start: trailing comment (both block and line) - parts.push(d.text(" ")); - parts.push(self.build_comment_doc(comment)); + if suffix_same_line_lines { + // Block → inline (width counted); line → line_suffix (zero width). + parts.push(self.build_trailing_comment_doc(comment)); + } else { + // Same line as start: trailing comment (block or line), inline. + parts.push(d.text(" ")); + parts.push(self.build_comment_doc(comment)); + } } else { // Own line comment (block or line) parts.push(d.hardline()); @@ -2246,12 +2267,14 @@ impl<'a> Printer<'a> { // Comma parts.push(d.text(",")); - // Same-line trailing comments after comma (line comments that consume the line) + // Same-line trailing comments after comma (line comments that consume the line). + // A line comment goes through `line_suffix` (zero width) so it never forces the + // preceding element to break; it flushes at the hardline below (prettier's + // `lineSuffix`). A block stays inline, width counted. let mut after_comma_end = comma_pos + 1; for comment in comments_in_range(self.comments, comma_pos + 1, next_start) { if self.is_same_line(elem_end, comment.span.start) { - parts.push(d.text(" ")); - parts.push(self.build_comment_doc(comment)); + parts.push(self.build_trailing_comment_doc(comment)); after_comma_end = comment.span.end; } } diff --git a/crates/tsv_ts/src/printer/expressions/conditional.rs b/crates/tsv_ts/src/printer/expressions/conditional.rs index b9826484..f1ee2fdd 100644 --- a/crates/tsv_ts/src/printer/expressions/conditional.rs +++ b/crates/tsv_ts/src/printer/expressions/conditional.rs @@ -305,11 +305,13 @@ impl<'a> Printer<'a> { let mut parts = vec![test]; - // Comments between test and ? (inline after test) + // Comments between test and ? (inline after test). A line comment goes + // through `line_suffix` (zero width), so a long trailing comment never + // forces the test (e.g. a binary expression) to break — matching + // prettier's `lineSuffix`. Block comments stay inline, width counted. let comments_before_q_end = question_pos.unwrap_or(consequent_start); for comment in tsv_lang::comments_in_range(self.comments, test_end, comments_before_q_end) { - parts.push(d.text(" ")); - parts.push(self.build_comment_doc(comment)); + parts.push(self.build_trailing_comment_doc(comment)); } // Start the indented part with ? on new line diff --git a/crates/tsv_ts/src/printer/expressions/operators.rs b/crates/tsv_ts/src/printer/expressions/operators.rs index 3eab0644..fea9a3b1 100644 --- a/crates/tsv_ts/src/printer/expressions/operators.rs +++ b/crates/tsv_ts/src/printer/expressions/operators.rs @@ -725,9 +725,12 @@ impl<'a> Printer<'a> { let has_newline_before = self.has_newline_between(pos, comment.span.start); if is_first && !has_newline_before { - // First comment on same line as operator: `a && // comment` - parts.push(d.text(" ")); - parts.push(self.build_comment_doc(comment)); + // First comment on same line as operator: `a && // comment`. A + // line comment goes through `line_suffix` (zero width), so a long + // trailing comment never forces the preceding operand group to + // break — matching prettier's `lineSuffix`. Block comments stay + // inline, width counted. + parts.push(self.build_trailing_comment_doc(comment)); } else { // Comment on its own line parts.push(d.hardline()); @@ -1170,13 +1173,9 @@ impl<'a> Printer<'a> { if self.has_newline_between(pos, comment.span.start) { break; } - if comment.is_block { - od.push(d.text(" ")); - od.push(self.build_comment_doc(comment)); - } else { - let suffix = d.concat(&[d.text(" "), self.build_comment_doc(comment)]); - od.push(d.line_suffix(suffix)); - } + // Same-line trailing comment: block inline before the comma, line + // comment deferred via `line_suffix` to render after the comma. + od.push(self.build_trailing_comment_doc(comment)); pos = comment.span.end; } } diff --git a/crates/tsv_ts/src/printer/statements/control_flow/switch.rs b/crates/tsv_ts/src/printer/statements/control_flow/switch.rs index e2c55790..0427bcab 100644 --- a/crates/tsv_ts/src/printer/statements/control_flow/switch.rs +++ b/crates/tsv_ts/src/printer/statements/control_flow/switch.rs @@ -220,8 +220,11 @@ impl<'a> Printer<'a> { tsv_lang::comments_in_range(self.comments, case_label_end, inline_comment_end) { if self.is_same_line(case_label_end, comment.span.start) { - parts.push(d.text(" ")); - parts.push(self.build_comment_doc(comment)); + // A line comment goes through `line_suffix` (zero width) so it never + // forces the case test (e.g. a binary expression) to break; it flushes + // at the consequent's hardline (prettier's `lineSuffix`). A block stays + // inline, width counted. + parts.push(self.build_trailing_comment_doc(comment)); if !comment.is_block { has_inline_line_comment = true; } diff --git a/crates/tsv_ts/src/printer/statements/variable.rs b/crates/tsv_ts/src/printer/statements/variable.rs index abcc741b..1d84ed7d 100644 --- a/crates/tsv_ts/src/printer/statements/variable.rs +++ b/crates/tsv_ts/src/printer/statements/variable.rs @@ -188,10 +188,14 @@ impl<'a> Printer<'a> { if needs_hardline { parts.push(d.hardline()); parts.push(d.text(INDENT)); + parts.push(self.build_comment_doc(comment)); } else { - parts.push(d.text(" ")); + // Same-line comment trailing the comma: a line comment + // goes through `line_suffix` (zero width) so it never + // forces the preceding declarator's value to break + // (prettier's `lineSuffix`); a block stays inline. + parts.push(self.build_trailing_comment_doc(comment)); } - parts.push(self.build_comment_doc(comment)); needs_hardline = !comment.is_block; } } else { diff --git a/crates/tsv_ts/src/printer/types/union_intersection.rs b/crates/tsv_ts/src/printer/types/union_intersection.rs index 4d5a0d4a..5396d8f8 100644 --- a/crates/tsv_ts/src/printer/types/union_intersection.rs +++ b/crates/tsv_ts/src/printer/types/union_intersection.rs @@ -363,8 +363,15 @@ impl<'a> Printer<'a> { if let Some(pipe_pos) = find_separator_position(self.source, prev_type_end, type_start, b'|') { - // Comments before the pipe (trailing on previous type's line or on own lines) - parts.extend(self.build_trailing_comments_multiline(prev_type_end, pipe_pos)); + // Comments before the pipe (trailing on previous type's line or on + // own lines). A same-line line comment is line_suffix'd (zero width) + // so it can't force the previous member to break — the leading-`|` + // form puts the next separator on a new line, where it flushes. + parts.extend(self.build_trailing_comments_multiline_ext( + prev_type_end, + pipe_pos, + true, + )); // Relocated paren leading line comments: trail prev member for comment in &relocated_paren_leading { diff --git a/tests/fixtures/svelte/tags/const/const_ternary_binary_test_comment/expected.json b/tests/fixtures/svelte/tags/const/const_ternary_binary_test_comment/expected.json new file mode 100644 index 00000000..5a734897 --- /dev/null +++ b/tests/fixtures/svelte/tags/const/const_ternary_binary_test_comment/expected.json @@ -0,0 +1,214 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 142, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [ + { + "type": "IfBlock", + "elseif": false, + "start": 0, + "end": 141, + "test": { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "name": "x" + }, + "consequent": { + "type": "Fragment", + "nodes": [ + { + "type": "Text", + "start": 7, + "end": 9, + "raw": "\n\t", + "data": "\n\t" + }, + { + "type": "ConstTag", + "start": 9, + "end": 135, + "declaration": { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "y", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 9, + "character": 17 + }, + "end": { + "line": 2, + "column": 10, + "character": 18 + } + } + }, + "init": { + "type": "ConditionalExpression", + "start": 23, + "end": 134, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "test": { + "type": "BinaryExpression", + "start": 23, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "name": "aaaaa" + }, + "operator": "===", + "right": { + "type": "Identifier", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "name": "bbbbb" + }, + "trailingComments": [ + { + "type": "Line", + "value": " comment that pushes the const test line well over the print width xxxxxxxxxxxx", + "start": 39, + "end": 120 + } + ] + }, + "consequent": { + "type": "Literal", + "start": 126, + "end": 127, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "value": 1, + "raw": "1" + }, + "alternate": { + "type": "Literal", + "start": 133, + "end": 134, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": 2, + "raw": "2" + } + }, + "start": 17, + "end": 134 + } + ], + "start": 11, + "end": 134 + } + }, + { + "type": "Text", + "start": 135, + "end": 136, + "raw": "\n", + "data": "\n" + } + ] + }, + "alternate": null + } + ] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " comment that pushes the const test line well over the print width xxxxxxxxxxxx", + "start": 39, + "end": 120, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 99 + } + } + } + ] +} diff --git a/tests/fixtures/svelte/tags/const/const_ternary_binary_test_comment/input.svelte b/tests/fixtures/svelte/tags/const/const_ternary_binary_test_comment/input.svelte new file mode 100644 index 00000000..1fb793e2 --- /dev/null +++ b/tests/fixtures/svelte/tags/const/const_ternary_binary_test_comment/input.svelte @@ -0,0 +1,6 @@ +{#if x} + {@const y = + aaaaa === bbbbb // comment that pushes the const test line well over the print width xxxxxxxxxxxx + ? 1 + : 2} +{/if} diff --git a/tests/fixtures/typescript/declarations/variable/multiple/binary_trailing_long_comment/expected.json b/tests/fixtures/typescript/declarations/variable/multiple/binary_trailing_long_comment/expected.json new file mode 100644 index 00000000..6dc8e24b --- /dev/null +++ b/tests/fixtures/typescript/declarations/variable/multiple/binary_trailing_long_comment/expected.json @@ -0,0 +1,208 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 132, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " comment pushing the declarator line over print width", + "start": 54, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 100 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 131, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 122, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 10, + "end": 121, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 14, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "id": { + "type": "Identifier", + "start": 14, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "name": "aaaaaaaaaa" + }, + "init": { + "type": "BinaryExpression", + "start": 27, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "left": { + "type": "Identifier", + "start": 27, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "name": "bbbbbbbbbb" + }, + "operator": "===", + "right": { + "type": "Identifier", + "start": 42, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "name": "cccccccccc" + } + }, + "trailingComments": [ + { + "type": "Line", + "value": " comment pushing the declarator line over print width", + "start": 54, + "end": 109 + } + ] + }, + { + "type": "VariableDeclarator", + "start": 112, + "end": 120, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "id": { + "type": "Identifier", + "start": 112, + "end": 116, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "name": "dddd" + }, + "init": { + "type": "Literal", + "start": 119, + "end": 120, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": 1, + "raw": "1" + } + } + ], + "kind": "let" + } + ], + "sourceType": "module" + }, + "attributes": [] + } +} diff --git a/tests/fixtures/typescript/declarations/variable/multiple/binary_trailing_long_comment/input.svelte b/tests/fixtures/typescript/declarations/variable/multiple/binary_trailing_long_comment/input.svelte new file mode 100644 index 00000000..995100ff --- /dev/null +++ b/tests/fixtures/typescript/declarations/variable/multiple/binary_trailing_long_comment/input.svelte @@ -0,0 +1,4 @@ + diff --git a/tests/fixtures/typescript/expressions/binary/operator_trailing_long_comment/expected.json b/tests/fixtures/typescript/expressions/binary/operator_trailing_long_comment/expected.json new file mode 100644 index 00000000..ac4a4a63 --- /dev/null +++ b/tests/fixtures/typescript/expressions/binary/operator_trailing_long_comment/expected.json @@ -0,0 +1,216 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 236, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " Trailing line comment after operator - operand fits, comment pushes line over 100 chars", + "start": 10, + "end": 100, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 91 + } + } + }, + { + "type": "Line", + "value": " comment that pushes the operand line over the print width xxxxxxx", + "start": 143, + "end": 211, + "loc": { + "start": { + "line": 4, + "column": 31 + }, + "end": { + "line": 4, + "column": 99 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 235, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 226, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 102, + "end": 225, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 108, + "end": 224, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 108, + "end": 109, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "name": "x" + }, + "init": { + "type": "LogicalExpression", + "start": 114, + "end": 224, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "left": { + "type": "BinaryExpression", + "start": 114, + "end": 139, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 114, + "end": 124, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "name": "aaaaaaaaaa" + }, + "operator": "===", + "right": { + "type": "Identifier", + "start": 129, + "end": 139, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "name": "bbbbbbbbbb" + } + }, + "operator": "&&", + "right": { + "type": "Identifier", + "start": 214, + "end": 224, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "name": "cccccccccc", + "leadingComments": [ + { + "type": "Line", + "value": " comment that pushes the operand line over the print width xxxxxxx", + "start": 143, + "end": 211 + } + ] + } + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " Trailing line comment after operator - operand fits, comment pushes line over 100 chars", + "start": 10, + "end": 100 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [] + } +} diff --git a/tests/fixtures/typescript/expressions/binary/operator_trailing_long_comment/input.svelte b/tests/fixtures/typescript/expressions/binary/operator_trailing_long_comment/input.svelte new file mode 100644 index 00000000..2853d635 --- /dev/null +++ b/tests/fixtures/typescript/expressions/binary/operator_trailing_long_comment/input.svelte @@ -0,0 +1,6 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/arg_binary_trailing_long_comment/expected.json b/tests/fixtures/typescript/expressions/calls/arg_binary_trailing_long_comment/expected.json new file mode 100644 index 00000000..1800df83 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/arg_binary_trailing_long_comment/expected.json @@ -0,0 +1,200 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 233, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " Trailing line comment after a binary argument - the binary fits, the comment pushes over 100", + "start": 10, + "end": 105, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 96 + } + } + }, + { + "type": "Line", + "value": " comment that pushes the argument line over the print width xxxxxxxx", + "start": 140, + "end": 210, + "loc": { + "start": { + "line": 4, + "column": 29 + }, + "end": { + "line": 4, + "column": 99 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 232, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 223, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 107, + "end": 222, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "expression": { + "type": "CallExpression", + "start": 107, + "end": 221, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 107, + "end": 109, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 3 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "BinaryExpression", + "start": 113, + "end": 138, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 113, + "end": 123, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "name": "aaaaaaaaaa" + }, + "operator": "===", + "right": { + "type": "Identifier", + "start": 128, + "end": 138, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "name": "bbbbbbbbbb" + }, + "trailingComments": [ + { + "type": "Line", + "value": " comment that pushes the argument line over the print width xxxxxxxx", + "start": 140, + "end": 210 + } + ] + }, + { + "type": "Identifier", + "start": 213, + "end": 217, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "name": "cccc" + } + ], + "optional": false + }, + "leadingComments": [ + { + "type": "Line", + "value": " Trailing line comment after a binary argument - the binary fits, the comment pushes over 100", + "start": 10, + "end": 105 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [] + } +} diff --git a/tests/fixtures/typescript/expressions/calls/arg_binary_trailing_long_comment/input.svelte b/tests/fixtures/typescript/expressions/calls/arg_binary_trailing_long_comment/input.svelte new file mode 100644 index 00000000..4c9aa202 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/arg_binary_trailing_long_comment/input.svelte @@ -0,0 +1,7 @@ + diff --git a/tests/fixtures/typescript/expressions/calls/new_arg_binary_trailing_long_comment/expected.json b/tests/fixtures/typescript/expressions/calls/new_arg_binary_trailing_long_comment/expected.json new file mode 100644 index 00000000..1a67da87 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/new_arg_binary_trailing_long_comment/expected.json @@ -0,0 +1,199 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 231, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " Trailing line comment after a binary argument in a `new` call - binary stays inline", + "start": 10, + "end": 96, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 87 + } + } + }, + { + "type": "Line", + "value": " comment that pushes the new argument line over the print width xxxx", + "start": 138, + "end": 208, + "loc": { + "start": { + "line": 4, + "column": 29 + }, + "end": { + "line": 4, + "column": 99 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 230, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 221, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 98, + "end": 220, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "expression": { + "type": "NewExpression", + "start": 98, + "end": 219, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "callee": { + "type": "Identifier", + "start": 102, + "end": 107, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "name": "Class" + }, + "arguments": [ + { + "type": "BinaryExpression", + "start": 111, + "end": 136, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 111, + "end": 121, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "name": "aaaaaaaaaa" + }, + "operator": "===", + "right": { + "type": "Identifier", + "start": 126, + "end": 136, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "name": "bbbbbbbbbb" + }, + "trailingComments": [ + { + "type": "Line", + "value": " comment that pushes the new argument line over the print width xxxx", + "start": 138, + "end": 208 + } + ] + }, + { + "type": "Identifier", + "start": 211, + "end": 215, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "name": "cccc" + } + ] + }, + "leadingComments": [ + { + "type": "Line", + "value": " Trailing line comment after a binary argument in a `new` call - binary stays inline", + "start": 10, + "end": 96 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [] + } +} diff --git a/tests/fixtures/typescript/expressions/calls/new_arg_binary_trailing_long_comment/input.svelte b/tests/fixtures/typescript/expressions/calls/new_arg_binary_trailing_long_comment/input.svelte new file mode 100644 index 00000000..b3084e85 --- /dev/null +++ b/tests/fixtures/typescript/expressions/calls/new_arg_binary_trailing_long_comment/input.svelte @@ -0,0 +1,7 @@ + diff --git a/tests/fixtures/typescript/expressions/ternary/test_trailing_long_comment/expected.json b/tests/fixtures/typescript/expressions/ternary/test_trailing_long_comment/expected.json new file mode 100644 index 00000000..59a1ba5a --- /dev/null +++ b/tests/fixtures/typescript/expressions/ternary/test_trailing_long_comment/expected.json @@ -0,0 +1,266 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 245, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " Trailing line comment on test - binary test fits, comment pushes line over 100 chars", + "start": 10, + "end": 97, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 88 + } + } + }, + { + "type": "Line", + "value": " comment that pushes the test line well over the print width xxxxxxxxxxxxxxxxxx", + "start": 127, + "end": 208, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 99 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 244, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 235, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 99, + "end": 234, + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 105, + "end": 233, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 105, + "end": 106, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "name": "x" + }, + "init": { + "type": "ConditionalExpression", + "start": 111, + "end": 233, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "test": { + "type": "BinaryExpression", + "start": 111, + "end": 126, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "left": { + "type": "Identifier", + "start": 111, + "end": 116, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "name": "aaaaa" + }, + "operator": "===", + "right": { + "type": "Identifier", + "start": 121, + "end": 126, + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "name": "bbbbb" + }, + "trailingComments": [ + { + "type": "Line", + "value": " comment that pushes the test line well over the print width xxxxxxxxxxxxxxxxxx", + "start": 127, + "end": 208 + } + ] + }, + "consequent": { + "type": "Literal", + "start": 214, + "end": 218, + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": null, + "raw": "null" + }, + "alternate": { + "type": "CallExpression", + "start": 224, + "end": 233, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "callee": { + "type": "Identifier", + "start": 224, + "end": 226, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "name": "fn" + }, + "arguments": [ + { + "type": "Identifier", + "start": 227, + "end": 232, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "name": "value" + } + ], + "optional": false + } + } + } + ], + "kind": "const", + "leadingComments": [ + { + "type": "Line", + "value": " Trailing line comment on test - binary test fits, comment pushes line over 100 chars", + "start": 10, + "end": 97 + } + ] + } + ], + "sourceType": "module" + }, + "attributes": [] + } +} diff --git a/tests/fixtures/typescript/expressions/ternary/test_trailing_long_comment/input.svelte b/tests/fixtures/typescript/expressions/ternary/test_trailing_long_comment/input.svelte new file mode 100644 index 00000000..9b8a60cf --- /dev/null +++ b/tests/fixtures/typescript/expressions/ternary/test_trailing_long_comment/input.svelte @@ -0,0 +1,7 @@ + diff --git a/tests/fixtures/typescript/statements/switch/case_test_trailing_long_comment/expected.json b/tests/fixtures/typescript/statements/switch/case_test_trailing_long_comment/expected.json new file mode 100644 index 00000000..ecfc4548 --- /dev/null +++ b/tests/fixtures/typescript/statements/switch/case_test_trailing_long_comment/expected.json @@ -0,0 +1,304 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 187, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " comment that pushes the case label line over the print width", + "start": 95, + "end": 158, + "loc": { + "start": { + "line": 4, + "column": 35 + }, + "end": { + "line": 4, + "column": 98 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 186, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 177, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "body": [ + { + "type": "FunctionDeclaration", + "start": 20, + "end": 176, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "name": "fn" + }, + "expression": false, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 32, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "name": "x", + "typeAnnotation": { + "type": "TSTypeAnnotation", + "start": 33, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "typeAnnotation": { + "type": "TSNumberKeyword", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 43, + "end": 176, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "body": [ + { + "type": "SwitchStatement", + "start": 47, + "end": 173, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "discriminant": { + "type": "Identifier", + "start": 55, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "x" + }, + "cases": [ + { + "type": "SwitchCase", + "start": 63, + "end": 169, + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "consequent": [ + { + "type": "BreakStatement", + "start": 163, + "end": 169, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "label": null, + "leadingComments": [ + { + "type": "Line", + "value": " comment that pushes the case label line over the print width", + "start": 95, + "end": 158 + } + ] + } + ], + "test": { + "type": "BinaryExpression", + "start": 68, + "end": 93, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "left": { + "type": "Identifier", + "start": 68, + "end": 78, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "name": "aaaaaaaaaa" + }, + "operator": "===", + "right": { + "type": "Identifier", + "start": 83, + "end": 93, + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 33 + } + }, + "name": "bbbbbbbbbb" + } + } + } + ] + } + ] + } + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/statements/switch/case_test_trailing_long_comment/input.svelte b/tests/fixtures/typescript/statements/switch/case_test_trailing_long_comment/input.svelte new file mode 100644 index 00000000..8cc8b09e --- /dev/null +++ b/tests/fixtures/typescript/statements/switch/case_test_trailing_long_comment/input.svelte @@ -0,0 +1,8 @@ + diff --git a/tests/fixtures/typescript/types/tuple/element_trailing_long_comment/expected.json b/tests/fixtures/typescript/types/tuple/element_trailing_long_comment/expected.json new file mode 100644 index 00000000..2f489618 --- /dev/null +++ b/tests/fixtures/typescript/types/tuple/element_trailing_long_comment/expected.json @@ -0,0 +1,311 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 153, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " comment pushing the tuple element over the print widthx", + "start": 72, + "end": 130, + "loc": { + "start": { + "line": 3, + "column": 41 + }, + "end": { + "line": 3, + "column": 99 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 152, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 143, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start": 20, + "end": 142, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "id": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "name": "T" + }, + "typeAnnotation": { + "type": "TSTupleType", + "start": 29, + "end": 141, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "elementTypes": [ + { + "type": "TSConditionalType", + "start": 33, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "checkType": { + "type": "TSTypeReference", + "start": 33, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "typeName": { + "type": "Identifier", + "start": 33, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "name": "aaaaaaaaaa" + } + }, + "extendsType": { + "type": "TSTypeReference", + "start": 52, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "typeName": { + "type": "Identifier", + "start": 52, + "end": 62, + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "name": "bbbbbbbbbb" + } + }, + "trueType": { + "type": "TSLiteralType", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "literal": { + "type": "Literal", + "start": 65, + "end": 66, + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 35 + } + }, + "value": 1, + "raw": "1" + } + }, + "falseType": { + "type": "TSLiteralType", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 38 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "literal": { + "type": "Literal", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 3, + "column": 38 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "value": 2, + "raw": "2" + } + }, + "trailingComments": [ + { + "type": "Line", + "value": " comment pushing the tuple element over the print widthx", + "start": 72, + "end": 130 + } + ] + }, + { + "type": "TSTypeReference", + "start": 133, + "end": 137, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "typeName": { + "type": "Identifier", + "start": 133, + "end": 137, + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "name": "cccc" + } + } + ] + } + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/types/tuple/element_trailing_long_comment/input.svelte b/tests/fixtures/typescript/types/tuple/element_trailing_long_comment/input.svelte new file mode 100644 index 00000000..321127bd --- /dev/null +++ b/tests/fixtures/typescript/types/tuple/element_trailing_long_comment/input.svelte @@ -0,0 +1,6 @@ + diff --git a/tests/fixtures/typescript/types/union_member_trailing_long_comment/expected.json b/tests/fixtures/typescript/types/union_member_trailing_long_comment/expected.json new file mode 100644 index 00000000..2c5b877e --- /dev/null +++ b/tests/fixtures/typescript/types/union_member_trailing_long_comment/expected.json @@ -0,0 +1,264 @@ +{ + "css": null, + "js": [], + "start": 0, + "end": 149, + "type": "Root", + "fragment": { + "type": "Fragment", + "nodes": [] + }, + "options": null, + "comments": [ + { + "type": "Line", + "value": " comment that pushes the union member line over the print width xxx", + "start": 59, + "end": 128, + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 99 + } + } + } + ], + "instance": { + "type": "Script", + "start": 0, + "end": 148, + "context": "default", + "content": { + "type": "Program", + "start": 18, + "end": 139, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start": 20, + "end": 138, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "id": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "name": "T" + }, + "typeAnnotation": { + "type": "TSUnionType", + "start": 31, + "end": 137, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "types": [ + { + "type": "TSParenthesizedType", + "start": 33, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "typeAnnotation": { + "type": "TSIntersectionType", + "start": 34, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "types": [ + { + "type": "TSTypeReference", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "typeName": { + "type": "Identifier", + "start": 34, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "name": "aaaaaaaaaa" + } + }, + { + "type": "TSTypeReference", + "start": 47, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "typeName": { + "type": "Identifier", + "start": 47, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 28 + } + }, + "name": "bbbbbbbbbb" + } + } + ], + "trailingComments": [ + { + "type": "Line", + "value": " comment that pushes the union member line over the print width xxx", + "start": 59, + "end": 128 + } + ] + } + }, + { + "type": "TSTypeReference", + "start": 133, + "end": 137, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "typeName": { + "type": "Identifier", + "start": 133, + "end": 137, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "name": "cccc" + } + } + ] + } + } + ], + "sourceType": "module" + }, + "attributes": [ + { + "type": "Attribute", + "start": 8, + "end": 17, + "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, + "value": [ + { + "start": 14, + "end": 16, + "type": "Text", + "raw": "ts", + "data": "ts" + } + ] + } + ] + } +} diff --git a/tests/fixtures/typescript/types/union_member_trailing_long_comment/input.svelte b/tests/fixtures/typescript/types/union_member_trailing_long_comment/input.svelte new file mode 100644 index 00000000..06ac6687 --- /dev/null +++ b/tests/fixtures/typescript/types/union_member_trailing_long_comment/input.svelte @@ -0,0 +1,5 @@ +