mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
fixes #1643: splatted accesses in destructuring assignments no longer create obj.key var declarations
This commit is contained in:
@@ -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(', ');
|
||||
|
||||
@@ -940,9 +940,10 @@ exports.Assign = class Assign extends Base
|
||||
return @compileSplice o if @variable.isSplice()
|
||||
return @compileConditional o if @context in ['||=', '&&=', '?=']
|
||||
name = @variable.compile o, LEVEL_LIST
|
||||
unless @context or @variable.isAssignable()
|
||||
unless @context or @variable.unwrapAll().isAssignable()
|
||||
throw SyntaxError "\"#{ @variable.compile o }\" cannot be assigned."
|
||||
unless @context or isValue and (@variable.namespaced or @variable.hasProperties())
|
||||
hasProps = (isValue and @variable.unwrapAll().hasProperties?()) or (@variable instanceof Splat and @variable.name.unwrapAll().hasProperties?())
|
||||
unless @context or hasProps
|
||||
if @param
|
||||
o.scope.add name, 'var'
|
||||
else
|
||||
@@ -1030,7 +1031,8 @@ exports.Assign = class Assign extends Base
|
||||
val = new Value new Literal(vvar), [new (if acc then Access else Index) idx]
|
||||
if name? and name in ['arguments','eval'].concat RESERVED
|
||||
throw new SyntaxError "assignment to a reserved word: #{obj.compile o} = #{val.compile o}"
|
||||
assigns.push new Assign(obj, val, null, param: @param).compile o, LEVEL_TOP
|
||||
isSoak = (soakNode = obj.name or obj) and soakNode.base?.soak or soakNode.properties?[0]?.soak
|
||||
assigns.push new Assign(obj.name or obj, val, null, param: @param).compile o, if isSoak then LEVEL_ACCESS else LEVEL_TOP
|
||||
assigns.push vvar unless top
|
||||
code = assigns.join ', '
|
||||
if o.level < LEVEL_LIST then code else "(#{code})"
|
||||
|
||||
Reference in New Issue
Block a user