re-enabling the mis-dented call case. Issue #657

This commit is contained in:
Jeremy Ashkenas 2010-08-30 20:59:16 -04:00
parent 704fbf499b
commit 0caa731291
3 changed files with 28 additions and 13 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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"