Fix shorthands after interpolated key in objects

Fixes #4324.
This commit is contained in:
Simon Lydell 2016-09-29 19:02:00 +02:00
parent 0b2d852f67
commit 46841d916d
3 changed files with 10 additions and 0 deletions

View File

@ -1488,6 +1488,9 @@
value = prop.value;
} else {
ref3 = prop.base.cache(o), key = ref3[0], value = ref3[1];
if (key instanceof IdentifierLiteral) {
key = new PropertyName(key.value);
}
}
prop = new Assign(new Value(new IdentifierLiteral(oref), [new Access(key)]), value);
}

View File

@ -1019,6 +1019,7 @@ exports.Obj = class Obj extends Base
value = prop.value
else
[key, value] = prop.base.cache o
key = new PropertyName key.value if key instanceof IdentifierLiteral
prop = new Assign (new Value (new IdentifierLiteral oref), [new Access key]), value
if indent then answer.push @makeCode indent
answer.push prop.compileToFragments(o, LEVEL_TOP)...

View File

@ -569,3 +569,9 @@ test "object keys with interpolations", ->
interpolated:
nested:
123: 456
test "#4324: Shorthand after interpolated key", ->
a = 2
obj = {"#{1}": 1, a}
eq 1, obj[1]
eq 2, obj.a