Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: can extract attribute key from Group #175

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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