File tree 1 file changed +13
-6
lines changed
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -2521,13 +2521,20 @@ def to_json(*opts)
2521
2521
# on_binary: (untyped left, (Op | Symbol) operator, untyped right) -> Binary
2522
2522
def on_binary ( left , operator , right )
2523
2523
if operator . is_a? ( Symbol )
2524
- # Here, we're going to search backward for the nearest token that matches
2525
- # the operator so we can delete it from the list.
2526
- token = find_token ( Op , operator . to_s , consume : false )
2524
+ # Here, we're going to search backward for the token that's between the
2525
+ # two operands that matches the operator so we can delete it from the
2526
+ # list.
2527
+ index =
2528
+ tokens . rindex do |token |
2529
+ location = token . location
2527
2530
2528
- if token && token . location . start_char > left . location . end_char
2529
- tokens . delete ( token )
2530
- end
2531
+ token . is_a? ( Op ) &&
2532
+ token . value == operator . to_s &&
2533
+ location . start_char > left . location . end_char &&
2534
+ location . end_char < right . location . start_char
2535
+ end
2536
+
2537
+ tokens . delete_at ( index ) if index
2531
2538
else
2532
2539
# On most Ruby implementations, operator is a Symbol that represents that
2533
2540
# operation being performed. For instance in the example `1 < 2`, the
You can’t perform that action at this time.
0 commit comments