Sha256: 5e024f97a276d48d877aa7f193c37f92989e84a7cb3e25faaee904e9c9c0379f
Contents?: true
Size: 1.5 KB
Versions: 7
Compression:
Stored size: 1.5 KB
Contents
# frozen_string_literal: true require 'opal/nodes/base' module Opal module Nodes # def args list class InlineArgs < Base handle :inline_args def compile push(arg_names.join(', ')) end def arg_names done_kwargs = false children.inject([]) do |result, arg| case arg.type when :kwarg, :kwoptarg, :kwrestarg unless done_kwargs done_kwargs = true result << '$kwargs' end add_arg(arg) when :mlhs tmp = scope.next_temp result << tmp scope.mlhs_mapping[arg] = tmp when :arg, :optarg arg_name, _ = *arg if !arg.meta[:inline] && arg_name[0] != '$' arg_name = "$#{arg_name}" end result << arg_name add_arg(arg) when :restarg # To make function.length working # in cases like def m(*rest) tmp_arg_name = scope.next_temp + "_rest" result << tmp_arg_name add_arg(arg) else raise "Unknown argument type #{arg.inspect}" end result end end # If the argument has a name, # we should mark it as an argument for current scope # Otherwise, these args will be interpreted # in the child scope as local variables def add_arg(arg) arg_name, _ = *arg scope.add_arg(arg_name) if arg_name end end end end
Version data entries
7 entries across 7 versions & 1 rubygems