From 0caa7312918ed0730335e29ee8606fcdb90a3602 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 30 Aug 2010 20:59:16 -0400 Subject: [PATCH] re-enabling the mis-dented call case. Issue #657 --- lib/rewriter.js | 6 ++++-- src/rewriter.coffee | 10 +++++++--- test/test_chaining.coffee | 25 +++++++++++++++++-------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/rewriter.js b/lib/rewriter.js index b6e7a482..86622d55 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -115,10 +115,12 @@ if (token[0] === 'CALL_START') { condition = function(token, i) { var _c; - return (')' === (_c = token[0]) || 'CALL_END' === _c); + return ((')' === (_c = token[0]) || 'CALL_END' === _c)) || (token[0] === 'OUTDENT' && this.tokens[i - 1][0] === ')'); }; action = function(token, i) { - return (token[0] = 'CALL_END'); + var idx; + idx = token[0] === 'OUTDENT' ? i - 1 : i; + return (this.tokens[idx][0] = 'CALL_END'); }; this.detectEnd(i + 1, condition, action); } diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 4f059486..f4df12c1 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -102,12 +102,16 @@ exports.Rewriter = class Rewriter return 0 # The lexer has tagged the opening parenthesis of a method call. Match it with - # its paired close. + # its paired close. We have the mis-nested outdent case included here for + # calls that close on the same line, just before their outdent. closeOpenCalls: -> @scanTokens (token, i) -> if token[0] is 'CALL_START' - condition = (token, i) -> token[0] in [')', 'CALL_END'] - action = (token, i) -> token[0] = 'CALL_END' + condition = (token, i) -> + (token[0] in [')', 'CALL_END']) or (token[0] is 'OUTDENT' and @tokens[i - 1][0] is ')') + action = (token, i) -> + idx = if token[0] is 'OUTDENT' then i - 1 else i + @tokens[idx][0] = 'CALL_END' @detectEnd i + 1, condition, action return 1 diff --git a/test/test_chaining.coffee b/test/test_chaining.coffee index 685717b4..7154a837 100644 --- a/test/test_chaining.coffee +++ b/test/test_chaining.coffee @@ -37,11 +37,20 @@ ok six is 6 # Ensure that indented array literals don't trigger whitespace rewriting. -# func = () -> -# ok arguments.length is 1 -# -# func( -# [[[[[], -# []], -# [[]]]], -# []]) +func = () -> + ok arguments.length is 1 + +func( + [[[[[], + []], + [[]]]], + []]) + +id = (x) -> x + +greeting = id( + """ + Hello + """) + +ok greeting is "Hello"