mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fixing commented-out if-clauses or empty if-clauses.
This commit is contained in:
parent
7e2eb997a8
commit
24676eea71
3 changed files with 23 additions and 0 deletions
|
@ -170,6 +170,10 @@
|
|||
return this.scanTokens((function(__this) {
|
||||
var __func = function(prev, token, post, i) {
|
||||
var idx, indent, insertion, outdent, parens, pre, starter, tok;
|
||||
if (token[0] === 'ELSE' && prev[0] !== 'OUTDENT') {
|
||||
this.tokens.splice(i, 0, ['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]);
|
||||
return 2;
|
||||
}
|
||||
if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) {
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -134,6 +134,9 @@ exports.Rewriter: class Rewriter
|
|||
# but we need to make sure it's balanced.
|
||||
addImplicitIndentation: ->
|
||||
@scanTokens (prev, token, post, i) =>
|
||||
if token[0] is 'ELSE' and prev[0] isnt 'OUTDENT'
|
||||
@tokens.splice i, 0, ['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]
|
||||
return 2
|
||||
return 1 unless include(SINGLE_LINERS, token[0]) and
|
||||
post[0] isnt 'INDENT' and
|
||||
not (token[0] is 'ELSE' and post[0] is 'IF')
|
||||
|
|
|
@ -44,3 +44,19 @@ ok result is 'ya'
|
|||
# Testing inline funcs with inline if-elses.
|
||||
func: -> if 1 < 0.5 then 1 else -1
|
||||
ok func() is -1
|
||||
|
||||
|
||||
# Testing empty or commented if statements ... should compile:
|
||||
result: if false
|
||||
else if false
|
||||
else
|
||||
|
||||
ok result is undefined
|
||||
|
||||
result: if false
|
||||
# comment
|
||||
else if true
|
||||
# comment
|
||||
else
|
||||
|
||||
ok result is undefined
|
||||
|
|
Loading…
Add table
Reference in a new issue