1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

fixing chained single-line if-elses with a smarter rewriter.

This commit is contained in:
Jeremy Ashkenas 2010-01-25 20:52:33 -05:00
parent 2875de5e73
commit 91e703052c
2 changed files with 11 additions and 3 deletions

View file

@ -127,6 +127,7 @@ module CoffeeScript
scan_tokens do |prev, token, post, i|
next 1 unless SINGLE_LINERS.include?(token[0]) && post[0] != :INDENT &&
!(token[0] == :ELSE && post[0] == :IF) # Elsifs shouldn't get blocks.
starter = token[0]
line = token[1].line
@tokens.insert(i + 1, [:INDENT, Value.new(2, line)])
idx = i + 1
@ -134,8 +135,9 @@ module CoffeeScript
loop do
idx += 1
tok = @tokens[idx]
if !tok || SINGLE_CLOSERS.include?(tok[0]) ||
(tok[0] == ')' && parens == 0)
if (!tok || SINGLE_CLOSERS.include?(tok[0]) ||
(tok[0] == ')' && parens == 0)) &&
!(starter == :ELSE && tok[0] == :ELSE)
@tokens.insert(idx, [:OUTDENT, Value.new(2, line)])
break
end