Skip to content

Improve build report route analysis with AST parsing#606

Open
Boyeep wants to merge 12 commits intocloudflare:mainfrom
Boyeep:fix/scope-getstaticprops-revalidate
Open

Improve build report route analysis with AST parsing#606
Boyeep wants to merge 12 commits intocloudflare:mainfrom
Boyeep:fix/scope-getstaticprops-revalidate

Conversation

@Boyeep
Copy link
Contributor

@Boyeep Boyeep commented Mar 20, 2026

Fixes #605

  1. Summary

This replaces the build report’s regex/string-based route analysis with AST-based analysis using the TypeScript compiler API.

The main goal is to make route classification more accurate, especially around getStaticProps and exported route config, while keeping the existing report flow intact.

  1. What changed
  • Switched build-report source inspection in packages/vinext/src/build/report.ts to TypeScript AST parsing

  • Replaced regex-based detection for:

  • named exports

  • export const dynamic = ...

  • export const revalidate = ...

  • getStaticProps revalidate extraction

  • Reused a single parsed AST per file during route classification instead of reparsing for each helper

  • Added support for:

  • aliased exports

  • local identifier aliases

  • as const

  • satisfies

  • extension-aware TS vs TSX parsing

  • Ignored non-runtime exports:

  • export type { ... }

  • export { type ... }

  • export declare ...

  • Treated non-local or non-analyzable getStaticProps exports conservatively as unknown instead of incorrectly reporting static

  • Applied speculative prerender promotion to Pages routes as well, so Pages routes classified as unknown can still be upgraded to static when prerender confirms them

  1. Tests

Added regression coverage for:

  • early-return redirects
  • re-exports
  • imported re-exports
  • aliased exports
  • default exports
  • type-only exports
  • generic arrow getStaticProps
  • local identifier aliases
  • non-analyzable local getStaticProps factories
  • as const / satisfies
  • speculative prerender upgrade for Pages routes

vp test tests/build-report.test.ts passes with 107 tests.

  1. Notes

vp lint still reports the existing unrelated benchmark import errors:

benchmarks/vinext/vite.config.ts
benchmarks/vinext-rolldown/vite.config.ts

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@606

commit: 536d7e2

@james-elicx
Copy link
Collaborator

Sorry to be a pain - have you looked at oxc-parser before?

It might be a nice option to try out as it has great performance and compatibility - https://npmx.dev/package/oxc-parser

@Boyeep
Copy link
Contributor Author

Boyeep commented Mar 20, 2026

oxc-parser actually does seem like a strong option here.

For this PR, I’d prefer to keep the current TypeScript compiler API approach so the scope stays limited to improving report accuracy and landing the current follow-up fixes cleanly. But I agree Oxc looks like a very reasonable option for the longer-term parser-based follow-up, and I’d be happy to explore that in a separate PR.

@james-elicx
Copy link
Collaborator

Completely slipped my mind before - Vite also has a parseAst function as well which we use in several places already

@Boyeep
Copy link
Contributor Author

Boyeep commented Mar 20, 2026

Yeah, that makes sense probably worth checking first.

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.

Explore using ASTs to improve route report generation

2 participants