Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/start-compiler-module-info-ast-retention.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/router-utils': patch
---

Stop the Start compiler's module cache from retaining parsed ASTs. `extractModuleInfoFromAst` now stores a detached clone of each binding's initializer, so a cached module no longer keeps the `@babel/traverse` `NodePath` and `Scope` graph of the file it came from reachable.
8 changes: 6 additions & 2 deletions packages/router-utils/src/compiler-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ function addVariableDeclarationModuleInfo(
for (const name of collectIdentifiersFromPattern(declarator.id)) {
bindings.set(name, {
type: 'var',
init: declarator.init ?? null,
// Detached: `@babel/traverse` keys its caches on node identity, so
// storing the original would pin this file's whole traversal graph.
init: declarator.init ? t.cloneNode(declarator.init, true, true) : null,
})
exportMap?.set(name, name)
}
Expand Down Expand Up @@ -552,7 +554,9 @@ export function extractModuleInfoFromAst(ast: t.File): ExtractedModuleInfo {
const synth = '__default_export__'
bindings.set(synth, {
type: 'var',
init: t.isExpression(declaration) ? declaration : null,
init: t.isExpression(declaration)
? t.cloneNode(declaration, true, true)
: null,
})
exportMap.set('default', synth)
}
Expand Down