Skip to content

fix(deps): patch @sveltejs/acorn-typescript with upstream PR #84 - #7140

Draft
JakeChampion wants to merge 1 commit into
mainfrom
jake/patch-acorn-typescript-pr84
Draft

fix(deps): patch @sveltejs/acorn-typescript with upstream PR #84#7140
JakeChampion wants to merge 1 commit into
mainfrom
jake/patch-acorn-typescript-pr84

Conversation

@JakeChampion

Copy link
Copy Markdown
Contributor

What

Patches @sveltejs/acorn-typescript@1.0.11 to include upstream sveltejs/acorn-typescript#84 ("make parse branches transactional") via patch-package.

Why

The bundled parser in 1.0.11 corrupts scope state when restoring speculative parse branches. This surfaces in edge-bundler's import-attribute rewriter (rewriteSourceImportAssertions) as Export 'X' is not defined on some compiled JS bundles - a leading cause of "Dry run: Eszip successful, tarball bundle generation failed" errors (e.g. unpdf's pdfjs.mjs, ~596 daily failure events).

Minimal repro that fails on stock 1.0.9-1.0.11 and passes with this patch:

function m(){_?(t):(t=(function(){t>>5}))};var en=1;export{en as X};

PR #84 fixes the class of scope-corruption bug but is unmerged and unreleased upstream, so it is applied locally.

How

  • Added patch-package as a devDependency and a root postinstall: patch-package script.
  • patches/@sveltejs+acorn-typescript+1.0.11.patch is the rebuilt bundled index.js from the PR Simplify code related to lifecycle reducer #84 branch.
  • The build was reproduced with the package's own command (esbuild src/index.ts --bundle --format=esm --platform=node --external:acorn). esbuild 0.25.5 rebuilds the released source byte-for-byte identical to the shipped index.js, so the patch contains only PR Simplify code related to lifecycle reducer #84's real changes (466 lines / 21 hunks, no toolchain noise). index.d.ts is unchanged by the PR.

Verification

  • npm install applies the patch via postinstall; re-applies idempotently.
  • Patched parser parses the minimal repro and general TS/JSX.
  • packages/edge-bundler builds cleanly (tsc) against the patched dep.

Follow-up

The patch is pinned to 1.0.11. It will need regenerating when the dependency is bumped or when the fix lands upstream; patch-package warns (does not silently skip) on a version mismatch.

🤖 Generated with Claude Code

The bundled parser in @sveltejs/acorn-typescript@1.0.11 corrupts scope
state when restoring speculative parse branches, causing edge-bundler's
import-attribute rewriter to throw "Export X is not defined" on some
compiled JS bundles (e.g. unpdf's pdfjs.mjs) - a leading cause of
"tarball bundle generation failed" dry-run errors.

Upstream sveltejs/acorn-typescript#84 ("make parse branches
transactional") fixes it but is unmerged and unreleased, so apply it
locally via patch-package. The patch is the rebuilt bundled index.js
from the PR branch (esbuild 0.25.5 reproduces the shipped bundle
byte-for-byte; index.d.ts is unchanged by the PR).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@JakeChampion
JakeChampion requested a review from a team as a code owner July 22, 2026 16:07
@JakeChampion
JakeChampion marked this pull request as draft July 22, 2026 16:07
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c9b016af-d313-4d01-840d-ba2ea3b6d2e3

📥 Commits

Reviewing files that changed from the base of the PR and between 7e468bb and f63e4e3.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json
  • patches/@sveltejs+acorn-typescript+1.0.11.patch
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • netlify/blueprints (manual)

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved TypeScript parsing reliability, particularly for speculative parsing and complex syntax.
    • Ensured parser state and emitted comments are handled consistently when parsing branches succeed or fail.
  • Maintenance
    • Added automatic application of required dependency patches during installation.

Walkthrough

The package adds a postinstall script and declares patch-package. The patch updates the TypeScript parser plugin with parser-state snapshot and restoration utilities, transactional callback buffering, revised lookahead state, and changed comment callback handling. Speculative parsing APIs and their call sites now restore parser state and select buffered parse-branch results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: serhalp

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately names the dependency patch and the upstream PR being applied.
Description check ✅ Passed The description covers what, why, how, verification, and follow-up, but omits the template's issue reference.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jake/patch-acorn-typescript-pr84

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.8)
package.json

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Dependency Size Changes

Warning

This PR adds 603.9 kB of new dependencies, which exceeds the threshold of 100 kB.

📦 Package 📏 Size
patch-package@8.0.1 413 kB
fs-extra@10.1.0 63.3 kB
open@7.4.2 41.9 kB
json-stable-stringify@1.3.0 36.4 kB
jsonify@0.0.1 19.4 kB
find-yarn-workspace-root@2.0.0 16.7 kB
klaw-sync@6.0.0 10.4 kB
slash@2.0.0 2.8 kB

Total size change: 603.9 kB

@pkg-pr-new

pkg-pr-new Bot commented Jul 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@netlify/build

npm i https://pkg.pr.new/@netlify/build@7140

@netlify/build-info

npm i https://pkg.pr.new/@netlify/build-info@7140

@netlify/cache-utils

npm i https://pkg.pr.new/@netlify/cache-utils@7140

@netlify/config

npm i https://pkg.pr.new/@netlify/config@7140

@netlify/edge-bundler

npm i https://pkg.pr.new/@netlify/edge-bundler@7140

@netlify/functions-utils

npm i https://pkg.pr.new/@netlify/functions-utils@7140

@netlify/git-utils

npm i https://pkg.pr.new/@netlify/git-utils@7140

@netlify/headers-parser

npm i https://pkg.pr.new/@netlify/headers-parser@7140

@netlify/api

npm i https://pkg.pr.new/@netlify/api@7140

@netlify/nock-udp

npm i https://pkg.pr.new/@netlify/nock-udp@7140

@netlify/opentelemetry-sdk-setup

npm i https://pkg.pr.new/@netlify/opentelemetry-sdk-setup@7140

@netlify/opentelemetry-utils

npm i https://pkg.pr.new/@netlify/opentelemetry-utils@7140

@netlify/redirect-parser

npm i https://pkg.pr.new/@netlify/redirect-parser@7140

@netlify/run-utils

npm i https://pkg.pr.new/@netlify/run-utils@7140

@netlify/zip-it-and-ship-it

npm i https://pkg.pr.new/@netlify/zip-it-and-ship-it@7140

commit: f63e4e3

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.

1 participant