Sha256: ecd56317007c2367e7b4e059645a88073ef65c29e64900003a440dea2e46ace3

Contents?: true

Size: 739 Bytes

Versions: 36

Compression:

Stored size: 739 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 ') {'; scope block; sput '}'
      ensure
        @next_token = next_token
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ruby2js-4.0.1 lib/ruby2js/converter/while.rb
ruby2js-4.0.0 lib/ruby2js/converter/while.rb
ruby2js-3.6.1 lib/ruby2js/converter/while.rb
ruby2js-3.6.0 lib/ruby2js/converter/while.rb
ruby2js-3.5.3 lib/ruby2js/converter/while.rb
ruby2js-3.5.2 lib/ruby2js/converter/while.rb
ruby2js-3.5.1 lib/ruby2js/converter/while.rb
ruby2js-3.5.0 lib/ruby2js/converter/while.rb
ruby2js-3.4.0 lib/ruby2js/converter/while.rb
ruby2js-3.3.6 lib/ruby2js/converter/while.rb
ruby2js-3.3.5 lib/ruby2js/converter/while.rb
ruby2js-3.3.4 lib/ruby2js/converter/while.rb
ruby2js-3.3.3 lib/ruby2js/converter/while.rb
ruby2js-3.3.2 lib/ruby2js/converter/while.rb
ruby2js-3.3.1 lib/ruby2js/converter/while.rb
ruby2js-3.3.0 lib/ruby2js/converter/while.rb
ruby2js-3.2.0 lib/ruby2js/converter/while.rb
ruby2js-3.1.2 lib/ruby2js/converter/while.rb
ruby2js-3.1.1 lib/ruby2js/converter/while.rb
ruby2js-3.1.0 lib/ruby2js/converter/while.rb