mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #4068 from lydell/issue-1192
Fix #1192: Assignment starting with object literals
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user