Skip to content

[APPS][Connections Part 1] Add internal AST traversal helper#350

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit intomasterfrom
sdkennedy2/ast-parsing-walk-ast
May 8, 2026
Merged

[APPS][Connections Part 1] Add internal AST traversal helper#350
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit intomasterfrom
sdkennedy2/ast-parsing-walk-ast

Conversation

@sdkennedy2
Copy link
Copy Markdown
Collaborator

@sdkennedy2 sdkennedy2 commented May 8, 2026

Motivation

The inline backend connection ID extractor needs an ESTree traversal helper, but using zimmerframe directly requires a temporary package patch and Jest shim because its current package exports do not support the repo's CommonJS integrity/test path. acorn-walk avoids that export issue but uses Acorn AST types, which forces casts around ESTree nodes.

Changes

Adds a small internal walkAst helper under packages/plugins/apps/src/backend/ast-parsing/ for inspect-only ESTree traversal. The helper walks all ESTree-shaped node types generically by scanning enumerable object properties and arrays for objects with a string type field, so it does not need a hardcoded visitor-key table. This works in a similar way to estree-walker and zimmerframe.

The API supports a universal _ visitor, specialized node-type visitors, and shared traversal state. It deliberately omits transformation features such as node replacement, immutable parent cloning, manual visit, ancestor paths, stop, and child-specific state threading because the current extractor only needs read-only traversal.

Example usage:

const importedNames = new Set<string>();

walkAst(program, importedNames, {
    ImportDeclaration(node, { state }) {
        if (node.source.value !== '@datadog/action-catalog/http/http') {
            return;
        }

        for (const specifier of node.specifiers) {
            state.add(specifier.local.name);
        }
    },
    CallExpression(node) {
        // Called for every CallExpression while walkAst continues traversing
        // children automatically.
    },
});

QA Instructions

Tests should pass.

Blast Radius

This PR only adds a new internal helper and tests. No existing production code consumes it yet, so runtime behavior is unchanged.

Documentation

Copy link
Copy Markdown
Collaborator Author

sdkennedy2 commented May 8, 2026

@sdkennedy2 sdkennedy2 changed the title Add internal AST traversal helper [APPS] Add internal AST traversal helper May 8, 2026
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/ast-parsing-walk-ast branch 3 times, most recently from f002135 to f9a0de7 Compare May 8, 2026 15:58
@sdkennedy2 sdkennedy2 force-pushed the sdkennedy2/ast-parsing-walk-ast branch from f9a0de7 to d681de3 Compare May 8, 2026 16:02
@sdkennedy2 sdkennedy2 marked this pull request as ready for review May 8, 2026 17:13
@sdkennedy2 sdkennedy2 requested review from a team and yoannmoinet as code owners May 8, 2026 17:13
@sdkennedy2 sdkennedy2 changed the title [APPS] Add internal AST traversal helper [APPS][Connections Part 1] Add internal AST traversal helper May 8, 2026
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot merged commit 26c39e3 into master May 8, 2026
6 checks passed
@gh-worker-dd-mergequeue-cf854d gh-worker-dd-mergequeue-cf854d Bot deleted the sdkennedy2/ast-parsing-walk-ast branch May 8, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants