Sha256: eb0ae62536827c94f167c3a9d2a229895d257b332d7bfe2f82278fa5764a2ee6

Contents?: true

Size: 944 Bytes

Versions: 29

Compression:

Stored size: 944 Bytes

Contents

module Ruby2JS
  class Converter

    # (lvasgn :a
    #   (int 1))

    # (gvasgn :$a
    #   (int 1))

    handle :lvasgn, :gvasgn do |name, value=nil|
      begin
        if value and value.type == :lvasgn and @state == :statement
          undecls = []
          undecls << name unless @vars.include? name

          child = value
          while child and child.type == :lvasgn
            undecls << child.children[0] unless @vars.include? child.children[0]
            child = child.children[1]
          end

          unless undecls.empty?
            return parse s(:begin, 
              *undecls.map {|name| s(:lvasgn, name)}, @ast), @state
          end
        end

        var = 'var ' unless @vars.include?(name) or @state != :statement

        if value

          "#{ var }#{ name } = #{ parse value }"
        else
          "#{ var }#{ name }"
        end
      ensure
        @vars[name] = true
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ruby2js-1.15.1 lib/ruby2js/converter/vasgn.rb
ruby2js-1.15.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.14.1 lib/ruby2js/converter/vasgn.rb
ruby2js-1.14.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.13.1 lib/ruby2js/converter/vasgn.rb
ruby2js-1.13.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.12.2 lib/ruby2js/converter/vasgn.rb
ruby2js-1.12.1 lib/ruby2js/converter/vasgn.rb
ruby2js-1.12.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.11.1 lib/ruby2js/converter/vasgn.rb
ruby2js-1.11.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.10.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.9.3 lib/ruby2js/converter/vasgn.rb
ruby2js-1.9.2 lib/ruby2js/converter/vasgn.rb
ruby2js-1.9.1 lib/ruby2js/converter/vasgn.rb
ruby2js-1.9.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.8.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.7.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.6.0 lib/ruby2js/converter/vasgn.rb
ruby2js-1.5.0 lib/ruby2js/converter/vasgn.rb