Sha256: 0fb62d94f56f6712ff96e04c48f946ab144247c354d5beea1fa1f1298d3cae8d

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

require_relative 'replace_strings'

def compile_custom_function_map(input_file_contents)

    function_map_replacements = {

        "puts" => "console.log",

        "p" => "console.log",

        "print" => "process.stdout.write",

        "require" => "require",

        "alert" => "alert",

        "prompt" => "prompt"

    }

    function_map = function_map_replacements.keys

    modified_file_contents = input_file_contents.dup

    javascript_regexp = /(if |for |while |\(function\(|= function\(|((=|:)\s+\{))/

    input_file_contents.each_with_index do |line, index|

      function_map.each do |function|

        test_line = replace_strings(line)

        if test_line.include?(function+"(") or test_line.include?(function+" ") and test_line.index(javascript_regexp) == nil

          testsplit =  line.gsub("#iggggnnnore","").split(function)

          testsplit = testsplit.collect {|element| element.strip}

          testsplit[0] = " " if testsplit[0].eql?("")

          if testsplit[0][-1].eql?(" ") or testsplit[0].eql?("return")

            modified_file_contents[index] = line.gsub(function, function_map_replacements[function])

          end

        end

      end

    end

    return modified_file_contents, function_map_replacements.values

  end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nilac-0.0.4.3.9.7.1 lib/nilac/compile_custom_function_map.rb
nilac-0.0.4.3.9.7 lib/nilac/compile_custom_function_map.rb