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

fixing herecomment/indentation bugaboo ... issue #474

This commit is contained in:
Jeremy Ashkenas 2010-07-06 22:20:42 -04:00
parent afa3bb4191
commit 577daf5457
3 changed files with 25 additions and 7 deletions

View file

@ -50,10 +50,13 @@
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 && !('TERMINATOR' === (_d = prev[0]) || 'INDENT' === _d || 'OUTDENT' === _d)) {
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]]);
if (post && post[0] === 'TERMINATOR' && after && after[0] === 'OUTDENT') {
this.tokens.splice.apply(this.tokens, [i + 3, 0].concat(this.tokens.splice(i, 2)));
this.tokens.splice(i + 3, 0, ['TERMINATOR', "\n", prev[2]]);
} else {
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]);
}
return 1;
};

View file

@ -63,13 +63,11 @@ exports.Rewriter: class Rewriter
@tokens.splice i, 0, after
else if prev and prev[0] not in ['TERMINATOR', 'INDENT', 'OUTDENT']
if post and post[0] is 'TERMINATOR' and after and after[0] is 'OUTDENT'
@tokens.splice(i, 0, @tokens.splice(i + 2, 2)...)
@tokens.splice(i + 3, 0, @tokens.splice(i, 2)...)
@tokens.splice(i + 3, 0, ['TERMINATOR', "\n", prev[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'
@tokens.splice i + 1, 0, @tokens.splice(i - 2, 1)[0]
return 1
# Leading newlines would introduce an ambiguity in the grammar, so we

View file

@ -66,6 +66,23 @@ func: ->
###
code
func: ->
one: ->
two: ->
three: ->
###
block.
###
four: ->
fn1: ->
oneLevel: null
###
This isn't fine.
###
ok ok
obj: {
a: 'b'
###