From fdffacfb4065545136f84a55b8f10f24a8d44e51 Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Mon, 22 Feb 2010 19:17:54 -0600 Subject: [PATCH] Make trailing else on switch fix pass on to multiple when switches --- lib/nodes.js | 2 +- src/nodes.coffee | 2 +- test/test_switch.coffee | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 9374746e..fa5f8fd1 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1248,7 +1248,7 @@ // Rewrite a chain of IfNodes to add a default case as the final else. add_else: function add_else(exprs, statement) { if (this.is_chain()) { - this.else_body.add_else(exprs); + this.else_body.add_else(exprs, statement); } else { if (!(statement)) { exprs = exprs.unwrap(); diff --git a/src/nodes.coffee b/src/nodes.coffee index d47a4e9e..1d0769ed 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -987,7 +987,7 @@ IfNode: exports.IfNode: inherit Node, { # Rewrite a chain of IfNodes to add a default case as the final else. add_else: (exprs, statement) -> if @is_chain() - @else_body.add_else exprs + @else_body.add_else exprs, statement else exprs: exprs.unwrap() unless statement @children.push @else_body: exprs diff --git a/test/test_switch.coffee b/test/test_switch.coffee index 549a1ddc..97475cbc 100644 --- a/test/test_switch.coffee +++ b/test/test_switch.coffee @@ -51,3 +51,14 @@ switch "word" result: true unless false ok result + +result: false +switch "word" + when "one thing" + do_something() + when "other thing" + do_something() + else + result: true unless false + +ok result