Skip to content

Add composable native visitor selectors - #90

Merged
kitten merged 2 commits into
expo:mainfrom
kitten-agent:perf/expo-structural-visitors
Oct 27, 2026
Merged

kitten merged 2 commits into
expo:mainfrom
kitten-agent:perf/expo-structural-visitors

Conversation

@kitten

@kitten kitten commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Summary

When applied, these changes let the native side filter visitor matches before preparing callback data or dispatching to JS, reducing unnecessary callbacks on expensive plugins.

defineVisitor now also accepts a selector object with:

  • route and where to select nodes by type and fields.
  • parent to constrain the immediate AST parent.
  • children to constrain named child roles, with optional list index.

This is backwards-compatible and filed as a patch instead, since we're still in 0. releases.

Examples

Conditionals combine in an AND logic and are:

Filter by fields:

defineVisitor(
  { route: 'Identifier', where: { name: { equals: 'exports' } } },
  { fields: ['name'] },
  path => console.log(path.node.name),
);

Match an immediate parent:

defineVisitor(
  { route: 'VariableDeclaration', parent: { route: 'Program' } },
  { fields: ['kind'] },
  path => console.log(path.node.kind),
);

Match a named child, while delivering the root node:

defineVisitor(
  {
    route: 'AssignmentExpression',
    children: {
      left: {
        route: 'Identifier',
        where: { name: { equals: 'exports' }, global: { equals: true } },
      },
    },
  },
  {},
  (_path, state: { hasCjsExports: boolean }) => {
    state.hasCjsExports = true;
  },
);

Match a particular list position:

defineVisitor(
  {
    route: 'CallExpression',
    children: {
      arguments: {
        route: 'Identifier',
        index: 0,
        where: { name: { equals: 'exports' } },
      },
    },
  },
  {},
  () => console.log('First argument is exports'),
);

@kitten
kitten merged commit 05ad9a7 into expo:main Oct 27, 2026
1 check passed
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants