Skip to content

Commit d387979

Browse files
committed
fix: #15 - Implement KeyValuePatProp.
Whoops... missed this node.
1 parent b24c31b commit d387979

File tree

3 files changed

+71
-20
lines changed

3 files changed

+71
-20
lines changed

src/parsing/parser.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
216216
Node::ArrayPat(node) => parse_array_pat(node, context),
217217
Node::AssignPat(node) => parse_assign_pat(node, context),
218218
Node::AssignPatProp(node) => parse_assign_pat_prop(node, context),
219+
Node::KeyValuePatProp(node) => parse_key_value_pat_prop(node, context),
219220
Node::RestPat(node) => parse_rest_pat(node, context),
220221
Node::ObjectPat(node) => parse_object_pat(node, context),
221222
/* properties */
@@ -1863,7 +1864,7 @@ fn parse_key_value_prop<'a>(node: &'a KeyValueProp, context: &mut Context<'a>) -
18631864
let mut items = PrintItems::new();
18641865
items.extend(parse_node((&node.key).into(), context));
18651866
items.extend(parse_assignment((&node.value).into(), ":", context));
1866-
return items;
1867+
items
18671868
}
18681869

18691870
fn parse_member_expr<'a>(node: &'a MemberExpr, context: &mut Context<'a>) -> PrintItems {
@@ -2724,23 +2725,26 @@ fn parse_array_pat<'a>(node: &'a ArrayPat, context: &mut Context<'a>) -> PrintIt
27242725
}
27252726

27262727
fn parse_assign_pat<'a>(node: &'a AssignPat, context: &mut Context<'a>) -> PrintItems {
2727-
parser_helpers::new_line_group({
2728-
let mut items = PrintItems::new();
2729-
items.extend(parse_node((&node.left).into(), context));
2730-
items.extend(parse_assignment((&node.right).into(), "=", context));
2731-
items
2732-
})
2728+
let mut items = PrintItems::new();
2729+
items.extend(parse_node((&node.left).into(), context));
2730+
items.extend(parse_assignment((&node.right).into(), "=", context));
2731+
items
27332732
}
27342733

27352734
fn parse_assign_pat_prop<'a>(node: &'a AssignPatProp, context: &mut Context<'a>) -> PrintItems {
2736-
parser_helpers::new_line_group({
2737-
let mut items = PrintItems::new();
2738-
items.extend(parse_node((&node.key).into(), context));
2739-
if let Some(value) = &node.value {
2740-
items.extend(parse_assignment(value.into(), "=", context));
2741-
}
2742-
items
2743-
})
2735+
let mut items = PrintItems::new();
2736+
items.extend(parse_node((&node.key).into(), context));
2737+
if let Some(value) = &node.value {
2738+
items.extend(parse_assignment(value.into(), "=", context));
2739+
}
2740+
items
2741+
}
2742+
2743+
fn parse_key_value_pat_prop<'a>(node: &'a KeyValuePatProp, context: &mut Context<'a>) -> PrintItems {
2744+
let mut items = PrintItems::new();
2745+
items.extend(parse_node((&node.key).into(), context));
2746+
items.extend(parse_assignment((&node.value).into(), ":", context));
2747+
items
27442748
}
27452749

27462750
fn parse_rest_pat<'a>(node: &'a RestPat, context: &mut Context<'a>) -> PrintItems {
@@ -5256,9 +5260,10 @@ fn parse_object_like_node<'a>(opts: ParseObjectLikeNodeOptions<'a>, context: &mu
52565260
};
52575261

52585262
items.extend(parse_surrounded_by_tokens(|context| {
5259-
let mut items = PrintItems::new();
5260-
if !opts.members.is_empty() {
5261-
items.extend(parse_separated_values(ParseSeparatedValuesOptions {
5263+
if opts.members.is_empty() {
5264+
PrintItems::new()
5265+
} else {
5266+
parse_separated_values(ParseSeparatedValuesOptions {
52625267
nodes: opts.members.into_iter().map(|x| Some(x)).collect(),
52635268
prefer_hanging: opts.prefer_hanging,
52645269
force_use_new_lines: force_multi_line,
@@ -5270,9 +5275,8 @@ fn parse_object_like_node<'a>(opts: ParseObjectLikeNodeOptions<'a>, context: &mu
52705275
custom_single_line_separator: None,
52715276
multi_line_options: parser_helpers::MultiLineOptions::surround_newlines_indented(),
52725277
force_possible_newline_at_start: false,
5273-
}, context));
5278+
}, context)
52745279
}
5275-
items
52765280
}, |_| None, ParseSurroundedByTokensOptions {
52775281
open_token: "{",
52785282
close_token: "}",

tests/specs/issues/issue0015.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
~~ deno: true ~~
2+
== should format key value pat properties in variables ==
3+
const {
4+
errors: {
5+
NotFound
6+
},
7+
} = Deno;
8+
9+
[expect]
10+
const {
11+
errors: {
12+
NotFound,
13+
},
14+
} = Deno;
15+
16+
== should format key value pat properties in functions ==
17+
function f({
18+
options: {
19+
Test
20+
},
21+
}) {
22+
}
23+
24+
[expect]
25+
function f({
26+
options: {
27+
Test,
28+
},
29+
}) {
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
== should format on one line ==
2+
const { test: { Other = 5 }} = obj;
3+
4+
[expect]
5+
const { test: { Other = 5 } } = obj;
6+
7+
== should format on multiple lines ==
8+
const {
9+
test: {
10+
Other = 5 }} = obj;
11+
12+
[expect]
13+
const {
14+
test: {
15+
Other = 5,
16+
},
17+
} = obj;

0 commit comments

Comments
 (0)