Sha256: c76ddda98e78e5c9979578490c83c94b1190396358c5b867a85fa555c79896ca

Contents?: true

Size: 742 Bytes

Versions: 19

Compression:

Stored size: 742 Bytes

Contents

module Ruby2JS
  class Converter

    # (while
    #   (true)
    #   (...))

    handle :while do |condition, block|
      begin
        next_token, @next_token = @next_token, :continue

        # handle while loops that assign a variable
        while condition.type == :begin and condition.children.length == 1
          condition = condition.children.first
        end

        if condition.type == :lvasgn
          var = condition.children[0]
          unless @vars[var]
            put "#{es2015 ? 'let' : 'var'} #{var}#@sep" 
            @vars[var] = true
          end
        end

        put 'while ('; parse condition; puts ') {'; redoable block; sput '}'
      ensure
        @next_token = next_token
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ruby2js-5.1.1 lib/ruby2js/converter/while.rb
ruby2js-5.1.0 lib/ruby2js/converter/while.rb
ruby2js-5.0.1 lib/ruby2js/converter/while.rb
ruby2js-5.0.0 lib/ruby2js/converter/while.rb
ruby2js-4.2.2 lib/ruby2js/converter/while.rb
ruby2js-4.2.1 lib/ruby2js/converter/while.rb
ruby2js-4.2.0 lib/ruby2js/converter/while.rb
ruby2js-4.1.7 lib/ruby2js/converter/while.rb
ruby2js-4.1.6 lib/ruby2js/converter/while.rb
ruby2js-4.1.5 lib/ruby2js/converter/while.rb
ruby2js-4.1.4 lib/ruby2js/converter/while.rb
ruby2js-4.1.3 lib/ruby2js/converter/while.rb
ruby2js-4.1.2 lib/ruby2js/converter/while.rb
ruby2js-4.1.1 lib/ruby2js/converter/while.rb
ruby2js-4.1.0 lib/ruby2js/converter/while.rb
ruby2js-4.0.5 lib/ruby2js/converter/while.rb
ruby2js-4.0.4 lib/ruby2js/converter/while.rb
ruby2js-4.0.3 lib/ruby2js/converter/while.rb
ruby2js-4.0.2 lib/ruby2js/converter/while.rb