From 8d63d269b8f7e8904aa971babb9f796c3d0f3a81 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 24 Jan 2010 23:56:27 -0500 Subject: [PATCH] making all postfix forms close out implicit calls, as in Ruby --- lib/coffee_script/rewriter.rb | 3 ++- test/fixtures/execution/test_functions.coffee | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/coffee_script/rewriter.rb b/lib/coffee_script/rewriter.rb index 069d1fc3..a710bbec 100644 --- a/lib/coffee_script/rewriter.rb +++ b/lib/coffee_script/rewriter.rb @@ -19,6 +19,7 @@ module CoffeeScript # Tokens pairs that, in immediate succession, indicate an implicit call. IMPLICIT_FUNC = [:IDENTIFIER, :SUPER] + IMPLICIT_END = [:IF, :UNLESS, :FOR, :WHILE, "\n"] IMPLICIT_CALL = [:IDENTIFIER, :NUMBER, :STRING, :JS, :REGEX, :NEW, :PARAM, :TRY, :DELETE, :INSTANCEOF, :TYPEOF, :SWITCH, :ARGUMENTS, :TRUE, :FALSE, :YES, :NO, :ON, :OFF, '!', '!!', :NOT] @@ -153,7 +154,7 @@ module CoffeeScript def add_implicit_parentheses open = false scan_tokens do |prev, token, post, i| - if open && token[0] == "\n" + if open && IMPLICIT_END.include?(token[0]) @tokens.insert(i, [')', Value.new(')', token[1].line)]) open = false next 2 diff --git a/test/fixtures/execution/test_functions.coffee b/test/fixtures/execution/test_functions.coffee index 786d494d..bc85e206 100644 --- a/test/fixtures/execution/test_functions.coffee +++ b/test/fixtures/execution/test_functions.coffee @@ -46,3 +46,9 @@ Math: { print Math.Add(5, 5) is 10 print Math.AnonymousAdd(10, 10) is 20 print Math.FastAdd(20, 20) is 40 + + +# Parens are optional on simple function calls. +print 100 > 1 if 1 > 0 +print true unless false +print true for i in [1..3]