<commit_before># frozen_string_literal: true

require 'opal/rewriters/base'

module Opal
  module Rewriters
    class ReturnableLogic < Base
      def next_tmp
        @counter ||= 0
        @counter += 1
        "$ret_or_#{@counter}"
      end

      def reset_tmp_counter!
        @counter = nil
      end

      def on_or(node)
        lhs, rhs = *node.children
        lhs_tmp = next_tmp

        node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), s(:js_tmp, lhs_tmp), process(rhs)])
      end

      def on_and(node)
        lhs, rhs = *node.children
        lhs_tmp = next_tmp

        node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), process(rhs), s(:js_tmp, lhs_tmp)])
      end
    end
  end
end
<commit_msg>Reuse the ret_or_* variables<commit_after># frozen_string_literal: true

require 'opal/rewriters/base'

module Opal
  module Rewriters
    class ReturnableLogic < Base
      def next_tmp
        @counter ||= 0
        @counter += 1
        "$ret_or_#{@counter}"
      end

      def free_tmp
        @counter -= 1
      end

      def reset_tmp_counter!
        @counter = nil
      end

      def on_or(node)
        lhs, rhs = *node.children
        lhs_tmp = next_tmp

        out = node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), s(:js_tmp, lhs_tmp), process(rhs)])
        free_tmp
        out
      end

      def on_and(node)
        lhs, rhs = *node.children
        lhs_tmp = next_tmp

        out = node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), process(rhs), s(:js_tmp, lhs_tmp)])
        free_tmp
        out
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11090107120352867, 'fraction_numerical': 0.00315059861373661, 'mean_word_length': 2.1137254901960785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7644637', 'n_tokens_mistral': 575, 'n_tokens_neox': 562, 'n_words': 130}