@@ -229,6 +229,33 @@ describe('walk — typed embedded fields (untagged)', () => {
229229 expect ( rawStmts ) . toHaveLength ( 2 ) ;
230230 } ) ;
231231
232+ it ( 'detects a bare libpg-query parse result at the root' , ( ) => {
233+ // libpg-query parseSync() returns {version, stmts} with no ParseResult wrapper
234+ const parseResult = {
235+ version : 180004 ,
236+ stmts : [ { stmt : createPolicyAst , stmt_len : 52 } ]
237+ } ;
238+ const tags : string [ ] = [ ] ;
239+ walk ( parseResult , ( path ) => { tags . push ( path . tag ) ; } ) ;
240+
241+ expect ( tags [ 0 ] ) . toBe ( 'ParseResult' ) ;
242+ expect ( tags [ 1 ] ) . toBe ( 'RawStmt' ) ;
243+ expect ( tags ) . toContain ( 'CreatePolicyStmt' ) ;
244+ expect ( tags ) . toContain ( 'RangeVar' ) ;
245+ } ) ;
246+
247+ it ( 'does not treat non-root {version, stmts} shapes as ParseResult' , ( ) => {
248+ const tags : string [ ] = [ ] ;
249+ walk ( { wrapper : { version : 180004 , stmts : [ ] as any [ ] } } , ( path ) => { tags . push ( path . tag ) ; } ) ;
250+ expect ( tags ) . toEqual ( [ ] ) ;
251+ } ) ;
252+
253+ it ( 'ignores tagged wrappers whose payload is not an object' , ( ) => {
254+ const visited : NodePath [ ] = [ ] ;
255+ walk ( { Weird : 'not-an-object' } , ( path ) => { visited . push ( path ) ; } ) ;
256+ expect ( visited ) . toEqual ( [ ] ) ;
257+ } ) ;
258+
232259 it ( 'keeps existing behavior for tagged nodes' , ( ) => {
233260 const visited : string [ ] = [ ] ;
234261 const visitor : Visitor = {
@@ -276,6 +303,20 @@ describe('visit — typed embedded fields (untagged)', () => {
276303 expect ( rangeVars [ 0 ] . relname ) . toBe ( 'posts' ) ;
277304 } ) ;
278305
306+ it ( 'detects a bare libpg-query parse result at the root' , ( ) => {
307+ const parseResult = {
308+ version : 180004 ,
309+ stmts : [ { stmt : createPolicyAst , stmt_len : 52 } ]
310+ } ;
311+ const visited : string [ ] = [ ] ;
312+ visit ( parseResult , {
313+ ParseResult : ( ) => { visited . push ( 'ParseResult' ) ; } ,
314+ RawStmt : ( ) => { visited . push ( 'RawStmt' ) ; } ,
315+ RangeVar : ( node ) => { visited . push ( `RangeVar:${ node . relname } ` ) ; }
316+ } ) ;
317+ expect ( visited ) . toEqual ( [ 'ParseResult' , 'RawStmt' , 'RangeVar:posts' ] ) ;
318+ } ) ;
319+
279320 it ( 'keeps existing behavior for tagged nodes' , ( ) => {
280321 const visited : string [ ] = [ ] ;
281322 visit ( createPolicyAst , {
0 commit comments