mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
yet another rewriter-based comment fix, this time for issue #403
This commit is contained in:
parent
d9071a80a0
commit
4b4b0e630e
3 changed files with 13 additions and 7 deletions
|
@ -72,7 +72,7 @@
|
|||
this.tokens.splice(i + 2, 1);
|
||||
before && before[0] === 'OUTDENT' && post && (prev[0] === post[0]) && (post[0] === 'TERMINATOR') ? this.tokens.splice(i - 2, 1) : this.tokens.splice(i, 0, after);
|
||||
} else if (prev && prev[0] !== 'TERMINATOR' && prev[0] !== 'INDENT' && prev[0] !== 'OUTDENT') {
|
||||
this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
||||
post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT' ? this.tokens.splice.apply(this.tokens, [i, 0].concat(this.tokens.splice(i + 2, 2))) : this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
|
||||
return 2;
|
||||
} else if (before && before[0] === 'OUTDENT' && prev && prev[0] === 'TERMINATOR' && post && post[0] === 'TERMINATOR' && after && after[0] === 'ELSE') {
|
||||
this.tokens.splice(i + 1, 0, this.tokens.splice(i - 2, 1)[0]);
|
||||
|
|
|
@ -62,12 +62,12 @@ exports.Rewriter: class Rewriter
|
|||
else
|
||||
@tokens.splice i, 0, after
|
||||
else if prev and prev[0] isnt 'TERMINATOR' and prev[0] isnt 'INDENT' and prev[0] isnt 'OUTDENT'
|
||||
if post and post[0] is 'TERMINATOR' and after and after[0] is 'OUTDENT'
|
||||
@tokens.splice(i, 0, @tokens.splice(i + 2, 2)...)
|
||||
else
|
||||
@tokens.splice i, 0, ['TERMINATOR', "\n", prev[2]]
|
||||
return 2
|
||||
else if before and before[0] is 'OUTDENT' and
|
||||
prev and prev[0] is 'TERMINATOR' and
|
||||
post and post[0] is 'TERMINATOR' and
|
||||
after and after[0] is 'ELSE'
|
||||
else if before and before[0] is 'OUTDENT' and prev and prev[0] is 'TERMINATOR' and post and post[0] is 'TERMINATOR' and after and after[0] is 'ELSE'
|
||||
@tokens.splice i + 1, 0, @tokens.splice(i - 2, 1)[0]
|
||||
return 1
|
||||
|
||||
|
|
|
@ -80,3 +80,9 @@ else
|
|||
3
|
||||
|
||||
ok result is 3
|
||||
|
||||
|
||||
result: switch 'z'
|
||||
when 'z' then 7
|
||||
# comment
|
||||
ok result is 7
|
||||
|
|
Loading…
Reference in a new issue