<commit_before>defmodule ElixirScript.Translator.Function do
  @moduledoc false
  alias ESTree.Tools.Builder, as: JS
  alias ElixirScript.Translator
  alias ElixirScript.Translator.Group
  alias ElixirScript.Translator.PatternMatching
  alias ElixirScript.Translator.Block

  @patterns JS.member_expression(
    JS.member_expression(
      JS.identifier("Elixir"),
      JS.identifier("Core")
    ),
    JS.identifier("Patterns")
  )

  @spec make_anonymous_function(list(), ElixirScript.Translator.LexicalScope.t, binary | atom) :: tuple()
  def make_anonymous_function(functions, env, name \\ nil)

  def make_anonymous_function(functions, env, name) do
    clauses = functions
    |> Enum.map(fn
      ({:->, _, [ [{:when, _, [params | guards]}], body ]}) ->
        process_function_body(params, body, env, name, guards)

      ({:->, _, [params, body]}) ->
        process_function_body(params, body, env, name)

      ({_, _, [{:when, _, [{_, _, params} | guards]}, body]}) ->
        body = convert_to_try(body)
        process_function_body(params, body, env, name, guards)

      ({_, _, [{_, _, params}, body]}) ->
        body = convert_to_try(body)
        process_function_body(params, body, env, name)
<commit_msg>Fix function head when there is a guard and multiple params<commit_after>defmodule ElixirScript.Translator.Function do
  @moduledoc false
  alias ESTree.Tools.Builder, as: JS
  alias ElixirScript.Translator
  alias ElixirScript.Translator.Group
  alias ElixirScript.Translator.PatternMatching
  alias ElixirScript.Translator.Block

  @patterns JS.member_expression(
    JS.member_expression(
      JS.identifier("Elixir"),
      JS.identifier("Core")
    ),
    JS.identifier("Patterns")
  )

  @spec make_anonymous_function(list(), ElixirScript.Translator.LexicalScope.t, binary | atom) :: tuple()
  def make_anonymous_function(functions, env, name \\ nil)

  def make_anonymous_function(functions, env, name) do
    clauses = functions
    |> Enum.map(fn
      ({:->, _, [ [{:when, _, params}], body ]}) ->
        guards = List.last(params) |> List.wrap
        params = params |> Enum.reverse |> tl |> Enum.reverse
        process_function_body(params, body, env, name, guards)

      ({:->, _, [params, body]}) ->
        process_function_body(params, body, env, name)

      ({_, _, [{:when, _, [{_, _, params} | guards]}, body]}) ->
        body = convert_to_try(body)
        process_function_body(params, body, env, name, guards)

      ({_, _, [{_, _, params}, body]}) ->
        body = convert_to_try(body)
        process_function_body(params, body, env, name)

{'fraction_non_alphanumeric': 0.1395617070357555, 'fraction_numerical': 0.0, 'mean_word_length': 3.5095320623916813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '6643409', 'n_tokens_mistral': 854, 'n_tokens_neox': 833, 'n_words': 169}