Skip to content

Commit

Permalink
feat: can extract attribute key from Group
Browse files Browse the repository at this point in the history
  • Loading branch information
sgulseth committed Aug 29, 2024
1 parent d319f1c commit 46ba490
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ function extractPropertyKey(node: ExprNode): string {
node.type === 'Slice' ||
node.type === 'Filter' ||
node.type === 'AccessElement' ||
node.type === 'ArrayCoerce'
node.type === 'ArrayCoerce' ||
node.type === 'Group'
) {
return extractPropertyKey(node.base)
}
Expand Down
31 changes: 31 additions & 0 deletions tap-snapshots/test/parse.test.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,34 @@ Object {
"type": "Select",
}
`

exports[`test/parse.test.ts TAP Expression parsing when extracting property keys can extract from group > must match snapshot 1`] = `
Object {
"base": Object {
"type": "Everything",
},
"expr": Object {
"base": Object {
"type": "This",
},
"expr": Object {
"attributes": Array [
Object {
"name": "id",
"type": "ObjectAttributeValue",
"value": Object {
"base": Object {
"name": "id",
"type": "AccessAttribute",
},
"type": "Group",
},
},
],
"type": "Object",
},
"type": "Projection",
},
"type": "Map",
}
`
4 changes: 4 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ t.test('Expression parsing', async (t) => {
t.test('throws when the key cannot be determined', async (t) => {
throwsWithMessage(t, () => parse('*{1}'), 'Cannot determine property key for type: Value')
})

t.test('can extract from group', async (t) => {
t.matchSnapshot(parse('*{(id)}'))
})
})

t.test('when parsing operators', async (t) => {
Expand Down

0 comments on commit 46ba490

Please sign in to comment.