@@ -87,12 +87,13 @@ export interface TreeNode {
8787 astNode : ASTNode
8888 primitiveValue ?: string | number | boolean
8989 attributeName ?: string
90+ path : string
9091}
9192
9293/**
9394 * Format a node label with relevant information based on node type
9495 */
95- function formatNodeLabel ( node : ASTNode , attributeName ?: string ) : string {
96+ function formatNodeLabel ( node : ASTNode ) : string {
9697 let label = node . type
9798
9899 // Add useful info based on type
@@ -141,6 +142,7 @@ export function buildTree(
141142 matchedNodes : Set < ASTNode > ,
142143 primitiveResults : Array < string | number | boolean > = [ ] ,
143144 attributeName ?: string ,
145+ parentPath : string = '' ,
144146) : TreeNode {
145147 const children : TreeNode [ ] = [ ]
146148
@@ -150,16 +152,20 @@ export function buildTree(
150152 // eslint-disable-next-line @typescript-eslint/no-explicit-any
151153 const anyNode = node as any
152154
155+ // Compute the path segment for this node
156+ const segment = attributeName ? `${ attributeName } :${ node . type } ` : node . type
157+ const currentPath = parentPath ? `${ parentPath } /${ segment } ` : `/${ segment } `
158+
153159 if (
154160 node . type === 'TemplateLiteral' &&
155161 Array . isArray ( anyNode . quasis ) &&
156162 Array . isArray ( anyNode . expressions )
157163 ) {
158164 // Interleave quasis and expressions by source position: quasi[0], expr[0], quasi[1], expr[1], ..., quasi[n]
159165 for ( let i = 0 ; i < anyNode . quasis . length ; i ++ ) {
160- children . push ( buildTree ( anyNode . quasis [ i ] , matchedNodes , primitiveResults , 'quasis' ) )
166+ children . push ( buildTree ( anyNode . quasis [ i ] , matchedNodes , primitiveResults , 'quasis' , currentPath ) )
161167 if ( i < anyNode . expressions . length ) {
162- children . push ( buildTree ( anyNode . expressions [ i ] , matchedNodes , primitiveResults , 'expressions' ) )
168+ children . push ( buildTree ( anyNode . expressions [ i ] , matchedNodes , primitiveResults , 'expressions' , currentPath ) )
163169 }
164170 }
165171 } else {
@@ -169,11 +175,11 @@ export function buildTree(
169175 if ( Array . isArray ( child ) ) {
170176 for ( const item of child ) {
171177 if ( item && typeof item === 'object' && 'type' in item ) {
172- children . push ( buildTree ( item , matchedNodes , primitiveResults , key ) )
178+ children . push ( buildTree ( item , matchedNodes , primitiveResults , key , currentPath ) )
173179 }
174180 }
175181 } else if ( child && typeof child === 'object' && 'type' in child ) {
176- children . push ( buildTree ( child , matchedNodes , primitiveResults , key ) )
182+ children . push ( buildTree ( child , matchedNodes , primitiveResults , key , currentPath ) )
177183 }
178184 }
179185 }
@@ -182,13 +188,14 @@ export function buildTree(
182188 type : node . type ,
183189 start : node . start ,
184190 end : node . end ,
185- label : formatNodeLabel ( node , attributeName ) ,
191+ label : formatNodeLabel ( node ) ,
186192 children,
187193 isMatched : matchedNodes . has ( node ) ,
188194 isAncestorOfMatch : false ,
189195 isExpanded : false ,
190196 astNode : node ,
191197 attributeName,
198+ path : currentPath ,
192199 }
193200
194201 return treeNode
0 commit comments