Skip to content

Commit ae753e4

Browse files
authored
fix: do not remove parens in var decl init when paren expr is assignment (#465)
1 parent e9d7bef commit ae753e4

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tracing = ["dprint-core/tracing"]
2626

2727
[dependencies]
2828
anyhow = "1.0.64"
29-
deno_ast = { version = "0.23.1", features = ["view"] }
29+
deno_ast = { version = "0.23.2", features = ["view"] }
3030
dprint-core = { version = "0.60.0", features = ["formatting"] }
3131
rustc-hash = "1.1.0"
3232
serde = { version = "1.0.144", features = ["derive"] }

src/generation/generate.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,9 +2735,11 @@ fn should_skip_paren_expr(node: &ParenExpr, context: &Context) -> bool {
27352735
}
27362736

27372737
if let Node::VarDeclarator(var_decl) = parent {
2738-
if let Some(init) = var_decl.init {
2739-
if init.range().contains(&node.range()) {
2740-
return true;
2738+
if node.expr.kind() != NodeKind::AssignExpr {
2739+
if let Some(init) = var_decl.init {
2740+
if init.range().contains(&node.range()) {
2741+
return true;
2742+
}
27412743
}
27422744
}
27432745
}

src/swc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ mod tests {
115115
"./test.ts",
116116
"+value.",
117117
concat!(
118+
// comment to keep this multi-line
118119
"Unexpected eof at ./test.ts:1:8\n\n",
119120
" +value.\n",
120-
// this excess whitespace is a bug, but not a big deal
121-
" "
121+
" ~"
122122
),
123123
);
124124
}

tests/specs/expressions/ParenExpr/ParenExpr_All.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const c = (1 + 1) + 1;
3333
const d = 1 + (1 + 1);
3434
// except here it should because of the type assertion
3535
const e = /** @type {number} */ (((1)));
36+
// keep this too as some people like it for clarity
37+
const a = (b = 5);
3638

3739
[expect]
3840
const a = 1;
@@ -41,6 +43,8 @@ const c = (1 + 1) + 1;
4143
const d = 1 + (1 + 1);
4244
// except here it should because of the type assertion
4345
const e = /** @type {number} */ (1);
46+
// keep this too as some people like it for clarity
47+
const a = (b = 5);
4448

4549
== should ignore paren exprs within paren exprs ==
4650
(((test)));

0 commit comments

Comments
 (0)