@@ -244,7 +244,7 @@ def prefix
244244 end
245245
246246 def splat?
247- @arguments . any? { |a | a . is_a? ( ArgSplatNode ) }
247+ @arguments . any? { |a | a . is_a? ( SplatNode ) }
248248 end
249249
250250 def <<( argument )
@@ -274,7 +274,7 @@ def compile_splat(o)
274274 obj = @variable . source || 'this'
275275 args = @arguments . map do |arg |
276276 code = arg . compile ( o )
277- code = arg . is_a? ( ArgSplatNode ) ? code : "[#{ code } ]"
277+ code = arg . is_a? ( SplatNode ) ? code : "[#{ code } ]"
278278 arg . equal? ( @arguments . first ) ? code : ".concat(#{ code } )"
279279 end
280280 "#{ prefix } #{ meth } .apply(#{ obj } , #{ args . join ( '' ) } )"
@@ -562,7 +562,7 @@ def compile_node(o)
562562 o . delete ( :no_wrap )
563563 o . delete ( :globals )
564564 name = o . delete ( :immediate_assign )
565- if @params . last . is_a? ( ParamSplatNode )
565+ if @params . last . is_a? ( SplatNode )
566566 splat = @params . pop
567567 splat . index = @params . length
568568 @body . unshift ( splat )
@@ -574,8 +574,9 @@ def compile_node(o)
574574 end
575575 end
576576
577- # A parameter splat in a function definition.
578- class ParamSplatNode < Node
577+ # A splat, either as a parameter to a function, an argument to a call,
578+ # or in a destructuring assignment.
579+ class SplatNode < Node
579580 attr_accessor :index
580581 attr_reader :name
581582
@@ -584,20 +585,16 @@ def initialize(name)
584585 end
585586
586587 def compile_node ( o = { } )
587- o [ :scope ] . find ( @name )
588- write ( "#{ @name } = Array.prototype.slice.call(arguments, #{ @index } )" )
588+ write ( @index ? compile_param ( o ) : compile_arg ( o ) )
589589 end
590- end
591-
592- class ArgSplatNode < Node
593- attr_reader :value
594590
595- def initialize ( value )
596- @value = value
591+ def compile_param ( o )
592+ o [ :scope ] . find ( @name )
593+ "#{ @name } = Array.prototype.slice.call(arguments, #{ @index } )"
597594 end
598595
599- def compile_node ( o = { } )
600- write ( @value . compile ( o ) )
596+ def compile_arg ( o )
597+ @name . compile ( o )
601598 end
602599
603600 end
0 commit comments