Skip to content

[docs-infra] Replace handwritten source parsing with TypeScript - #1764

Open
brijeshb42 wants to merge 2 commits into
masterfrom
docs-infra-typescript-factory-parser
Open

[docs-infra] Replace handwritten source parsing with TypeScript#1764
brijeshb42 wants to merge 2 commits into
masterfrom
docs-infra-typescript-factory-parser

Conversation

@brijeshb42

@brijeshb42 brijeshb42 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Part of #1762

Summary

Replace handwritten JavaScript/TypeScript parsing with the TypeScript syntax tree for:

  • create* factory discovery and source ranges
  • factory arguments, objects, arrays, calls, generics, arrows, and assertions
  • static imports, export-from statements, and dynamic imports

The existing structured output and legacy generic factory syntax remain supported. CSS and comment processing are unchanged. Direct utility imports keep the TypeScript parser out of unrelated Base UI bundles.

This reduces production code by 1,046 SLOC (+531 / -1,577). All 133 factory results and 520 import results in the Base UI demo corpus are byte-for-byte equivalent to master.

The corpus microbenchmark increases from 23 ms to 82 ms. The cold Base UI docs build still compiled in 37.8 seconds, generated all 193 pages, and reported no broken links or HTML issues. Across three alternating cold builds, median aggregate peak RSS was 4.32 GB on master and 4.24 GB on this branch—no measurable memory regression.

Validation

  • 402 focused parser and integration tests
  • Prettier, targeted ESLint, TypeScript, and release build
  • Base UI production build and link check

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 4, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-1764--mui-internal.netlify.app/
QR code for https://deploy-preview-1764--mui-internal.netlify.app/

Bundle size

Total Size Change: ▼-7.05KB(-0.21%) - Total Gzip Change: ▼-1.87KB(-0.20%)
Files: 69 total (0 added, 0 removed, 7 changed)

Show details for 69 more bundles

@mui/internal-docs-infra/useCodeparsed: 🔺+13B(+0.01%) gzip: 🔺+71B(+0.20%)
@mui/internal-docs-infra/useDemoparsed: 🔺+5B(0.00%) gzip: 🔺+27B(+0.06%)
@mui/internal-docs-infra/cliparsed: ▼-4.47KB(-0.54%) gzip: ▼-1.27KB(-0.50%)
transpileSourceparsed: ▼-2.59KB(-1.20%) gzip: ▼-684B(-1.37%)
loadIsomorphicCodeVariantparsed: ▼-1B(0.00%) gzip: ▼-9B(-0.10%)
@mui/internal-docs-infra/abstractCreateDemoparsed: 0B(0.00%) gzip: ▼-5B(-0.21%)
@mui/internal-docs-infra/abstractCreateDemoClientparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/abstractCreateTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/ChunkProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeControllerContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeExternalsContextparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighterparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/errorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeHighlighter/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CodeProviderparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazyparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/CoordinatedLazy/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoDataparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createDemoData/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemapparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/createSitemap/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCodeWindowparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCoordinatedparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCopierparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useCrossTabStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useDemoControllerparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useErrorsparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useLocalStorageStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/usePreferenceparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useScrollAnchorparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearchparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useSearch/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStreamparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useStream/typesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypeparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useTypesparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/useUrlHashStateparsed: 0B(0.00%) gzip: 0B(0.00%)
@mui/internal-docs-infra/withDocsInfraparsed: 0B(0.00%) gzip: 0B(0.00%)
addLineGuttersparsed: 0B(0.00%) gzip: 0B(0.00%)
BuildEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterChunkparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeHighlighterClientparsed: 0B(0.00%) gzip: 0B(0.00%)
CodeInitialSourceLoaderparsed: 0B(0.00%) gzip: 🔺+1B(+0.04%)
CodeSourceLoaderparsed: 0B(0.00%) gzip: 0B(0.00%)
compileCssWithPostcssparsed: 0B(0.00%) gzip: 0B(0.00%)
createFrameparsed: 0B(0.00%) gzip: 0B(0.00%)
createParseSourceWorkerClientparsed: 0B(0.00%) gzip: 0B(0.00%)
EditingEngineparsed: 0B(0.00%) gzip: 0B(0.00%)
embedTransformsparsed: 0B(0.00%) gzip: 0B(0.00%)
enhanceCodeEmphasisparsed: 0B(0.00%) gzip: 0B(0.00%)
findExpandingRangesparsed: 0B(0.00%) gzip: 0B(0.00%)
getHastTextContentparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarLoadersparsed: 0B(0.00%) gzip: 0B(0.00%)
grammarsparsed: 0B(0.00%) gzip: 0B(0.00%)
isFrameSpanparsed: 0B(0.00%) gzip: 0B(0.00%)
parseSourceparsed: 0B(0.00%) gzip: 0B(0.00%)
rolldown-runtimeparsed: 0B(0.00%) gzip: 0B(0.00%)
source.cssparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.jsonparsed: 0B(0.00%) gzip: 0B(0.00%)
source.mdxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.shellparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsparsed: 0B(0.00%) gzip: 0B(0.00%)
source.tsxparsed: 0B(0.00%) gzip: 0B(0.00%)
source.yamlparsed: 0B(0.00%) gzip: 0B(0.00%)
text.html.basicparsed: 0B(0.00%) gzip: 0B(0.00%)
text.mdparsed: 0B(0.00%) gzip: 0B(0.00%)
TransformEngineparsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Performance

