assigning to bizarre things like [a()] = b now causes syntax error

This commit is contained in:
satyr
2010-10-25 07:33:41 +09:00
parent e146b539f5
commit 98d22f9510
3 changed files with 28 additions and 22 deletions

View File

@@ -152,11 +152,12 @@
return new Op('!', this);
};
Base.prototype.children = [];
Base.prototype.unwrap = THIS;
Base.prototype.isStatement = NO;
Base.prototype.isPureStatement = NO;
Base.prototype.isComplex = YES;
Base.prototype.isChainable = NO;
Base.prototype.isAssignable = NO;
Base.prototype.unwrap = THIS;
Base.prototype.unfoldSoak = NO;
Base.prototype.assigns = NO;
return Base;
@@ -276,6 +277,9 @@
var _ref2;
return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
};
Literal.prototype.isAssignable = function() {
return IDENTIFIER.test(this.value);
};
Literal.prototype.isComplex = NO;
Literal.prototype.assigns = function(name) {
return name === this.value;
@@ -355,6 +359,9 @@
}
return true;
};
Value.prototype.isAssignable = function() {
return this.hasProperties() || this.base.isAssignable();
};
Value.prototype.assigns = function(name) {
return !this.properties.length && this.base.assigns(name);
};
@@ -899,7 +906,7 @@
return If.unfoldSoak(o, this, 'variable');
};
Assign.prototype.compileNode = function(o) {
var _ref2, assignee, isValue, match, name, val;
var _ref2, isValue, match, name, val;
if (isValue = this.variable instanceof Value) {
if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o);
@@ -917,8 +924,8 @@
if (this.context === 'object') {
return "" + name + ": " + val;
}
if (!(this.variable.isComplex() || IDENTIFIER.test(assignee = this.variable.unwrap().value))) {
throw SyntaxError("" + assignee + " cannot be assigned.");
if (!this.variable.isAssignable()) {
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
}
if (!(isValue && (this.variable.hasProperties() || this.variable.namespaced))) {
o.scope.find(name);
@@ -971,9 +978,6 @@
}
}
}
if (!(obj instanceof Value || obj instanceof Splat)) {
throw SyntaxError('destructuring assignment must use only identifiers on the left-hand side.');
}
if (!splat && obj instanceof Splat) {
val = new Literal(obj.compileValue(o, valVar, i, olength - i - 1));
splat = true;
@@ -1003,9 +1007,6 @@
while (obj !== (obj = obj.unwrap())) {
continue;
}
if (!(obj instanceof Literal || obj instanceof Value)) {
throw SyntaxError('nonreference in destructuring assignment shorthand.');
}
return Value.wrap(obj).cacheReference(o);
};
return Assign;
@@ -1151,6 +1152,7 @@
})();
__extends(Splat, Base);
Splat.prototype.children = ['name'];
Splat.prototype.isAssignable = YES;
Splat.prototype.assigns = function(name) {
return this.name.assigns(name);
};