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 Feb 21, 2024
1 parent 2da36d8 commit c1526c9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
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
43 changes: 34 additions & 9 deletions tap-snapshots/test/parse.test.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ Object {
}
`

exports[
`test/parse.test.ts TAP Basic parsing Object expression starting with string > must match snapshot 1`
] = `
exports[`test/parse.test.ts TAP Basic parsing Object expression starting with string > must match snapshot 1`] = `
Object {
"attributes": Array [
Object {
Expand All @@ -187,9 +185,7 @@ Object {
}
`

exports[
`test/parse.test.ts TAP Basic parsing Space after field in objects > must match snapshot 1`
] = `
exports[`test/parse.test.ts TAP Basic parsing Space after field in objects > must match snapshot 1`] = `
Object {
"attributes": Array [
Object {
Expand All @@ -205,9 +201,7 @@ Object {
}
`

exports[
`test/parse.test.ts TAP Basic parsing Trailing comma in function call > must match snapshot 1`
] = `
exports[`test/parse.test.ts TAP Basic parsing Trailing comma in function call > must match snapshot 1`] = `
Object {
"alternatives": Array [],
"fallback": Object {
Expand All @@ -217,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 c1526c9

Please sign in to comment.