From cb1815885ca63d4e8025a0c67df4bbc919c17f0b Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 3 Jan 2010 18:58:34 -0500 Subject: [PATCH] adding a statement-as-expression test, and returning null from while loops, if asked --- lib/coffee_script/nodes.rb | 5 +++-- .../generation/statements_as_expressions.coffee | 11 +++++++++++ test/unit/test_execution.rb | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/generation/statements_as_expressions.coffee diff --git a/lib/coffee_script/nodes.rb b/lib/coffee_script/nodes.rb index 9f75ea46..c4a4fda3 100644 --- a/lib/coffee_script/nodes.rb +++ b/lib/coffee_script/nodes.rb @@ -575,12 +575,13 @@ module CoffeeScript end def compile_node(o) - o.delete(:return) + returns = o.delete(:return) indent = o[:indent] o[:indent] += TAB o[:top] = true cond = @condition.compile(o) - write("#{indent}while (#{cond}) {\n#{@body.compile(o)}\n#{indent}}") + post = returns ? "\n#{indent}return null;" : '' + write("#{indent}while (#{cond}) {\n#{@body.compile(o)}\n#{indent}}#{post}") end end diff --git a/test/fixtures/generation/statements_as_expressions.coffee b/test/fixtures/generation/statements_as_expressions.coffee new file mode 100644 index 00000000..5bfb9f43 --- /dev/null +++ b/test/fixtures/generation/statements_as_expressions.coffee @@ -0,0 +1,11 @@ +# Everything should be able to be an expression. + +result: while sunny? + go_outside() + +print(3 + try + nonexistent.no_way + catch error + print(error) + 3 +) \ No newline at end of file diff --git a/test/unit/test_execution.rb b/test/unit/test_execution.rb index 04186305..1a72f994 100644 --- a/test/unit/test_execution.rb +++ b/test/unit/test_execution.rb @@ -14,8 +14,8 @@ class ExecutionTest < Test::Unit::TestCase end end - def test_lintless_coffeescript - no_warnings `bin/coffee -l test/fixtures/execution/*.coffee` + def test_lintless_tests + no_warnings `bin/coffee -l test/fixtures/*/*.coffee` end def test_lintless_examples