Skip to content

Commit

Permalink
Fix handling of member expression as object property key (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Oct 12, 2021
1 parent 7a74e0c commit d932de7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Jint.Tests/Runtime/EngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,31 @@ public void RecursiveCallStack()
Assert.Equal(1389, result);
}

[Fact]
public void MemberExpressionInObjectProperty()
{
var engine = new Engine();
dynamic result = engine.Evaluate(@"
const colorMap = {
Red: ""red"",
Orange: ""orange"",
White: ""white"",
};
Object
.keys(colorMap)
.reduce((agg, next) => {
return {...agg, ...{ [colorMap[next]]: next } };
},
{});
")
.ToObject();

Assert.Equal("Red", result.red);
Assert.Equal("Orange", result.orange);
Assert.Equal("White", result.white);
}

private class Wrapper
{
public Testificate Test { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Jint/EsprimaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ or Nodes.BinaryExpression
or Nodes.UpdateExpression
or Nodes.AssignmentExpression
or Nodes.UnaryExpression
|| expression is StaticMemberExpression)
or Nodes.MemberExpression)
{
propertyKey = TypeConverter.ToPropertyKey(JintExpression.Build(engine, expression).GetValue());
return true;
Expand Down

0 comments on commit d932de7

Please sign in to comment.