From 474c372b17cd6ebd5eb6c26ef7f6cb5769c881bf Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 16 Aug 2010 21:19:34 -0400 Subject: [PATCH] Fixes Issue #618. Close implicit arguments in the middle of param lists. --- lib/rewriter.js | 7 +++++-- src/rewriter.coffee | 3 ++- test/test_literals.coffee | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/rewriter.js b/lib/rewriter.js index 62219d54..f6ec0326 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -160,7 +160,7 @@ tok.generated = true; this.tokens.splice(idx, 0, tok); condition = function(token, i) { - var _c, _d, _e, one, three, two; + var _c, _d, _e, _f, one, three, two; _c = this.tokens.slice(i + 1, i + 4); one = _c[0]; two = _c[1]; @@ -168,7 +168,10 @@ if ((this.tag(i + 1) === 'HERECOMMENT' || this.tag(i - 1) === 'HERECOMMENT')) { return false; } - return ((('TERMINATOR' === (_d = token[0]) || 'OUTDENT' === _d)) && !((two && two[0] === ':') || (one && one[0] === '@' && three && three[0] === ':'))) || (token[0] === ',' && one && (!('IDENTIFIER' === (_e = one[0]) || 'STRING' === _e || '@' === _e || 'TERMINATOR' === _e || 'OUTDENT' === _e))); + if (token[0] === ',' && one && (('TERMINATOR' === (_d = one[0]) || 'OUTDENT' === _d))) { + return false; + } + return ((('TERMINATOR' === (_e = token[0]) || 'OUTDENT' === _e || ',' === _e)) && !((two && two[0] === ':') || (one && one[0] === '@' && three && three[0] === ':'))) || (token[0] === ',' && one && (!('IDENTIFIER' === (_f = one[0]) || 'STRING' === _f || '@' === _f || 'TERMINATOR' === _f || 'OUTDENT' === _f))); }; action = function(token, i) { return this.tokens.splice(i, 0, ['}', '}', token[2]]); diff --git a/src/rewriter.coffee b/src/rewriter.coffee index a642ae2e..23979889 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -140,7 +140,8 @@ exports.Rewriter = class Rewriter condition = (token, i) -> [one, two, three] = @tokens.slice(i + 1, i + 4) return false if 'HERECOMMENT' in [@tag(i + 1), @tag(i - 1)] - ((token[0] in ['TERMINATOR', 'OUTDENT']) and not ((two and two[0] is ':') or (one and one[0] is '@' and three and three[0] is ':'))) or + return false if token[0] is ',' and one and (one[0] in ['TERMINATOR', 'OUTDENT']) + ((token[0] in ['TERMINATOR', 'OUTDENT', ',']) and not ((two and two[0] is ':') or (one and one[0] is '@' and three and three[0] is ':'))) or (token[0] is ',' and one and (one[0] not in ['IDENTIFIER', 'STRING', '@', 'TERMINATOR', 'OUTDENT'])) action = (token, i) -> @tokens.splice i, 0, ['}', '}', token[2]] diff --git a/test/test_literals.coffee b/test/test_literals.coffee index 2daad9a6..9bc82071 100644 --- a/test/test_literals.coffee +++ b/test/test_literals.coffee @@ -152,6 +152,13 @@ ok obj.a is 1 ok obj.b is 2 +# Implicit objects may close in the middle of argument lists. +result = null +func = (one, two) -> result = two +func a: 1, b: 2, 3, 4 +ok result is 3 + + # Implicit objects nesting. obj = options: