mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
coco 63d607f: made deep destructuring compile nicer
This commit is contained in:
parent
09aa9e2a04
commit
15bdcf79e6
2 changed files with 7 additions and 7 deletions
12
lib/nodes.js
12
lib/nodes.js
|
@ -978,7 +978,7 @@
|
|||
}
|
||||
};
|
||||
Assign.prototype.compilePatternMatch = function(o) {
|
||||
var acc, assigns, code, i, idx, isObject, ivar, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref, _ref2, _ref3, _ref4, _ref5, _ref6;
|
||||
var acc, assigns, code, i, idx, isObject, ivar, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref, _ref2, _ref3, _ref4;
|
||||
top = o.level === LEVEL_TOP;
|
||||
value = this.value;
|
||||
objects = this.variable.base.objects;
|
||||
|
@ -988,10 +988,10 @@
|
|||
isObject = this.variable.isObject();
|
||||
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
|
||||
if (obj instanceof Assign) {
|
||||
_ref = obj, (_ref2 = _ref.variable, idx = _ref2.base, _ref2), obj = _ref.value;
|
||||
_ref = obj, idx = _ref.variable.base, obj = _ref.value;
|
||||
} else {
|
||||
if (obj.base instanceof Parens) {
|
||||
_ref3 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref3[0], idx = _ref3[1];
|
||||
_ref2 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref2[0], idx = _ref2[1];
|
||||
} else {
|
||||
idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
|
||||
}
|
||||
|
@ -1013,10 +1013,10 @@
|
|||
idx = i;
|
||||
if (isObject) {
|
||||
if (obj instanceof Assign) {
|
||||
_ref4 = obj, (_ref5 = _ref4.variable, idx = _ref5.base, _ref5), obj = _ref4.value;
|
||||
_ref3 = obj, idx = _ref3.variable.base, obj = _ref3.value;
|
||||
} else {
|
||||
if (obj.base instanceof Parens) {
|
||||
_ref6 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref6[0], idx = _ref6[1];
|
||||
_ref4 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref4[0], idx = _ref4[1];
|
||||
} else {
|
||||
idx = obj["this"] ? obj.properties[0].name : obj;
|
||||
}
|
||||
|
@ -1045,7 +1045,7 @@
|
|||
}
|
||||
val = new Value(new Literal(vvar), [new (acc ? Accessor : Index)(idx)]);
|
||||
}
|
||||
assigns.push(new Assign(obj, val).compile(o, LEVEL_LIST));
|
||||
assigns.push(new Assign(obj, val).compile(o, LEVEL_TOP));
|
||||
}
|
||||
if (!top) {
|
||||
assigns.push(vvar);
|
||||
|
|
|
@ -842,7 +842,7 @@ exports.Assign = class Assign extends Base
|
|||
else
|
||||
acc = isObject and IDENTIFIER.test idx.unwrap().value or 0
|
||||
val = new Value new Literal(vvar), [new (if acc then Accessor else Index) idx]
|
||||
assigns.push new Assign(obj, val).compile o, LEVEL_LIST
|
||||
assigns.push new Assign(obj, val).compile o, LEVEL_TOP
|
||||
assigns.push vvar unless top
|
||||
code = assigns.join ', '
|
||||
if o.level < LEVEL_LIST then code else "(#{code})"
|
||||
|
|
Loading…
Reference in a new issue