@@ -353,7 +353,7 @@ export function findFunction(source: string, args: ASTLookupArgs): ASTLookupResu
353353}
354354
355355/**
356- * Searches for a variable declaration in the given code based on specified criteria.
356+ * Searches for a variable declarator in the given code based on specified criteria.
357357 *
358358 * @example
359359 * ```ts
@@ -381,23 +381,21 @@ export function findVariable(code: string, options: ASTLookupArgs): ASTLookupRes
381381 function walk ( node : Node ) : void {
382382 if ( found ) return ;
383383
384- if ( node . type === 'VariableDeclaration ' ) {
384+ if ( node . type === 'VariableDeclarator ' ) {
385385 const [ start , end ] = node . range ! ;
386386 const node_source = code . slice ( start , end ) ;
387387
388- for ( const declarator of node . declarations ) {
389- if ( declarator . id . type === 'Identifier' ) {
390- const var_name = declarator . id . name ;
391- if ( options . name && var_name === options . name ) {
392- found = { start, end, name : var_name , node, result : node_source } ;
393- return ;
394- }
388+ if ( node . id . type === 'Identifier' ) {
389+ const var_name = node . id . name ;
390+ if ( options . name && var_name === options . name ) {
391+ found = { start, end, name : var_name , node, result : node_source } ;
392+ return ;
395393 }
396394 }
397395 if (
398396 ( options . includes && node_source . includes ( options . includes ) ) ||
399397 ( options . regexp && options . regexp . test ( node_source ) ) ) {
400- found = { start, end, name : ( node . declarations ?. [ 0 ] ?. id as any ) ?. name , node, result : node_source } ;
398+ found = { start, end, name : ( node ?. id as any ) ?. name , node, result : node_source } ;
401399 return ;
402400 }
403401 }
0 commit comments