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

fixing single-line implicit call wrapped around function with trailing arguments

This commit is contained in:
Jeremy Ashkenas 2010-03-28 16:44:41 -04:00
parent 6e0e0767f9
commit 1e315b5a33
3 changed files with 19 additions and 4 deletions

View file

@ -177,6 +177,9 @@
if (tag === 'INDENT' && prev && include(IMPLICIT_BLOCK, prev[0])) {
return 1;
}
if (tag === 'OUTDENT' && token.generated) {
return 1;
}
if (open || tag === 'INDENT') {
idx = tag === 'OUTDENT' ? i + 1 : i;
stack_pointer = tag === 'INDENT' ? 2 : 1;
@ -209,7 +212,7 @@
Rewriter.prototype.add_implicit_indentation = function add_implicit_indentation() {
return this.scan_tokens((function(__this) {
var __func = function(prev, token, post, i) {
var idx, insertion, parens, pre, starter, tok;
var idx, insertion, outdent, parens, pre, starter, tok;
if (!(include(SINGLE_LINERS, token[0]) && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) {
return 1;
}
@ -223,7 +226,9 @@
pre = this.tokens[idx - 1];
if ((!tok || (include(SINGLE_CLOSERS, tok[0]) && tok[1] !== ';') || (tok[0] === ')' && parens === 0)) && !(starter === 'ELSE' && tok[0] === 'ELSE')) {
insertion = pre[0] === "," ? idx - 1 : idx;
this.tokens.splice(insertion, 0, ['OUTDENT', 2, token[2]]);
outdent = ['OUTDENT', 2, token[2]];
outdent.generated = true;
this.tokens.splice(insertion, 0, outdent);
break;
}
if (tok[0] === '(') {

View file

@ -126,6 +126,7 @@ exports.Rewriter: class Rewriter
return 2
if !post? or include IMPLICIT_END, tag
return 1 if tag is 'INDENT' and prev and include IMPLICIT_BLOCK, prev[0]
return 1 if tag is 'OUTDENT' and token.generated
if open or tag is 'INDENT'
idx: if tag is 'OUTDENT' then i + 1 else i
stack_pointer: if tag is 'INDENT' then 2 else 1
@ -162,7 +163,9 @@ exports.Rewriter: class Rewriter
(tok[0] is ')' && parens is 0)) and
not (starter is 'ELSE' and tok[0] is 'ELSE')
insertion: if pre[0] is "," then idx - 1 else idx
@tokens.splice(insertion, 0, ['OUTDENT', 2, token[2]])
outdent: ['OUTDENT', 2, token[2]]
outdent.generated: true
@tokens.splice(insertion, 0, outdent)
break
parens: + 1 if tok[0] is '('
parens: - 1 if tok[0] is ')'

View file

@ -120,4 +120,11 @@ mult: (x, mids..., y) ->
ok mult(1, 2,) is 2
ok mult(1, 2, 3,) is 6
ok mult(10,[1..6]...,) is 7200
ok mult(10,[1..6]...,) is 7200
# Test for inline functions with parentheses and implicit calls.
combine: (func, num) -> func() * num
result: combine (-> 1 + 2), 3
ok result is 9