Skip to content

fix: uneval emits valid JS for graphs with more than 65534 repeated references - #176

Open
youdie006 wants to merge 2 commits into
sveltejs:mainfrom
youdie006:fix/uneval-param-limit
Open

fix: uneval emits valid JS for graphs with more than 65534 repeated references#176
youdie006 wants to merge 2 commits into
sveltejs:mainfrom
youdie006:fix/uneval-param-limit

Conversation

@youdie006

Copy link
Copy Markdown

Fixes #93.

uneval hoists every value referenced more than once into a parameter of a single IIFE ((function(a,b,c){...}(1,2,3))). A function may have at most 65535 parameters, so a graph with more than ~65534 repeated references produces code that engines reject:

SyntaxError: Too many parameters in function definition (only 65534 allowed)

Repro:

const shared = Array.from({ length: 70000 }, () => ({}));
uneval({ a: shared, b: shared.slice() }); // the output throws when eval'd

Fix: when the parameter count exceeds the limit, pass the hoisted values as a single array argument and destructure them into the placeholder names:

(function(){var[a,b,c]=arguments[0];...}([1,2,3]))

instead of one parameter each. This also avoids the analogous too-many-arguments limit on the call. Graphs below the threshold are byte-for-byte unchanged.

Test: added a case that uneval-serializes a graph with 70,000 repeated references and evals the output, asserting the round-trip and shared identity. Verified red before the fix (Too many parameters in function definition) and green after. npm test (uvu) passes: 723 + 29 + 18.


Disclosure: developed with the assistance of Claude Code (AI); reviewed and verified by me.

uneval hoists every value that is referenced more than once into a
parameter of a single IIFE. A function may have at most 65535
parameters, so a graph with more than that many repeated references
produced code that engines reject with "Too many parameters in
function definition".

When the parameter count exceeds the limit, pass the hoisted values as
a single array argument and destructure them into the placeholder
names instead of using one parameter each. Smaller graphs are
unchanged.
@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e44e4db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
devalue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

Eval breaks when params exceeds 65534 in chrome - (SyntaxError: Too many parameters in function definition (only 65534 allowed))

1 participant