+1
-1
| { | ||
| "name": "devalue", | ||
| "description": "Gets the job done when JSON.stringify can't", | ||
| "version": "5.9.0", | ||
| "version": "5.9.1", | ||
| "repository": "sveltejs/devalue", | ||
@@ -6,0 +6,0 @@ "sideEffects": false, |
+30
-6
@@ -293,3 +293,3 @@ import { | ||
| if (!names.has(thing.buffer)) { | ||
| str += `([${stringify_typed_array_elements(new thing.constructor(thing.buffer))}])`; | ||
| str += `([${stringify_typed_array_elements(type, thing.buffer)}])`; | ||
| } else { | ||
@@ -455,3 +455,3 @@ str += `(${stringify(thing.buffer)})`; | ||
| if (!names.has(thing.buffer)) { | ||
| str += `([${stringify_typed_array_elements(new thing.constructor(thing.buffer))}])`; | ||
| str += `([${stringify_typed_array_elements(type, thing.buffer)}])`; | ||
| } else { | ||
@@ -520,2 +520,10 @@ str += `(${stringify(thing.buffer)})`; | ||
| const body = [...reconstructions, ...statements].join(';'); | ||
| // A function may have at most 65535 parameters (and a call at most that | ||
| // many arguments). For very large graphs, pass the hoisted values as a | ||
| // single array argument and destructure them into the placeholder names, | ||
| // so the emitted code stays within the engine limit (#93). | ||
| if (params.length > 65534) { | ||
| return `(function(){var[${params.join(',')}]=arguments[0];${body}}([${values.join(',')}]))`; | ||
| } | ||
| return `(function(${params.join(',')}){${body}}(${values.join(',')}))`; | ||
@@ -528,12 +536,28 @@ } else { | ||
| /** | ||
| * Serialize the elements of a typed array as a comma-separated list. | ||
| * Serialize the elements of `buffer`, read as `type`, as a comma-separated list. | ||
| * The view is created from `type` rather than from the serialized value's own | ||
| * constructor, which may be a subclass like Node's `Buffer` whose `toString` | ||
| * decodes the bytes instead of listing them. | ||
| * `BigInt64Array`/`BigUint64Array` elements are bigints and must be written | ||
| * with an `n` suffix, otherwise the emitted `new BigInt64Array([...])` throws. | ||
| * @param {import('./types.js').TypedArray} array | ||
| * @param {string} type | ||
| * @param {ArrayBufferLike} buffer | ||
| */ | ||
| function stringify_typed_array_elements(array) { | ||
| if (array instanceof BigInt64Array || array instanceof BigUint64Array) { | ||
| function stringify_typed_array_elements(type, buffer) { | ||
| const array = new (/** @type {any} */ (globalThis)[type])(buffer); | ||
| if (type === 'BigInt64Array' || type === 'BigUint64Array') { | ||
| return Array.from(array, (element) => `${element}n`).join(','); | ||
| } | ||
| // Float arrays can hold `-0`, which `toString()` collapses to `"0"`, silently | ||
| // losing the sign on round-trip. Emit `-0` explicitly for those elements. | ||
| if ( | ||
| array instanceof Float32Array || | ||
| array instanceof Float64Array || | ||
| (typeof Float16Array !== 'undefined' && array instanceof Float16Array) | ||
| ) { | ||
| return Array.from(array, (element) => (Object.is(element, -0) ? '-0' : `${element}`)).join(','); | ||
| } | ||
| return array.toString(); | ||
@@ -540,0 +564,0 @@ } |
103061
1.06%2446
0.87%