diff --git a/lib/rewriter.js b/lib/rewriter.js index 18c19014..154371ce 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -177,6 +177,9 @@ if (tag === 'INDENT' && prev && include(IMPLICIT_BLOCK, prev[0])) { return 1; } + if (tag === 'OUTDENT' && token.generated) { + return 1; + } if (open || tag === 'INDENT') { idx = tag === 'OUTDENT' ? i + 1 : i; stack_pointer = tag === 'INDENT' ? 2 : 1; @@ -209,7 +212,7 @@ Rewriter.prototype.add_implicit_indentation = function add_implicit_indentation() { return this.scan_tokens((function(__this) { var __func = function(prev, token, post, i) { - var idx, insertion, parens, pre, starter, tok; + var idx, insertion, outdent, parens, pre, starter, tok; if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) { return 1; } @@ -223,7 +226,9 @@ pre = this.tokens[idx - 1]; if ((!tok || (include(SINGLE_CLOSERS, tok[0]) && tok[1] !== ';') || (tok[0] === ')' && parens === 0)) && !(starter === 'ELSE' && tok[0] === 'ELSE')) { insertion = pre[0] === "," ? idx - 1 : idx; - this.tokens.splice(insertion, 0, ['OUTDENT', 2, token[2]]); + outdent = ['OUTDENT', 2, token[2]]; + outdent.generated = true; + this.tokens.splice(insertion, 0, outdent); break; } if (tok[0] === '(') { diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 461546a6..8df2b323 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -126,6 +126,7 @@ exports.Rewriter: class Rewriter return 2 if !post? or include IMPLICIT_END, tag return 1 if tag is 'INDENT' and prev and include IMPLICIT_BLOCK, prev[0] + return 1 if tag is 'OUTDENT' and token.generated if open or tag is 'INDENT' idx: if tag is 'OUTDENT' then i + 1 else i stack_pointer: if tag is 'INDENT' then 2 else 1 @@ -162,7 +163,9 @@ exports.Rewriter: class Rewriter (tok[0] is ')' && parens is 0)) and not (starter is 'ELSE' and tok[0] is 'ELSE') insertion: if pre[0] is "," then idx - 1 else idx - @tokens.splice(insertion, 0, ['OUTDENT', 2, token[2]]) + outdent: ['OUTDENT', 2, token[2]] + outdent.generated: true + @tokens.splice(insertion, 0, outdent) break parens: + 1 if tok[0] is '(' parens: - 1 if tok[0] is ')' diff --git a/test/test_functions.coffee b/test/test_functions.coffee index caaf3785..fdabb47c 100644 --- a/test/test_functions.coffee +++ b/test/test_functions.coffee @@ -120,4 +120,11 @@ mult: (x, mids..., y) -> ok mult(1, 2,) is 2 ok mult(1, 2, 3,) is 6 -ok mult(10,[1..6]...,) is 7200 \ No newline at end of file +ok mult(10,[1..6]...,) is 7200 + + +# Test for inline functions with parentheses and implicit calls. +combine: (func, num) -> func() * num +result: combine (-> 1 + 2), 3 + +ok result is 9