mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
follow-up to d1bca636; fixed unrolling of the single case ({@a} = o
-> @a = o.a
)
This commit is contained in:
parent
9fd031c896
commit
0ada1dfc3f
3 changed files with 11 additions and 15 deletions
10
lib/nodes.js
10
lib/nodes.js
|
@ -801,7 +801,7 @@
|
|||
join = '';
|
||||
}
|
||||
indent = prop instanceof CommentNode ? '' : this.idt(1);
|
||||
if (prop instanceof ValueNode && prop.tags['this']) {
|
||||
if (prop instanceof ValueNode && prop.tags["this"]) {
|
||||
prop = new AssignNode(prop.properties[0].name, prop, 'object');
|
||||
} else if (!(prop instanceof AssignNode) && !(prop instanceof CommentNode)) {
|
||||
prop = new AssignNode(prop, prop, 'object');
|
||||
|
@ -1000,7 +1000,7 @@
|
|||
if (obj instanceof AssignNode) {
|
||||
_ref2 = obj, idx = _ref2.variable.base, obj = _ref2.value;
|
||||
} else {
|
||||
idx = isObject ? obj : literal(0);
|
||||
idx = isObject ? (obj.tags["this"] ? obj.properties[0].name : obj) : literal(0);
|
||||
}
|
||||
if (!(value instanceof ValueNode)) {
|
||||
value = new ValueNode(value);
|
||||
|
@ -1023,11 +1023,7 @@
|
|||
if (obj instanceof AssignNode) {
|
||||
_ref2 = [obj.value, obj.variable.base], obj = _ref2[0], idx = _ref2[1];
|
||||
} else {
|
||||
if (obj.tags['this']) {
|
||||
idx = obj.properties[0].name;
|
||||
} else {
|
||||
idx = obj;
|
||||
}
|
||||
idx = obj.tags["this"] ? obj.properties[0].name : obj;
|
||||
}
|
||||
}
|
||||
if (!(obj instanceof ValueNode || obj instanceof SplatNode)) {
|
||||
|
|
|
@ -714,7 +714,7 @@ exports.ObjectNode = class ObjectNode extends BaseNode
|
|||
join = "\n" if (prop is lastNoncom) or (prop instanceof CommentNode)
|
||||
join = '' if i is @properties.length - 1
|
||||
indent = if prop instanceof CommentNode then '' else @idt 1
|
||||
if prop instanceof ValueNode and prop.tags['this']
|
||||
if prop instanceof ValueNode and prop.tags.this
|
||||
prop = new AssignNode prop.properties[0].name, prop, 'object'
|
||||
else if prop not instanceof AssignNode and prop not instanceof CommentNode
|
||||
prop = new AssignNode prop, prop, 'object'
|
||||
|
@ -886,7 +886,9 @@ exports.AssignNode = class AssignNode extends BaseNode
|
|||
if obj instanceof AssignNode
|
||||
{variable: {base: idx}, value: obj} = obj
|
||||
else
|
||||
idx = if isObject then obj else literal 0
|
||||
idx = if isObject
|
||||
if obj.tags.this then obj.properties[0].name else obj
|
||||
else literal 0
|
||||
value = new ValueNode value unless value instanceof ValueNode
|
||||
accessClass = if IDENTIFIER.test idx.value then AccessorNode else IndexNode
|
||||
value.properties.push new accessClass idx
|
||||
|
@ -904,12 +906,8 @@ exports.AssignNode = class AssignNode extends BaseNode
|
|||
# A regular object pattern-match.
|
||||
[obj, idx] = [obj.value, obj.variable.base]
|
||||
else
|
||||
if obj.tags['this']
|
||||
# A shorthand `{@a, @b, @c} = val` pattern-match.
|
||||
idx = obj.properties[0].name
|
||||
else
|
||||
# A shorthand `{a, b, c} = val` pattern-match.
|
||||
idx = obj
|
||||
# A shorthand `{a, b, @c} = val` pattern-match.
|
||||
idx = if obj.tags.this then obj.properties[0].name else obj
|
||||
unless obj instanceof ValueNode or obj instanceof SplatNode
|
||||
throw new Error 'pattern matching must use only identifiers on the left-hand side.'
|
||||
accessClass = if isObject and IDENTIFIER.test(idx.value) then AccessorNode else IndexNode
|
||||
|
|
|
@ -149,6 +149,8 @@ obj =
|
|||
func: (list, object) ->
|
||||
[@one, @two] = list
|
||||
{@a, @b} = object
|
||||
{@a} = object # must not unroll this
|
||||
null
|
||||
|
||||
obj.func [1, 2], a: 'a', b: 'b'
|
||||
|
||||
|
|
Loading…
Reference in a new issue