Fixes #2207 -- unambiguous immediate implicit closes don't close implicit objects
This commit is contained in:
parent
3e95d7f2d0
commit
6bcc798a76
|
@ -112,12 +112,13 @@
|
|||
};
|
||||
|
||||
Rewriter.prototype.addImplicitBraces = function() {
|
||||
var action, condition, sameLine, stack, start, startIndent, startsLine;
|
||||
var action, condition, sameLine, stack, start, startIndent, startIndex, startsLine;
|
||||
stack = [];
|
||||
start = null;
|
||||
startsLine = null;
|
||||
sameLine = true;
|
||||
startIndent = 0;
|
||||
startIndex = 0;
|
||||
condition = function(token, i) {
|
||||
var one, tag, three, two, _ref, _ref1;
|
||||
_ref = this.tokens.slice(i + 1, (i + 3) + 1 || 9e9), one = _ref[0], two = _ref[1], three = _ref[2];
|
||||
|
@ -128,7 +129,7 @@
|
|||
if (__indexOf.call(LINEBREAKS, tag) >= 0) {
|
||||
sameLine = false;
|
||||
}
|
||||
return (((tag === 'TERMINATOR' || tag === 'OUTDENT') || (__indexOf.call(IMPLICIT_END, tag) >= 0 && sameLine)) && ((!startsLine && this.tag(i - 1) !== ',') || !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':'))) || (tag === ',' && one && ((_ref1 = one[0]) !== 'IDENTIFIER' && _ref1 !== 'NUMBER' && _ref1 !== 'STRING' && _ref1 !== '@' && _ref1 !== 'TERMINATOR' && _ref1 !== 'OUTDENT'));
|
||||
return (((tag === 'TERMINATOR' || tag === 'OUTDENT') || (__indexOf.call(IMPLICIT_END, tag) >= 0 && sameLine && !(i - startIndex === 1))) && ((!startsLine && this.tag(i - 1) !== ',') || !((two != null ? two[0] : void 0) === ':' || (one != null ? one[0] : void 0) === '@' && (three != null ? three[0] : void 0) === ':'))) || (tag === ',' && one && ((_ref1 = one[0]) !== 'IDENTIFIER' && _ref1 !== 'NUMBER' && _ref1 !== 'STRING' && _ref1 !== '@' && _ref1 !== 'TERMINATOR' && _ref1 !== 'OUTDENT'));
|
||||
};
|
||||
action = function(token, i) {
|
||||
var tok;
|
||||
|
@ -149,6 +150,7 @@
|
|||
return 1;
|
||||
}
|
||||
sameLine = true;
|
||||
startIndex = i + 1;
|
||||
stack.push(['{']);
|
||||
idx = ago === '@' ? i - 2 : i - 1;
|
||||
while (this.tag(idx - 2) === 'HERECOMMENT') {
|
||||
|
|
|
@ -105,17 +105,21 @@ class exports.Rewriter
|
|||
startsLine = null
|
||||
sameLine = yes
|
||||
startIndent = 0
|
||||
startIndex = 0
|
||||
|
||||
condition = (token, i) ->
|
||||
[one, two, three] = @tokens[i + 1 .. i + 3]
|
||||
return no if 'HERECOMMENT' is one?[0]
|
||||
[tag] = token
|
||||
sameLine = no if tag in LINEBREAKS
|
||||
((tag in ['TERMINATOR', 'OUTDENT'] or (tag in IMPLICIT_END and sameLine)) and
|
||||
((!startsLine and @tag(i - 1) isnt ',') or
|
||||
return (
|
||||
(tag in ['TERMINATOR', 'OUTDENT'] or
|
||||
(tag in IMPLICIT_END and sameLine and not (i - startIndex is 1))) and
|
||||
((!startsLine and @tag(i - 1) isnt ',') or
|
||||
not (two?[0] is ':' or one?[0] is '@' and three?[0] is ':'))) or
|
||||
(tag is ',' and one and
|
||||
one[0] not in ['IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT'])
|
||||
one[0] not in ['IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT']
|
||||
)
|
||||
|
||||
action = (token, i) ->
|
||||
tok = @generate '}', '}', token[2]
|
||||
|
@ -131,6 +135,7 @@ class exports.Rewriter
|
|||
return 1 unless tag is ':' and
|
||||
((ago = @tag i - 2) is ':' or stack[stack.length - 1]?[0] isnt '{')
|
||||
sameLine = yes
|
||||
startIndex = i + 1
|
||||
stack.push ['{']
|
||||
idx = if ago is '@' then i - 2 else i - 1
|
||||
idx -= 2 while @tag(idx - 2) is 'HERECOMMENT'
|
||||
|
|
|
@ -269,3 +269,11 @@ test "#1961, #1974, regression with compound assigning to an implicit object", -
|
|||
four: 4
|
||||
|
||||
eq obj.four, 4
|
||||
|
||||
test "#2207: Immediate implicit closes don't close implicit objects", ->
|
||||
func = ->
|
||||
key: for i in [1, 2, 3] then i
|
||||
|
||||
eq func().key.join(' '), '1 2 3'
|
||||
|
||||
|
Loading…
Reference in New Issue