fix: emit valid JS for BigInt64Array and BigUint64Array in uneval - #171
Merged
Conversation
uneval rendered typed-array elements by interpolating the array directly, which calls Array#toString and produces bare numbers (e.g. new BigInt64Array([1,2,3])). BigInt64Array/BigUint64Array constructors require bigint elements, so the emitted code threw 'Cannot convert 1 to a BigInt' when evaluated. Emit bigint elements with an 'n' suffix. stringify/parse were unaffected (they encode the underlying buffer as base64).
🦋 Changeset detectedLatest commit: 8bc2da9 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 |
Rich-Harris
approved these changes
Jul 18, 2026
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.
Problem
unevalrenders typed-array elements by interpolating the array directly into a template string, which invokesArray#toStringand produces bare numbers:But the
BigInt64Array/BigUint64Arrayconstructors require bigint elements, so the emitted code throws when evaluated:This affects any
BigInt64Array/BigUint64Arraywhose buffer isn't separately shared (the common case), including subarrays. There was previously no test coverage for these two types.Fix
Emit bigint elements with an
nsuffix (e.g.new BigInt64Array([1n,2n,3n])) via a smallstringify_typed_array_elementshelper used by both the inline and the deduplicated (hoisted) code paths. Non-bigint typed arrays are unchanged.Scope
stringify/parsewere not affected — they encode the underlyingArrayBufferas base64 and rebuild the view from bytes, so elements are never stringified individually.unevalshared-buffer path was also already correct (it reconstructs from the buffer); only the inline-elements path was broken.Tests
Adds fixtures for
BigInt64Array(with a negative value) andBigUint64Array, plus a repetition fixture, which run through the existinguneval/stringify/parse/ round-trip harnesses.