Skip to content

Commit

Permalink
Fix multi assign methods (#218)
Browse files Browse the repository at this point in the history
Fixes #196
  • Loading branch information
fables-tales authored Jul 8, 2020
1 parent eedfe21 commit ed23d03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions fixtures/small/multi_assign_method_actual.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo.bar = 1,2
1 change: 1 addition & 0 deletions fixtures/small/multi_assign_method_expected.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo.bar = 1, 2
5 changes: 3 additions & 2 deletions librubyfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,9 @@ pub fn format_assign(ps: &mut ParserState, assign: Assign) {
ps.emit_op("=".to_string());
ps.emit_space();

ps.with_formatting_context(FormattingContext::Assign, |ps| {
format_expression(ps, *right);
ps.with_formatting_context(FormattingContext::Assign, |ps| match right {
ExpressionOrMRHSNewFromArgs::Expression(e) => format_expression(ps, *e),
ExpressionOrMRHSNewFromArgs::MRHSNewFromArgs(m) => format_mrhs_new_from_args(ps, m),
});
});

Expand Down
12 changes: 11 additions & 1 deletion librubyfmt/src/ripper_tree_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,17 @@ pub enum ArgsAddBlockOrExpressionList {

def_tag!(assign_tag, "assign");
#[derive(Deserialize, Debug, Clone)]
pub struct Assign(pub assign_tag, pub Assignable, pub Box<Expression>);
pub struct Assign(
pub assign_tag,
pub Assignable,
pub ExpressionOrMRHSNewFromArgs,
);

#[derive(RipperDeserialize, Debug, Clone)]
pub enum ExpressionOrMRHSNewFromArgs {
Expression(Box<Expression>),
MRHSNewFromArgs(MRHSNewFromArgs),
}

def_tag!(massign_tag, "massign");
#[derive(Deserialize, Debug, Clone)]
Expand Down

0 comments on commit ed23d03

Please sign in to comment.