From 12f7333ebbb9824d0ba73c7d7ddbbaeeb2aed15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?wear=E5=B7=A5=E7=A8=8B=E5=B8=88?= <63706387+wearzdk@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:02:04 +0800 Subject: [PATCH 1/3] fix: fix no URL env --- src/is.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/is.ts b/src/is.ts index 438ea49..f7bafdc 100644 --- a/src/is.ts +++ b/src/is.ts @@ -84,4 +84,4 @@ export type TypedArray = InstanceType; export const isTypedArray = (payload: any): payload is TypedArray => ArrayBuffer.isView(payload) && !(payload instanceof DataView); -export const isURL = (payload: any): payload is URL => payload instanceof URL; +export const isURL = (payload: any): payload is URL => typeof URL !== 'undefined' && payload instanceof URL; From 9f179a57a5a649c9c70583d44375b28cdffb8159 Mon Sep 17 00:00:00 2001 From: wearzdk Date: Tue, 2 Sep 2025 21:18:48 +0800 Subject: [PATCH 2/3] test: add isURL test for environments without URL global --- src/is.test.ts | 11 +++++++++++ src/is.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/is.test.ts b/src/is.test.ts index 5f8e5e4..8137630 100644 --- a/src/is.test.ts +++ b/src/is.test.ts @@ -92,3 +92,14 @@ test('Regression: null-prototype object', () => { expect(isPlainObject(Object.create(null))).toBe(true); expect(isPrimitive(Object.create(null))).toBe(false); }); + +test('isURL without URL global', () => { + const originalURL = globalThis.URL; + // @ts-ignore + delete globalThis.URL; + + expect(() => isURL('https://example.com')).not.toThrow(); + expect(isURL('https://example.com')).toBe(false); + + globalThis.URL = originalURL; +}); diff --git a/src/is.ts b/src/is.ts index f7bafdc..8d7c5a9 100644 --- a/src/is.ts +++ b/src/is.ts @@ -84,4 +84,5 @@ export type TypedArray = InstanceType; export const isTypedArray = (payload: any): payload is TypedArray => ArrayBuffer.isView(payload) && !(payload instanceof DataView); -export const isURL = (payload: any): payload is URL => typeof URL !== 'undefined' && payload instanceof URL; +export const isURL = (payload: any): payload is URL => + typeof URL !== 'undefined' && payload instanceof URL; From 32e67c9db61a0382c688b99dc9325b967b150bcb Mon Sep 17 00:00:00 2001 From: wearzdk Date: Wed, 3 Sep 2025 11:08:04 +0800 Subject: [PATCH 3/3] lint: fix lint --- src/index.test.ts | 4 +++- src/index.ts | 7 +++++-- src/pathstringifier.test.ts | 12 ++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 570236b..7b7d27d 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1275,7 +1275,9 @@ test('doesnt iterate to keys that dont exist', () => { test('deserialize in place', () => { const serialized = SuperJSON.serialize({ a: new Date() }); const deserializedCopy = SuperJSON.deserialize(serialized); - const deserializedInPlace = SuperJSON.deserialize(serialized, { inPlace: true }); + const deserializedInPlace = SuperJSON.deserialize(serialized, { + inPlace: true, + }); expect(deserializedInPlace).toBe(serialized.json); expect(deserializedCopy).not.toBe(serialized.json); expect(deserializedCopy).toEqual(deserializedInPlace); diff --git a/src/index.ts b/src/index.ts index 9a11ad7..4fcd0bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,10 +60,13 @@ export default class SuperJSON { return res; } - deserialize(payload: SuperJSONResult, options?: { inPlace?: boolean }): T { + deserialize( + payload: SuperJSONResult, + options?: { inPlace?: boolean } + ): T { const { json, meta } = payload; - let result: T = options?.inPlace ? json : copy(json) as any; + let result: T = options?.inPlace ? json : (copy(json) as any); if (meta?.values) { result = applyValueAnnotations(result, meta.values, meta.v ?? 0, this); diff --git a/src/pathstringifier.test.ts b/src/pathstringifier.test.ts index b6ef6e4..e5fcd3e 100644 --- a/src/pathstringifier.test.ts +++ b/src/pathstringifier.test.ts @@ -22,12 +22,12 @@ describe('parsePath', () => { expect(parsePath(input, false)).toEqual(expectedOutput); }); - it.each([ - 'test\\a.b', - 'foo.bar.baz\\', - ])('parsePath(%p) is rejected', (input) => { - expect(() => parsePath(input, false)).toThrowError(); - }); + it.each(['test\\a.b', 'foo.bar.baz\\'])( + 'parsePath(%p) is rejected', + input => { + expect(() => parsePath(input, false)).toThrowError(); + } + ); }); describe('escapeKey', () => {