Skip to content

Commit 46ba490

Browse files
committed
feat: can extract attribute key from Group
1 parent d319f1c commit 46ba490

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/parser.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ function extractPropertyKey(node: ExprNode): string {
839839
node.type === 'Slice' ||
840840
node.type === 'Filter' ||
841841
node.type === 'AccessElement' ||
842-
node.type === 'ArrayCoerce'
842+
node.type === 'ArrayCoerce' ||
843+
node.type === 'Group'
843844
) {
844845
return extractPropertyKey(node.base)
845846
}

tap-snapshots/test/parse.test.ts.test.cjs

+31
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,34 @@ Object {
211211
"type": "Select",
212212
}
213213
`
214+
215+
exports[`test/parse.test.ts TAP Expression parsing when extracting property keys can extract from group > must match snapshot 1`] = `
216+
Object {
217+
"base": Object {
218+
"type": "Everything",
219+
},
220+
"expr": Object {
221+
"base": Object {
222+
"type": "This",
223+
},
224+
"expr": Object {
225+
"attributes": Array [
226+
Object {
227+
"name": "id",
228+
"type": "ObjectAttributeValue",
229+
"value": Object {
230+
"base": Object {
231+
"name": "id",
232+
"type": "AccessAttribute",
233+
},
234+
"type": "Group",
235+
},
236+
},
237+
],
238+
"type": "Object",
239+
},
240+
"type": "Projection",
241+
},
242+
"type": "Map",
243+
}
244+
`

test/parse.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ t.test('Expression parsing', async (t) => {
134134
t.test('throws when the key cannot be determined', async (t) => {
135135
throwsWithMessage(t, () => parse('*{1}'), 'Cannot determine property key for type: Value')
136136
})
137+
138+
t.test('can extract from group', async (t) => {
139+
t.matchSnapshot(parse('*{(id)}'))
140+
})
137141
})
138142

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

0 commit comments

Comments
 (0)