Total duration: 16.74 ms +0.69 ms(+4.3%) | Renders: 5 (+0) | Paint: 57.74 ms -1.11 ms(-1.9%)

Test Duration Renders
custom scalar + discrete metrics 0.00 ms 0 (+0)
sub-series via labels 0.00 ms 0 (+0)

5 tests within noise — details

Metric alarms

Test Metric Change
custom scalar + discrete metrics fib_duration 🔺 +0.13 ms
sub-series via labels fib_phase#small 🔺 +0.06 ms
sub-series via labels fib_phase#large 🔺 +0.52 ms

Check out the code infra dashboard for more information about this PR.

@brijeshb42 brijeshb42 added the scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305). label Aug 4, 2026
@brijeshb42 brijeshb42 changed the title [docs-infra] Parse factory calls with TypeScript [docs-infra] Replace handwritten source parsing with TypeScript Aug 4, 2026
@brijeshb42
brijeshb42 force-pushed the docs-infra-typescript-factory-parser branch from 4adce95 to be5d612 Compare August 5, 2026 06:35
@brijeshb42
brijeshb42 marked this pull request as ready for review August 5, 2026 07:50
@brijeshb42
brijeshb42 requested a review from a team August 5, 2026 07:50
@brijeshb42
brijeshb42 force-pushed the docs-infra-typescript-factory-parser branch 2 times, most recently from 8990172 to 8dc4603 Compare August 5, 2026 17:10
@brijeshb42
brijeshb42 force-pushed the docs-infra-typescript-factory-parser branch from 8dc4603 to d8164b0 Compare August 18, 2026 14:44
@Janpot

Janpot commented Aug 18, 2026

Copy link
Copy Markdown
Member
  1. Is there a specific reason to parse with typescript over e.g. babel? When I think of typescript I think slow, and unstable API.
  2. Does this affect dev mode page transitions performance?

@brijeshb42

Copy link
Copy Markdown
Contributor Author

Is there a specific reason to parse with typescript over e.g. babel

Mainly because typescript is already installed and initialized. So there's no overhead there. It'll work till we have the lighter version with lezer based parsing.

Does this affect dev mode page transitions performance?

There's a very slight impact in perf (in 40ms range) here, mainly because a ts project is already initialized (for type generation). But nothing significant. We still get same build times but with less code.

@brijeshb42
brijeshb42 force-pushed the docs-infra-typescript-factory-parser branch from d8164b0 to 1196891 Compare August 20, 2026 06:26
@Janpot

Janpot commented Aug 20, 2026

Copy link
Copy Markdown
Member

tbh, I'd be very careful relying on typescript API if all we do is parsing. It's really unstable, and non-existent in v7. There is barely an ecosystem for ts as a transpiler platform. I guess we could tolerate it if it's temporary

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

Labels

scope: docs-infra Involves the docs-infra product (https://www.notion.so/mui-org/b9f676062eb94747b6768209f7751305).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants