put the commas on the outside of expression closers

This commit is contained in:
Jeremy Ashkenas
2009-12-29 20:39:51 -05:00
parent f5aafc6591
commit fd357871f2

View File

@@ -148,7 +148,7 @@ module CoffeeScript
end end
def outdent_token(move_out) def outdent_token(move_out)
while move_out > 0 while move_out > 0 && !@indents.empty?
last_indent = @indents.pop last_indent = @indents.pop
token(:OUTDENT, last_indent) token(:OUTDENT, last_indent)
move_out -= last_indent move_out -= last_indent
@@ -276,8 +276,8 @@ module CoffeeScript
# it with the inverse of what we've just popped. # it with the inverse of what we've just popped.
# 3. Keep track of "debt" for tokens that we fake, to make sure we end # 3. Keep track of "debt" for tokens that we fake, to make sure we end
# up balanced in the end. # up balanced in the end.
# 4. Make sure that we don't accidentally break trailing commas, which # 4. Make sure that we don't accidentally break trailing commas, which need
# should be before OUTDENTS, but after parens. # to go on the outside of expression closers.
# #
def rewrite_closing_parens def rewrite_closing_parens
stack, debt = [], [] stack, debt = [], []
@@ -285,13 +285,11 @@ module CoffeeScript
stack.push(token) if [:INDENT, '('].include?(token[0]) stack.push(token) if [:INDENT, '('].include?(token[0])
if [:OUTDENT, ')'].include?(token[0]) if [:OUTDENT, ')'].include?(token[0])
reciprocal = stack.pop reciprocal = stack.pop
if reciprocal[0] == :INDENT tok = reciprocal[0] == :INDENT ? [:OUTDENT, Value.new(reciprocal[1], token[1].line)] :
@tokens[i] = [:OUTDENT, Value.new(reciprocal[1], token[1].line)] [')', Value.new(')', token[1].line)]
else index = prev[0] == ',' ? i - 1 : i
index = prev[0] == ',' ? i - 1 : i @tokens.delete_at(i)
@tokens.delete_at(i) @tokens.insert(index, tok)
@tokens.insert(index, [')', Value.new(')', token[1].line)])
end
end end
end end
end end