fixed a bug that compound assignments were declaring variables

This commit is contained in:
satyr 2010-11-01 10:42:42 +09:00
parent 195ca70278
commit 4f4032c053
3 changed files with 9 additions and 4 deletions

View File

@ -927,7 +927,7 @@
if (!this.variable.isAssignable()) {
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
}
if (!(isValue && (this.variable.hasProperties() || this.variable.namespaced))) {
if (!(this.context || isValue && (this.variable.namespaced || this.variable.hasProperties()))) {
o.scope.find(name);
}
val = name + (" " + (this.context || '=') + " ") + val;
@ -1001,7 +1001,7 @@
Assign.prototype.compileConditional = function(o) {
var _ref2, left, rite;
_ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1];
return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value)).compile(o);
return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o);
};
return Assign;
})();

View File

@ -764,7 +764,8 @@ exports.Assign = class Assign extends Base
return "#{name}: #{val}" if @context is 'object'
unless @variable.isAssignable()
throw SyntaxError "\"#{ @variable.compile o }\" cannot be assigned."
o.scope.find name unless isValue and (@variable.hasProperties() or @variable.namespaced)
o.scope.find name unless @context or
isValue and (@variable.namespaced or @variable.hasProperties())
val = name + " #{ @context or '=' } " + val
if o.level <= LEVEL_LIST then val else "(#{val})"
@ -833,7 +834,7 @@ exports.Assign = class Assign extends Base
# more than once.
compileConditional: (o) ->
[left, rite] = @variable.cacheReference o
return new Op(@context.slice(0, -1), left, new Assign(rite, @value)).compile o
new Op(@context.slice(0, -1), left, new Assign(rite, @value, '=')).compile o
#### Code

View File

@ -64,3 +64,7 @@ eq val, 'value'
for nonref in ['""', '0', 'f()']
try ok not CoffeeScript.compile "{k: #{nonref}} = v"
catch e then eq e.message, "\"#{nonref}\" cannot be assigned."
# Compound assignments should not declare.
eq Math, (-> Math or= 0)()