From 8980647f329a77722583348e8980c97fd47edbc6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 6 Feb 2014 09:07:43 -0500 Subject: [PATCH] Add tests for the optimization of trailing return statements This documents current behavior. When #1038 was fixed, we also optimized away trailing "undefined" and "return undefined", but that is no longer the case. --- test/functions.coffee | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/functions.coffee b/test/functions.coffee index 7349428e..931d79a8 100644 --- a/test/functions.coffee +++ b/test/functions.coffee @@ -240,3 +240,16 @@ test "#1435 Indented property access", -> rec.rec() .rec() 1 + +test "#1038 Optimize trailing return statements", -> + compile = (code) -> CoffeeScript.compile(code, bare: yes).trim().replace(/\s+/g, " ") + + eq "(function() {});", compile("->") + eq "(function() {});", compile("-> return") + eq "(function() { return void 0; });", compile("-> undefined") + eq "(function() { return void 0; });", compile("-> return undefined") + eq "(function() { foo(); });", compile(""" + -> + foo() + return + """)