Fixing the double-implicit-call-into-implicit-object problem.

This commit is contained in:
Jeremy Ashkenas 2010-09-15 22:29:03 -04:00
parent c782c2ec1c
commit 60f80e2698
3 changed files with 14 additions and 3 deletions

View File

@ -213,7 +213,7 @@
if (('IF' === (_c = token[0]) || 'ELSE' === _c || 'UNLESS' === _c || '->' === _c || '=>' === _c)) {
seenSingle = true;
}
return (!token.generated && this.tokens[i - 1][0] !== ',' && include(IMPLICIT_END, token[0]) && !(token[0] === 'INDENT' && (include(IMPLICIT_BLOCK, this.tag(i - 1)) || this.tag(i - 2) === 'CLASS'))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
return (!token.generated && this.tokens[i - 1][0] !== ',' && include(IMPLICIT_END, token[0]) && !(token[0] === 'INDENT' && (include(IMPLICIT_BLOCK, this.tag(i - 1)) || this.tag(i - 2) === 'CLASS' || this.tag(i + 1) === '{'))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
};
action = function(token, i) {
idx = token[0] === 'OUTDENT' ? i + 1 : i;

View File

@ -174,7 +174,7 @@ exports.Rewriter = class Rewriter
return yes if not seenSingle and token.fromThen
seenSingle = yes if token[0] in ['IF', 'ELSE', 'UNLESS', '->', '=>']
(not token.generated and @tokens[i - 1][0] isnt ',' and include(IMPLICIT_END, token[0]) and
not (token[0] is 'INDENT' and (include(IMPLICIT_BLOCK, @tag(i - 1)) or @tag(i - 2) is 'CLASS'))) or
not (token[0] is 'INDENT' and (include(IMPLICIT_BLOCK, @tag(i - 1)) or @tag(i - 2) is 'CLASS' or @tag(i + 1) is '{'))) or
token[0] is 'PROPERTY_ACCESS' and @tag(i - 1) is 'OUTDENT'
action = (token, i) ->
idx = if token[0] is 'OUTDENT' then i + 1 else i

View File

@ -227,4 +227,15 @@ obj = then second 'the',
three: 3
ok obj[1] is 1
ok obj.three is 3
ok obj.three is 3
# Implicit objects as part of chained calls.
identity = (x) -> x.a
b = identity identity identity
a:
a:
a: 100
ok b is 100