File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11---
22threshold : 13
3- total_score : 666
3+ total_score : 670
Original file line number Diff line number Diff line change @@ -161,27 +161,36 @@ class FlattenImplicitDSTR < self
161161 # No need to register :dsym, because Ruby doesn't do implicit concatenation of symbols
162162 register :dstr
163163
164+ FLATTEN_CHILDREN = IceNine . deep_freeze ( [ :dstr , :str ] )
165+
164166 # Return preprocessor result
165167 #
166168 # @return [Parser::AST::Node]
167169 #
168170 # @api private
169171 #
170172 def result
171- # This should only ever be true for DSTR nodes that are a result of implicit concatenation
172- # (see the comments on this class). Any other DSTR node would have a :begin node as a child.
173- if children . any? && children . all? { |child | [ :dstr , :str ] . include? ( child . type ) }
174- flat_children = children . flat_map do |child |
175- if child . type . equal? ( :str )
176- child
177- else # child.type is dstr
178- child . children
179- end
180- end
181- node . updated ( nil , flat_children )
182- else
183- node
173+ return node unless implicit_dstr?
174+
175+ flat_children = children . flat_map do |child |
176+ child . type . equal? ( :dstr ) ? child . children : child
184177 end
178+ node . updated ( nil , flat_children )
179+ end
180+
181+ private
182+
183+ # Test for implicit dstr
184+ #
185+ # This should only ever be true for dstr nodes that are a result of implicit concatenation
186+ # (see the comments on this class). Any other dstr node would have a :begin node as a child.
187+ #
188+ # @return [Boolean]
189+ #
190+ # @api private
191+ #
192+ def implicit_dstr?
193+ children . map ( &:type ) . all? ( &FLATTEN_CHILDREN . method ( :include? ) )
185194 end
186195
187196 end # FlattenImplicitDSTR
You can’t perform that action at this time.
0 commit comments