chore(sveltekit): replace recast + @babel/parser with acorn#19533
Open
roli-lpci wants to merge 1 commit intogetsentry:developfrom
Open
chore(sveltekit): replace recast + @babel/parser with acorn#19533roli-lpci wants to merge 1 commit intogetsentry:developfrom
roli-lpci wants to merge 1 commit intogetsentry:developfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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