Merge pull request #4068 from lydell/issue-1192

Fix #1192: Assignment starting with object literals
This commit is contained in:
Michael Ficarra
2015-08-22 07:24:23 -07:00
3 changed files with 11 additions and 0 deletions

View File

@@ -1697,6 +1697,9 @@
}
}
val = this.value.compileToFragments(o, LEVEL_LIST);
if (isValue && this.variable.base instanceof Obj) {
this.variable.front = true;
}
compiledName = this.variable.compileToFragments(o, LEVEL_LIST);
if (this.context === 'object') {
return compiledName.concat(this.makeCode(": "), val);

View File

@@ -1217,6 +1217,7 @@ exports.Assign = class Assign extends Base
else
o.scope.find varBase.value
val = @value.compileToFragments o, LEVEL_LIST
@variable.front = true if isValue and @variable.base instanceof Obj
compiledName = @variable.compileToFragments o, LEVEL_LIST
return (compiledName.concat @makeCode(": "), val) if @context is 'object'
answer = compiledName.concat @makeCode(" #{ @context or '=' } "), val

View File

@@ -131,6 +131,13 @@ test "more compound assignment", ->
val ?= true
eq c, val
test "#1192: assignment starting with object literals", ->
doesNotThrow (-> CoffeeScript.run "{}.p = 0")
doesNotThrow (-> CoffeeScript.run "{}.p++")
doesNotThrow (-> CoffeeScript.run "{}[0] = 1")
doesNotThrow (-> CoffeeScript.run """{a: 1, 'b', "#{1}": 2}.p = 0""")
doesNotThrow (-> CoffeeScript.run "{a:{0:{}}}.a[0] = 0")
# Destructuring Assignment