eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.77 kB
JavaScript
function collectReferencedIdentifierNames(e){let t=new Set,visit=(e,n)=>{if(e.type?.startsWith(`TS`)){isRuntimeTypeScriptExpression(e)&&e.expression&&visit(e.expression,`reference`);return}e.type===`Identifier`&&e.name&&n===`reference`&&t.add(e.name);for(let[t,r]of Object.entries(e)){let i=getChildContext(e,t,n);if(i)if(Array.isArray(r))for(let e of r)isAstNode(e)&&visit(e,i);else isAstNode(r)&&visit(r,i)}};return visit(e,`reference`),t}function getChildContext(e,t,n){return t===`typeAnnotation`||t===`returnType`||t===`typeParameters`||t===`typeArguments`?null:e.type===`VariableDeclarator`&&t===`id`||(e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`||e.type===`FunctionDeclaration`)&&(t===`id`||t===`params`)||e.type===`CatchClause`&&t===`param`||(e.type===`ClassDeclaration`||e.type===`ClassExpression`)&&t===`id`?`binding`:e.type===`Property`&&t===`key`?e.computed===!0?`reference`:null:e.type===`Property`&&t===`value`?n:e.type===`AssignmentPattern`?t===`right`?`reference`:n:(e.type===`ObjectPattern`||e.type===`ArrayPattern`||e.type===`RestElement`)&&(t===`properties`||t===`elements`||t===`argument`)?n:(e.type===`MemberExpression`||e.type===`OptionalMemberExpression`)&&t===`property`||(e.type===`MethodDefinition`||e.type===`PropertyDefinition`)&&t===`key`?e.computed===!0?`reference`:null:(e.type===`LabeledStatement`||e.type===`BreakStatement`||e.type===`ContinueStatement`)&&t===`label`?null:`reference`}function isRuntimeTypeScriptExpression(e){return e.type===`TSAsExpression`||e.type===`TSInstantiationExpression`||e.type===`TSNonNullExpression`||e.type===`TSSatisfiesExpression`||e.type===`TSTypeAssertion`}function isAstNode(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}export{collectReferencedIdentifierNames};