Sha256: b04a12e2a450744668c7d98207a62876aed7882981e8d0fbca9dcac7954b69dd
Contents?: true
Size: 1.38 KB
Versions: 7
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true require 'opal/nodes/base' module Opal module Nodes class WhileNode < Base handle :while children :test, :body def compile with_temp do |redo_var| test_code = js_truthy(test) compiler.in_while do while_loop[:closure] = true if wrap_in_closure? while_loop[:redo_var] = redo_var body_code = stmt(body) if uses_redo? push "#{redo_var} = false; #{while_open}#{redo_var} || " push test_code push while_close else push while_open, test_code, while_close end push "#{redo_var} = false;" if uses_redo? line body_code end line "}" end wrap '(function() {', '; return nil; })()' if wrap_in_closure? end def while_open "while (" end def while_close ") {" end def uses_redo? while_loop[:use_redo] end def wrap_in_closure? expr? or recv? end end class WhilePostNode < WhileNode handle :while_post end class UntilNode < WhileNode handle :until def while_open "while (!(" end def while_close ")) {" end end class UntilPostNode < UntilNode handle :until_post end end end
Version data entries
7 entries across 7 versions & 1 rubygems