Skip to content

perf: parse code once and share the AST via context - #594

Open
xbinaryx wants to merge 1 commit into
eslint:mainfrom
xbinaryx:share-ast-parse
Open

xbinaryx wants to merge 1 commit into
eslint:mainfrom
xbinaryx:share-ast-parse

Conversation

@xbinaryx

@xbinaryx xbinaryx commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

Every component that called useAST() parsed the code on its own. Up to three are mounted at once (App, EsquerySelectorInput, and the AST or Scope tab), so each code edit could trigger three parses. Even typing in the ESQuery selector re-parsed the code in each of them.

The Scope tab had a separate problem. The React Compiler silently skipped the Scope component because of a conditional inside a try/catch. With nothing memoized, eslintScope.analyze ran on every render of the tab, including on every selector keystroke.

What changes did you make? (Give an overview)

  • Added an ASTProvider that parses the code once and shares the result through context. useAST() now reads from that context.
  • Memoized the parse and the ESQuery match separately, so typing in the selector reruns only the match.
  • Moved the try/catch in Scope into an analyzeScope helper and memoized the analysis on the AST and the JS options.
  • Exported the ExplorerState type for the parse input, and updated docs/adding-languages.md to point to the new file.

Related Issues

#64

Is there anything you'd like reviewers to focus on?

Summary by CodeRabbit

  • Bug Fixes

    • Scope analysis errors are now displayed alongside parsing errors instead of being left unhandled.
  • Refactor

    • AST parsing and selector matching are coordinated through a shared provider, with results reused when inputs have not changed.
    • Scope analysis reuses AST results and JavaScript parsing options.
  • Documentation

    • Updated language integration guidance for AST wiring and language-specific options.

@netlify

netlify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for eslint-code-explorer ready!

Name Link
🔨 Latest commit 8456248
🔍 Latest deploy log https://app.netlify.com/projects/eslint-code-explorer/deploys/6ad33adcfb4c99b9e19210c1
😎 Deploy Preview https://deploy-preview-594--eslint-code-explorer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@eslintbot eslintbot added this to Triage Oct 17, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Oct 17, 2026
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: eslint/coderabbit/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8f5c8406-fea1-41d0-9c0f-105b917035fa
📥 Commits

Reviewing files that changed from the base of the PR and between cd374e2 and 8456248.

📒 Files selected for processing: 5
  • docs/adding-languages.md
  • src/components/scope/index.tsx
  • src/hooks/use-ast.tsx
  • src/hooks/use-explorer.ts
  • src/index.tsx

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

AST parsing and selector matching now run through ASTProvider, which supplies AST results through context. Scope memoizes scope analysis and displays analysis errors. The language-adding guide now documents the provider and language-specific parse options.

Changes: AST and Scope Analysis

Layer / File(s) Summary
AST result provider and integration
src/hooks/use-ast.tsx, src/hooks/use-explorer.ts, src/index.tsx, docs/adding-languages.md
ASTProvider reads parsing inputs and the selector, memoizes parsing and node matching, and supplies AST results through context. The entry point wraps App with the provider. The guide documents ParseInput options and the provider.
Scope analysis and error display
src/components/scope/index.tsx
Scope memoizes analysis using the AST result and JavaScript options. Scope analysis returns a scope manager or an error, and Scope displays errors.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant ASTProvider
  participant ExplorerState
  participant parseCode
  participant addEsqueryMatchedNodes
  participant useAST
  App->>ASTProvider: Render inside provider
  ASTProvider->>ExplorerState: Read parsing inputs and selector
  ASTProvider->>parseCode: Parse language, source, and options
  parseCode-->>ASTProvider: Return parse result
  ASTProvider->>addEsqueryMatchedNodes: Match nodes using parse result and selector
  ASTProvider-->>useAST: Supply AST result through context
Loading

Suggested reviewers: pixel998

Merge Risk: ⚪ Minimal · up to 84562

No actionable merge-blocking risk was found; the change is ready for normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main performance change: parsing code once and sharing the AST through context.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants