fixing chained single-line if-elses with a smarter rewriter.
This commit is contained in:
parent
2875de5e73
commit
91e703052c
|
@ -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
|
||||
|
|
|
@ -7,4 +7,10 @@ result: if a
|
|||
if d
|
||||
true
|
||||
|
||||
print result
|
||||
print result
|
||||
|
||||
|
||||
first: if false then false else second: if false then false else true
|
||||
|
||||
print first
|
||||
print second
|
Loading…
Reference in New Issue