mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fixing issue #544. Needed to special case implicit-object-closing for outdents -- it's different than a single-line implicit object with a terminator.
This commit is contained in:
parent
f3caa9292f
commit
acd69b1c70
3 changed files with 25 additions and 1 deletions
|
@ -128,7 +128,7 @@
|
|||
return size;
|
||||
}, this);
|
||||
return this.scanTokens(__bind(function(prev, token, post, i) {
|
||||
var _c, after, before, idx, len, open, tag;
|
||||
var _c, after, before, idx, len, open, size, tag;
|
||||
tag = token[0];
|
||||
len = stack.length - 1;
|
||||
before = this.tokens[i - 2];
|
||||
|
@ -146,10 +146,16 @@
|
|||
if (tag === 'OUTDENT' && post && post[0] === '}') {
|
||||
return 1;
|
||||
}
|
||||
if (tag === 'OUTDENT') {
|
||||
size = closeBrackets(i);
|
||||
}
|
||||
stack[len - 1] += stack.pop();
|
||||
if (tag === '}') {
|
||||
stack[len - 1] -= 1;
|
||||
}
|
||||
if (tag === 'OUTDENT') {
|
||||
return size;
|
||||
}
|
||||
} else if (tag === ':' && !open) {
|
||||
idx = before && before[0] === '@' ? i - 2 : i - 1;
|
||||
this.tokens.splice(idx, 0, ['{', '{', token[2]]);
|
||||
|
|
|
@ -19,6 +19,9 @@ else
|
|||
# its internal array of tokens.
|
||||
exports.Rewriter = class Rewriter
|
||||
|
||||
# Helpful snippet for debugging:
|
||||
# puts (t[0] + '/' + t[1] for t in @tokens).join ' '
|
||||
|
||||
# Rewrite the token stream in multiple passes, one logical filter at
|
||||
# a time. This could certainly be changed into a single pass through the
|
||||
# stream, with a big ol' efficient switch, but it's much nicer to work with
|
||||
|
@ -138,8 +141,10 @@ exports.Rewriter = class Rewriter
|
|||
return 2 if tag is '{' and post and post[0] is 'INDENT'
|
||||
else if include EXPRESSION_END, tag
|
||||
return 1 if tag is 'OUTDENT' and post and post[0] is '}'
|
||||
size = closeBrackets(i) if tag is 'OUTDENT'
|
||||
stack[len - 1] += stack.pop()
|
||||
stack[len - 1] -= 1 if tag is '}'
|
||||
return size if tag is 'OUTDENT'
|
||||
else if tag is ':' and not open
|
||||
idx = if before and before[0] is '@' then i - 2 else i - 1
|
||||
@tokens.splice idx, 0, ['{', '{', token[2]]
|
||||
|
|
|
@ -139,3 +139,16 @@ obj =
|
|||
|
||||
ok obj.a is 1
|
||||
ok obj.b is 2
|
||||
|
||||
|
||||
# Implicit objects nesting.
|
||||
obj =
|
||||
options:
|
||||
value: yes
|
||||
|
||||
fn: ->
|
||||
{}
|
||||
null
|
||||
|
||||
ok obj.options.value is yes
|
||||
ok obj.fn() is null
|
Loading…
Add table
Reference in a new issue