Skip to content

Commit

Permalink
implement variable in object key
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Jun 28, 2020
1 parent 29b689a commit e0487bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cli/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,17 @@
error: |
expected an object but got: number (10)
- name: variable in object key
args:
- '. as [$x, $y, $z] | {$x: 1, $y: 2, $z: 3}'
input: '["a", "b", "c"]'
expected: |
{
"a": 1,
"b": 2,
"c": 3
}
- name: pipe in object key
args:
- '{ (.foo|.bar): .foo.bar }'
Expand Down
5 changes: 5 additions & 0 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,11 @@ func (c *compiler) compileObjectKeyVal(v [2]int, kv ObjectKeyVal) error {
if err := c.compileString(kv.KeyString); err != nil {
return err
}
} else if kv.Key[0] == '$' {
c.append(&code{op: opload, v: v})
if err := c.compileFunc(&Func{Name: kv.Key}); err != nil {
return err
}
} else {
c.append(&code{op: oppush, v: kv.Key})
}
Expand Down

0 comments on commit e0487bd

Please sign in to comment.