Uh oh!
There was an error while loading. Please reload this page.
ref(sveltekit): Replace recast + @babel/parser with acorn - #19533
Conversation
fa80627 to
d9cb391Compared9cb391 to
f54035eCompareThere was a problem hiding this comment.
Hi, thanks for taking this on! This looks good to me! Once we drop support for SvelteKit <2.31.0, we can even get rid of these deps entirely but for now, the reduction from 8 to 2 deps already is a win.
heads-up: I adjusted the PR title to better reflect the type of change
Head branch was pushed to by a user without write access
470a2a7 to
2299bb2CompareUh oh!
There was an error while loading. Please reload this page.
Replaces recast and @babel/parser with acorn and @sveltejs/acorn-typescript for AST parsing in the auto-instrumentation plugin. Since the code only reads the AST (never transforms or prints), the full recast pipeline is unnecessary. Key changes: - Delete recastTypescriptParser.ts (no longer needed) - Use acorn Parser.extend(tsPlugin()) for TypeScript parsing - Use @sveltejs/acorn-typescript (actively maintained) instead of TyrealHu's abandoned acorn-typescript - Fix StringLiteral -> Literal node type check (ESTree compliance) - Fix ast.program -> ast (acorn returns Program directly) - Use try/catch for parse errors instead of null program check Removes ~8 transitive dependencies (recast, ast-types, esprima, source-map, tslib, tiny-invariant, @babel/parser, @babel/types). Ref: getsentry#19447 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix import sort order in autoInstrument.ts (scoped package before unscoped) - Deduplicate @sveltejs/acorn-typescript entries in yarn.lock Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2299bb2 to
87f80a4CompareJPeer264
commented
Mar 19, 2026
I just rebased the branch and deduplicated yarn.lock. Hopefully this can be merged then right after |
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Deps
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Lms24
commented
Mar 20, 2026
rebased once more after the last release. Gonna merge this afterwards! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
Uh oh!
There was an error while loading. Please reload this page.
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #19533 Co-authored-by: Lms24 <8420481+Lms24@users.noreply.github.com>
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #19533 Co-authored-by: Lms24 <8420481+Lms24@users.noreply.github.com>

Replaces
recastand@babel/parserwithacornand@sveltejs/acorn-typescriptfor AST parsing in the sveltekit auto-instrumentation plugin.yarn lint) & (yarn test).Ref #19447
What this does
The
autoInstrumentVite plugin parses SvelteKit+page.ts/+layout.server.tsfiles to detectexport const loadorexport function loaddeclarations. It only reads the AST — never transforms or prints it — so recast's source-preserving round-trip feature is entirely unused.This replaces the full recast + @babel/parser pipeline with acorn (Node.js's own parser) and
@sveltejs/acorn-typescript(the actively maintained TypeScript plugin used by SvelteKit itself).Changes
recastTypescriptParser.ts— the 91-line Babel parser config with 20+ plugin declarations is no longer neededrecast.parse()withacorn.Parser.extend(tsPlugin()).parse()inautoInstrument.tsStringLiteral(Babel-specific) →Literal(ESTree standard) for string literal export detectionast.program(recast's File wrapper) → directast(acorn returns Program)try/catcharound parse (acorn throws SyntaxError) replaces dubious null check(specifier.exported as unknown as t.StringLiteral)in favor of proper discriminant narrowingDependency reduction
Removed:
recast,ast-types,esprima,source-map,tslib,tiny-invariant,@babel/parser,@babel/types,@babel/helper-string-parser,@babel/helper-validator-identifierAdded:
acorn(already in dep tree via Vite/Rollup),@sveltejs/acorn-typescript(already in dep tree via@sveltejs/kit)Net effect: ~8 fewer transitive dependencies, zero new packages for end users.
Why @sveltejs/acorn-typescript?
The original
acorn-typescriptpackage by TyrealHu hasn't been updated since January 2024 and has known unpatched bugs. The Svelte team's fork (@sveltejs/acorn-typescript) is actively maintained and is already a transitive dependency of every SvelteKit project.All 69 existing tests pass without modification.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com