@@ -58,8 +58,34 @@ 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+ reason_call = { { :. , [ ] , [ { :_e0 , context , atom } , :__reason ] } , [ ] , [ ] }
66+ reason_call = { { :. , [ ] , [ reason_call , :__struct__ ] } , [ ] , [ ] }
67+ reason_call = { { :. , [ ] , [ reason_call , :__MODULE__ ] } , [ ] , [ ] }
68+
69+ { ast , _ } = Clause . compile ( {
70+ [ ] ,
71+ [ param ] ,
72+ [ { { :. , [ ] , [ Enum , :member? ] } , [ ] , [ names , reason_call ] } ] ,
73+ body } ,
74+ state )
75+ ast
6176 { :-> , _ , [ [ { :in , _ , [ param , names ] } ] , body ] } ->
62- { ast , _ } = Clause . compile ( { [ ] , [ param ] , [ { { :. , [ ] , [ Enum , :member? ] } , [ ] , [ param , names ] } ] , body } , state )
77+ names = Enum . map ( names , & make_exception_ast ( & 1 ) )
78+
79+ reason_call = { { :. , [ ] , [ param , :__reason ] } , [ ] , [ ] }
80+ reason_call = { { :. , [ ] , [ reason_call , :__struct__ ] } , [ ] , [ ] }
81+ reason_call = { { :. , [ ] , [ reason_call , :__MODULE__ ] } , [ ] , [ ] }
82+
83+ { ast , _ } = Clause . compile ( {
84+ [ ] ,
85+ [ param ] ,
86+ [ { { :. , [ ] , [ Enum , :member? ] } , [ ] , [ names , reason_call ] } ] ,
87+ body } ,
88+ state )
6389 ast
6490 { :-> , _ , [ [ param ] , body ] } ->
6591 { ast , _ } = Clause . compile ( { [ ] , [ param ] , [ ] , body } , state )
@@ -77,6 +103,10 @@ defmodule ElixirScript.Translate.Forms.Try do
77103
78104 end
79105
106+ defp make_exception_ast ( name ) do
107+ { { :. , [ ] , [ name , :__MODULE__ ] } , [ ] , [ ] }
108+ end
109+
80110 defp process_after_block ( after_block , state ) do
81111 translated_body = prepare_function_body ( after_block , state )
82112 translated_body = JS . block_statement ( translated_body )
0 commit comments