Fixing issue #694. Destructuring assignment as first line of implicitly called block -- regression.

This commit is contained in:
Jeremy Ashkenas 2010-09-19 09:04:38 -04:00
parent 08e1101c1f
commit 15d84dbb4e
3 changed files with 15 additions and 3 deletions

View File

@ -206,14 +206,15 @@
if (prev && (prev.spaced && (include(IMPLICIT_FUNC, prev[0]) || prev.call) && include(IMPLICIT_CALL, token[0]) && !(token[0] === 'UNARY' && (('IN' === (_c = this.tag(i + 1)) || 'OF' === _c || 'INSTANCEOF' === _c)))) || callObject) {
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
condition = function(token, i) {
var _c;
var _c, post;
if (!seenSingle && token.fromThen) {
return true;
}
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' || this.tag(i + 1) === '{'))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
post = this.tokens[i + 1];
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' || (post && post.generated && post[0] === '{')))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
};
action = function(token, i) {
idx = token[0] === 'OUTDENT' ? i + 1 : i;

View File

@ -173,8 +173,9 @@ exports.Rewriter = class Rewriter
condition = (token, i) ->
return yes if not seenSingle and token.fromThen
seenSingle = yes if token[0] in ['IF', 'ELSE', 'UNLESS', '->', '=>']
post = @tokens[i + 1]
(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 @tag(i + 1) is '{'))) or
not (token[0] is 'INDENT' and (include(IMPLICIT_BLOCK, @tag(i - 1)) or @tag(i - 2) is 'CLASS' or (post and post.generated and post[0] 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

@ -137,3 +137,13 @@ persons = [['Bob', ['George']], ['Alice', ['Bob']], ['Stan', ['Christopher']]]
join3 = "#{parent}: #{name}" for [name, [parent]] in persons
deepEqual join2, join3
# Pattern matching doesn't clash with implicit block objects.
obj = a: 101
func -> true
if func func
{a} = obj
ok a is 101