Skip to content

Commit

Permalink
fix: #22 - Use a queued indent on the conditional expression test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jul 6, 2020
1 parent f648e87 commit 52ee087
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1704,14 +1704,14 @@ fn parse_conditional_expr<'a>(node: &'a CondExpr, context: &mut Context<'a>) ->
items.push_info(top_most_data.top_most_info);
}

items.extend(parser_helpers::new_line_group(parse_node_with_inner_parse((&node.test).into(), context, {
items.extend(parser_helpers::new_line_group(with_queued_indent(parse_node_with_inner_parse((&node.test).into(), context, {
move |mut items, _| {
if operator_position == OperatorPosition::SameLine {
items.push_str(" ?");
}
items
}
})));
}))));

// force re-evaluation of all the conditions below once the end info has been reached
items.push_condition(conditions::force_reevaluation_once_resolved(context.end_statement_or_member_infos.peek().map(|x| x.clone()).unwrap_or(end_info)));
Expand Down
12 changes: 6 additions & 6 deletions tests/specs/issues/issue0022.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
~~ deno: true ~~
== should format as-is. This could probably be better and note that the entire assignment is the conditional expression ==
== should format with the test indented. Note the entire assignment is a conditional expr ==
const es5Bundle = test === asdf ? true : false ||
target === ts.ScriptTarget.ES2016
? true
: false

[expect]
const es5Bundle = test === asdf ? true : false ||
target === ts.ScriptTarget.ES2016
target === ts.ScriptTarget.ES2016
? true
: false;

== should format as-is ==
== should format with the test indented ==
const es5Bundle = target === ts.ScriptTarget.ES3 ||
target === ts.ScriptTarget.ES5 ||
target === ts.ScriptTarget.ES2015 ||
Expand All @@ -21,8 +21,8 @@ const es5Bundle = target === ts.ScriptTarget.ES3 ||

[expect]
const es5Bundle = target === ts.ScriptTarget.ES3 ||
target === ts.ScriptTarget.ES5 ||
target === ts.ScriptTarget.ES2015 ||
target === ts.ScriptTarget.ES2016
target === ts.ScriptTarget.ES5 ||
target === ts.ScriptTarget.ES2015 ||
target === ts.ScriptTarget.ES2016
? true
: false;

0 comments on commit 52ee087

Please sign in to comment.