Skip to content

Commit 9e06a98

Browse files
committed
fix: should keep multi-line comments above question token in conditional expr in same place
Closes #272
1 parent 20c1377 commit 9e06a98

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dprint-plugin-typescript"
3-
version = "0.51.0"
3+
version = "0.52.0"
44
authors = ["David Sherret <[email protected]>"]
55
edition = "2018"
66
homepage = "https://github.com/dprint/dprint-plugin-typescript"

src/parsing/parser.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,17 @@ fn parse_conditional_expr<'a>(node: &'a CondExpr, context: &mut Context<'a>) ->
17951795

17961796
let cons_and_alt_items = {
17971797
let mut items = PrintItems::new();
1798+
1799+
// add any preceeding comments of the question token
1800+
items.extend({
1801+
let operator_token_leading_comments = get_leading_comments_on_previous_lines(operator_token, context);
1802+
let mut items = parse_comment_collection(operator_token_leading_comments.into_iter(), None, None, context);
1803+
if !items.is_empty() {
1804+
items.push_signal(Signal::NewLine);
1805+
}
1806+
items
1807+
});
1808+
17981809
if operator_position == OperatorPosition::NextLine {
17991810
items.push_str("? ");
18001811
}

tests/specs/expressions/ConditionalExpression/ConditionalExpression_OperatorPosition_SameLine.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ test ?
2828
test :
2929
// comment
3030
test;
31+
32+
== should handle moving comments before the question token to now be after ==
33+
test
34+
// testing
35+
? test
36+
: test;
37+
38+
[expect]
39+
test ?
40+
// testing
41+
test :
42+
test;

tests/specs/issues/issue0272.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
== should keep multi-line comments in conditional expr above question token ==
2+
generateScopedName = hashCssNames
3+
// multiline
4+
// comment
5+
? (name, filepath) => getLocalIdent(filepath, name)
6+
: cssModulesOpts.modules.localIdentName;
7+
generateScopedName = hashCssNames
8+
// multiline
9+
/* block comment */
10+
? (name, filepath) => getLocalIdent(filepath, name)
11+
: cssModulesOpts.modules.localIdentName;
12+
generateScopedName = hashCssNames
13+
14+
// multiline
15+
// comment
16+
17+
18+
? (name, filepath) => getLocalIdent(filepath, name)
19+
: cssModulesOpts.modules.localIdentName;
20+
21+
[expect]
22+
generateScopedName = hashCssNames
23+
// multiline
24+
// comment
25+
? (name, filepath) => getLocalIdent(filepath, name)
26+
: cssModulesOpts.modules.localIdentName;
27+
generateScopedName = hashCssNames
28+
// multiline
29+
/* block comment */
30+
? (name, filepath) => getLocalIdent(filepath, name)
31+
: cssModulesOpts.modules.localIdentName;
32+
generateScopedName = hashCssNames
33+
// multiline
34+
// comment
35+
? (name, filepath) => getLocalIdent(filepath, name)
36+
: cssModulesOpts.modules.localIdentName;

0 commit comments

Comments
 (0)