@@ -58,8 +58,24 @@ defmodule ElixirScript.Translate.Forms.Try do
5858
5959 defp process_rescue_block ( rescue_block , state ) do
6060 processed_clauses = Enum . map ( rescue_block , fn
61+ { :-> , _ , [ [ { :in , _ , [ { :_ , context , atom } , names ] } ] , body ] } ->
62+ names = Enum . map ( names , & make_exception_ast ( & 1 ) )
63+
64+ param = { :_e , context , atom }
65+ reasonCall = { { :. , [ ] , [ { :_e0 , context , atom } , :__reason ] } , [ ] , [ ] }
66+ reasonCall = { { :. , [ ] , [ reasonCall , :__struct__ ] } , [ ] , [ ] }
67+ reasonCall = { { :. , [ ] , [ reasonCall , :__MODULE__ ] } , [ ] , [ ] }
68+
69+ { ast , _ } = Clause . compile ( { [ ] , [ param ] , [ { { :. , [ ] , [ Enum , :member? ] } , [ ] , [ names , reasonCall ] } ] , body } , state )
70+ ast
6171 { :-> , _ , [ [ { :in , _ , [ param , names ] } ] , body ] } ->
62- { ast , _ } = Clause . compile ( { [ ] , [ param ] , [ { { :. , [ ] , [ Enum , :member? ] } , [ ] , [ param , names ] } ] , body } , state )
72+ names = Enum . map ( names , & make_exception_ast ( & 1 ) )
73+
74+ reasonCall = { { :. , [ ] , [ param , :__reason ] } , [ ] , [ ] }
75+ reasonCall = { { :. , [ ] , [ reasonCall , :__struct__ ] } , [ ] , [ ] }
76+ reasonCall = { { :. , [ ] , [ reasonCall , :__MODULE__ ] } , [ ] , [ ] }
77+
78+ { ast , _ } = Clause . compile ( { [ ] , [ param ] , [ { { :. , [ ] , [ Enum , :member? ] } , [ ] , [ names , reasonCall ] } ] , body } , state )
6379 ast
6480 { :-> , _ , [ [ param ] , body ] } ->
6581 { ast , _ } = Clause . compile ( { [ ] , [ param ] , [ ] , body } , state )
@@ -77,6 +93,10 @@ defmodule ElixirScript.Translate.Forms.Try do
7793
7894 end
7995
96+ defp make_exception_ast ( name ) do
97+ { { :. , [ ] , [ name , :__MODULE__ ] } , [ ] , [ ] }
98+ end
99+
80100 defp process_after_block ( after_block , state ) do
81101 translated_body = prepare_function_body ( after_block , state )
82102 translated_body = JS . block_statement ( translated_body )
0 commit comments