Skip to content

Commit f39d2ca

Browse files
committed
Updates to make sure try works correctly
1 parent eedcd41 commit f39d2ca

File tree

8 files changed

+485
-11
lines changed

8 files changed

+485
-11
lines changed

lib/elixir_script/passes/find_used_modules.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ defmodule ElixirScript.FindUsedModules do
225225
end
226226

227227
defp walk({:try, _, [blocks]}, state) do
228+
walk(Enum, state)
229+
228230
try_block = Keyword.get(blocks, :do)
229231
rescue_block = Keyword.get(blocks, :rescue, nil)
230232
catch_block = Keyword.get(blocks, :catch, nil)
@@ -236,7 +238,8 @@ defmodule ElixirScript.FindUsedModules do
236238
if rescue_block do
237239
Enum.each(rescue_block, fn
238240
{:->, _, [ [{:in, _, [param, names]}], body]} ->
239-
walk({[], [param], [{{:., [], [Enum, :member?]}, [], [param, names]}], body}, state)
241+
Enum.each(names, &walk(&1, state))
242+
walk({[], [param], [{{:., [], [Enum, :member?]}, [], [names, param]}], body}, state)
240243
{:->, _, [ [param], body]} ->
241244
walk({[], [param], [], body}, state)
242245
end)

lib/elixir_script/passes/translate/forms/try.ex

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)

priv/testrunner/testRunner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function runTests(mod, results) {
7070
if (result) {
7171
results.success++;
7272
} else {
73-
resuls.failed++;
73+
results.failed++;
7474
}
7575
}
7676
}
@@ -80,7 +80,7 @@ function runTests(mod, results) {
8080

8181
function runTest(mod, test, incomingContext, results) {
8282
const context = runSetup(mod, '__elixirscript_test_setup', incomingContext);
83-
const testPassed = true;
83+
let testPassed = true;
8484
try {
8585
test.get(Symbol.for('test'))(context);
8686
process.stdout.write(Colors.fg.Green + '.' + Colors.Reset);
@@ -116,7 +116,7 @@ function handleError(e, test, results, mod) {
116116
}
117117

118118
function printErrorLine(value, label = null) {
119-
if (value !== Symbol.for('ex_unit_no_meaningful_value')) {
119+
if (value && value !== Symbol.for('ex_unit_no_meaningful_value')) {
120120
if (label) {
121121
console.log(Colors.fg.Cyan, `${label}:`, Colors.Reset, `${value}`);
122122
} else {

0 commit comments

Comments
 (0)