fix: uneval emits valid JS for graphs with more than 65534 repeated references - #176
Open
youdie006 wants to merge 2 commits into
Open
fix: uneval emits valid JS for graphs with more than 65534 repeated references#176youdie006 wants to merge 2 commits into
youdie006 wants to merge 2 commits into
Conversation
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 detectedLatest commit: e44e4db The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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.
Fixes #93.
unevalhoists 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:Repro:
Fix: 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 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.