From 31bfe50831e3e7ac621fec77be69453d9d31bb73 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 1 May 2011 10:16:04 -0400 Subject: [PATCH] Fix for #1304 ... but disallows an alternative syntax. --- lib/rewriter.js | 2 +- src/rewriter.coffee | 2 +- test/function_invocation.coffee | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/rewriter.js b/lib/rewriter.js index f4c4003b..d5fdf825 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -118,7 +118,7 @@ return false; } tag = token[0]; - return ((tag === 'TERMINATOR' || tag === 'OUTDENT') && !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':')) || (tag === ',' && one && ((_ref2 = one[0]) !== 'IDENTIFIER' && _ref2 !== 'NUMBER' && _ref2 !== 'STRING' && _ref2 !== '@' && _ref2 !== 'TERMINATOR' && _ref2 !== 'OUTDENT')); + return ((tag === 'TERMINATOR' || tag === 'OUTDENT') && !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':')) || (tag === ',' && one && ((_ref2 = one[0]) !== 'IDENTIFIER' && _ref2 !== 'NUMBER' && _ref2 !== 'STRING' && _ref2 !== '@' && _ref2 !== 'TERMINATOR' && _ref2 !== 'OUTDENT' && _ref2 !== '->' && _ref2 !== '=>')); }; action = function(token, i) { var tok; diff --git a/src/rewriter.coffee b/src/rewriter.coffee index c738e4a1..6ef87033 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -103,7 +103,7 @@ class exports.Rewriter (tag in ['TERMINATOR', 'OUTDENT'] and not (two?[0] is ':' or one?[0] is '@' and three?[0] is ':')) or (tag is ',' and one and - one[0] not in ['IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT']) + one[0] not in ['IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT', '->', '=>']) action = (token, i) -> tok = ['}', '}', token[2]] tok.generated = yes diff --git a/test/function_invocation.coffee b/test/function_invocation.coffee index ff39304a..5c7c51be 100644 --- a/test/function_invocation.coffee +++ b/test/function_invocation.coffee @@ -147,9 +147,23 @@ test "Trying an implicit object call with a trailing function.", -> a = null meth = (arg, obj, func) -> a = [obj.a, arg, func()].join ' ' - meth 'apple', b: 1, a: 13, -> + meth 'apple', {b: 1, a: 13}, -> 'orange' ok a is '13 apple orange' + + +test "Ensure that trailing calls in implicit objects can be parsed.", -> + + obj = + a: id 0, -> + 1 + b: id 0, => + 1 + + eq obj.a[0], 0 + eq obj.a[1](), 1 + eq obj.b[0], 0 + eq obj.b[1](), 1 test "Ensure that empty functions don't return mistaken values.", ->