refactor(plugins): use ESTree types for AST transforms - #3172
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
🔵 Needs a closer look
The refactor touches many critical AST-based transforms and shared traversal/scope utilities, making subtle behavioral regressions hard to rule out without a deeper manual review and full test/fixture validation.
Pull request overview
Refactors vinext’s plugin AST transforms to use Vite-exported ESTree node types end-to-end, replacing prior “loose record” AST shapes and runtime validation with typed node threading through traversals and scope helpers.
Changes:
- Migrates core AST utilities (
ast-utils,ast-scope) from structural records toESTree.NodeAPIs (typed traversal, binding collection, wrapper unwrapping). - Updates multiple transform plugins to consume typed programs/nodes directly (removing many
isAstRecord/hasRange/nodeArrayguards). - Refreshes AST utility tests to use
parseAst()output shapes instead of hand-built node objects.
File summaries
| File | Description |
|---|---|
| tests/plugin-utils.test.ts | Updates AST utility tests to parse real code via parseAst() and assert against actual ESTree node shapes. |
| packages/vinext/src/plugins/worker-image-imports.ts | Uses ESTree types when walking and rewriting import specifiers for worker image handling. |
| packages/vinext/src/plugins/typeof-window.ts | Converts environment-condition replacement logic to operate on typed ESTree.Node values and typed scopes. |
| packages/vinext/src/plugins/styled-jsx.ts | Tightens JSX tag detection using typed JSX node fields rather than structural casting. |
| packages/vinext/src/plugins/require-context.ts | Refactors require.context parsing/analysis helpers to typed ESTree nodes (incl. regex literal handling). |
| packages/vinext/src/plugins/require-condition-resolution.ts | Moves conditional-require analysis to typed nodes and simplifies traversal over typed bodies/args. |
| packages/vinext/src/plugins/pages-node-externals.ts | Updates dependency specifier extraction to use typed import/export/dynamic-import node handling. |
| packages/vinext/src/plugins/optimize-imports.ts | Replaces custom declaration shape types with typed declaration/binding collection via collectBindingNames. |
| packages/vinext/src/plugins/middleware-export-validation.ts | Switches middleware export static analysis to iterate typed program statements/specifiers. |
| packages/vinext/src/plugins/import-meta-url.ts | Converts import.meta.url detection and CJS global analysis to typed nodes, simplifying child walking. |
| packages/vinext/src/plugins/ignore-dynamic-requests.ts | Refactors dynamic request detection/static evaluation helpers to typed ESTree nodes and arguments. |
| packages/vinext/src/plugins/extensionless-dynamic-import.ts | Updates extensionless dynamic import collection/parsing to typed ESTree.Program and nodes. |
| packages/vinext/src/plugins/dynamic-preload-metadata.ts | Replaces record-based AST inspection with typed traversal, binding collection, and object property helpers. |
| packages/vinext/src/plugins/ast-utils.ts | Core change: redefines AST utility surface area around ESTree types (walkers, literal helpers, bindings). |
| packages/vinext/src/plugins/ast-scope.ts | Updates scope/binding collection utilities to typed node unions and typed statement-container handling. |
Review details
- Files reviewed: 15/15 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
Summary