1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

fixes #1643: splatted accesses in destructuring assignments no longer create obj.key var declarations

This commit is contained in:
Gerald Lewis 2011-09-01 14:47:10 -04:00
parent d37cfc69d9
commit 43a8b46203
2 changed files with 13 additions and 9 deletions

View file

@ -1063,7 +1063,7 @@
return unfoldSoak(o, this, 'variable');
};
Assign.prototype.compileNode = function(o) {
var isValue, match, name, val, _ref2, _ref3, _ref4, _ref5;
var hasProps, isValue, match, name, val, _base, _base2, _ref2, _ref3, _ref4, _ref5;
if (isValue = this.variable instanceof Value) {
if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o);
@ -1074,10 +1074,11 @@
}
}
name = this.variable.compile(o, LEVEL_LIST);
if (!(this.context || this.variable.isAssignable())) {
if (!(this.context || this.variable.unwrapAll().isAssignable())) {
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
}
if (!(this.context || isValue && (this.variable.namespaced || this.variable.hasProperties()))) {
hasProps = (isValue && (typeof (_base = this.variable.unwrapAll()).hasProperties === "function" ? _base.hasProperties() : void 0)) || (this.variable instanceof Splat && (typeof (_base2 = this.variable.name.unwrapAll()).hasProperties === "function" ? _base2.hasProperties() : void 0));
if (!(this.context || hasProps)) {
if (this.param) {
o.scope.add(name, 'var');
} else {
@ -1098,7 +1099,7 @@
}
};
Assign.prototype.compilePatternMatch = function(o) {
var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref2, _ref3, _ref4, _ref5, _ref6;
var acc, assigns, code, i, idx, isObject, isSoak, ivar, name, obj, objects, olen, ref, rest, soakNode, splat, top, val, value, vvar, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;
top = o.level === LEVEL_TOP;
value = this.value;
objects = this.variable.base.objects;
@ -1183,9 +1184,10 @@
if ((name != null) && __indexOf.call(['arguments', 'eval'].concat(RESERVED), name) >= 0) {
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (val.compile(o)));
}
assigns.push(new Assign(obj, val, null, {
isSoak = (soakNode = obj.name || obj) && ((_ref7 = soakNode.base) != null ? _ref7.soak : void 0) || ((_ref8 = soakNode.properties) != null ? (_ref9 = _ref8[0]) != null ? _ref9.soak : void 0 : void 0);
assigns.push(new Assign(obj.name || obj, val, null, {
param: this.param
}).compile(o, LEVEL_TOP));
}).compile(o, isSoak ? LEVEL_ACCESS : LEVEL_TOP));
}
if (!top) assigns.push(vvar);
code = assigns.join(', ');