Skip to content

Commit

Permalink
Fix shorthands after interpolated key in objects
Browse files Browse the repository at this point in the history
Fixes #4324.
  • Loading branch information
lydell committed Sep 29, 2016
1 parent 0b2d852 commit 46841d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)...
Expand Down
6 changes: 6 additions & 0 deletions test/objects.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 comments on commit 46841d9

@jashkenas
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curiosity — is this a regression or has the bug always been there?

@lydell
Copy link
Collaborator Author

@lydell lydell commented on 46841d9 Sep 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression since #4220.

Please sign in to comment.