From 35c6772e56bea003ff003ec676e4637a0380dda4 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 16 Jul 2024 23:22:15 +0000 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=94=A7=20Toggle=20on=20`isolatedDec?= =?UTF-8?q?larations`=20flag=20on=20the=20project?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #5057 --- tsconfig.common.json | 3 ++- tsconfig.publish.json | 1 + tsconfig.publish.types.json | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tsconfig.common.json b/tsconfig.common.json index 7766a5f34e5..a0deb51b2f6 100644 --- a/tsconfig.common.json +++ b/tsconfig.common.json @@ -1,7 +1,8 @@ { "compilerOptions": { "noEmit": true, - "declaration": false, + "declaration": true, + "isolatedDeclarations": true, "incremental": false, "sourceMap": true, "target": "es2017", diff --git a/tsconfig.publish.json b/tsconfig.publish.json index 7abf8de509d..d2632ccb79d 100644 --- a/tsconfig.publish.json +++ b/tsconfig.publish.json @@ -3,6 +3,7 @@ "compilerOptions": { "noEmit": false, "declaration": false, + "isolatedDeclarations": false, "removeComments": true, "sourceMap": false } diff --git a/tsconfig.publish.types.json b/tsconfig.publish.types.json index abb33a7c0f6..4b2addcf4cd 100644 --- a/tsconfig.publish.types.json +++ b/tsconfig.publish.types.json @@ -4,6 +4,7 @@ "noEmit": false, "declaration": true, "emitDeclarationOnly": true, + "isolatedDeclarations": true, "removeComments": false, "sourceMap": false, "stripInternal": true From fcd9d5bf4c76a29ea10d8ce2cb27b409659a0c8b Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 16 Jul 2024 23:39:09 +0000 Subject: [PATCH 02/12] fix poisoning --- packages/poisoning/src/internals/PoisoningFreeArray.ts | 8 ++++---- packages/poisoning/src/internals/PoisoningFreeMap.ts | 8 ++++---- packages/poisoning/src/internals/PoisoningFreeSet.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/poisoning/src/internals/PoisoningFreeArray.ts b/packages/poisoning/src/internals/PoisoningFreeArray.ts index 9499276363c..b8811a47cf7 100644 --- a/packages/poisoning/src/internals/PoisoningFreeArray.ts +++ b/packages/poisoning/src/internals/PoisoningFreeArray.ts @@ -6,13 +6,13 @@ const safeArraySort = Array.prototype.sort; const safeObjectDefineProperty = Object.defineProperty; /** Alias for Array.prototype.map */ -export const MapSymbol = Symbol('safe.map'); +export const MapSymbol: unique symbol = Symbol('safe.map'); /** Alias for Array.prototype.push */ -export const PushSymbol = Symbol('safe.push'); +export const PushSymbol: unique symbol = Symbol('safe.push'); /** Alias for Array.prototype.shift */ -export const ShiftSymbol = Symbol('safe.shift'); +export const ShiftSymbol: unique symbol = Symbol('safe.shift'); /** Alias for Array.prototype.sort */ -export const SortSymbol = Symbol('safe.sort'); +export const SortSymbol: unique symbol = Symbol('safe.sort'); /** Array instance enriched with aliased methods that cannot be poisoned */ export type PoisoningFreeArray = Array & { diff --git a/packages/poisoning/src/internals/PoisoningFreeMap.ts b/packages/poisoning/src/internals/PoisoningFreeMap.ts index afa5e443077..d00074a6122 100644 --- a/packages/poisoning/src/internals/PoisoningFreeMap.ts +++ b/packages/poisoning/src/internals/PoisoningFreeMap.ts @@ -6,13 +6,13 @@ const safeMapSet = Map.prototype.set; const safeObjectDefineProperty = Object.defineProperty; /** Alias for Map.prototype.get */ -export const GetSymbol = Symbol('safe.get'); +export const GetSymbol: unique symbol = Symbol('safe.get'); /** Alias for Map.prototype.has */ -export const HasSymbol = Symbol('safe.has'); +export const HasSymbol: unique symbol = Symbol('safe.has'); /** Alias for Map.prototype.entries */ -export const EntriesSymbol = Symbol('safe.entries'); +export const EntriesSymbol: unique symbol = Symbol('safe.entries'); /** Alias for Map.prototype.set */ -export const SetSymbol = Symbol('safe.set'); +export const SetSymbol: unique symbol = Symbol('safe.set'); /** Map instance enriched with aliased methods that cannot be poisoned */ export type PoisoningFreeMap = Map & { diff --git a/packages/poisoning/src/internals/PoisoningFreeSet.ts b/packages/poisoning/src/internals/PoisoningFreeSet.ts index 975b4447701..feb4fe0d015 100644 --- a/packages/poisoning/src/internals/PoisoningFreeSet.ts +++ b/packages/poisoning/src/internals/PoisoningFreeSet.ts @@ -4,9 +4,9 @@ const safeSetHas = Set.prototype.has; const safeObjectDefineProperty = Object.defineProperty; /** Alias for Set.prototype.add */ -export const AddSymbol = Symbol('safe.add'); +export const AddSymbol: unique symbol = Symbol('safe.add'); /** Alias for Set.prototype.has */ -export const HasSymbol = Symbol('safe.has'); +export const HasSymbol: unique symbol = Symbol('safe.has'); /** Set instance enriched with aliased methods that cannot be poisoned */ export type PoisoningFreeSet = Set & { From 146beab8a2bee714ef79b45a4e939000032ede77 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 16 Jul 2024 23:56:41 +0000 Subject: [PATCH 03/12] fix some in fc --- packages/fast-check/src/check/symbols.ts | 2 +- packages/fast-check/src/utils/stringify.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/fast-check/src/check/symbols.ts b/packages/fast-check/src/check/symbols.ts index ef3affef15d..81cdec4d566 100644 --- a/packages/fast-check/src/check/symbols.ts +++ b/packages/fast-check/src/check/symbols.ts @@ -11,7 +11,7 @@ * @remarks Since 1.8.0 * @public */ -export const cloneMethod = Symbol.for('fast-check/cloneMethod'); +export const cloneMethod: unique symbol = Symbol.for('fast-check/cloneMethod'); /** * Object instance that should be cloned from one generation/shrink to another diff --git a/packages/fast-check/src/utils/stringify.ts b/packages/fast-check/src/utils/stringify.ts index 30bd239f639..4fbdd64ed81 100644 --- a/packages/fast-check/src/utils/stringify.ts +++ b/packages/fast-check/src/utils/stringify.ts @@ -28,7 +28,7 @@ const safePositiveInfinity = Number.POSITIVE_INFINITY; * @remarks Since 2.17.0 * @public */ -export const toStringMethod = Symbol.for('fast-check/toStringMethod'); +export const toStringMethod: unique symbol = Symbol.for('fast-check/toStringMethod'); /** * Interface to implement for {@link toStringMethod} * @@ -62,7 +62,7 @@ export function hasToStringMethod(instance: T): instance is T & WithToStringM * @remarks Since 2.17.0 * @public */ -export const asyncToStringMethod = Symbol.for('fast-check/asyncToStringMethod'); +export const asyncToStringMethod: unique symbol = Symbol.for('fast-check/asyncToStringMethod'); /** * Interface to implement for {@link asyncToStringMethod} * From 4dc1f789a7bfd4ce9fc18ad2741ca6bd93d7c9f8 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 6 Aug 2024 23:11:40 +0000 Subject: [PATCH 04/12] fix stream --- packages/fast-check/src/stream/Stream.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fast-check/src/stream/Stream.ts b/packages/fast-check/src/stream/Stream.ts index 29d49520464..0c29b40a5c9 100644 --- a/packages/fast-check/src/stream/Stream.ts +++ b/packages/fast-check/src/stream/Stream.ts @@ -55,7 +55,7 @@ export class Stream implements IterableIterator { next(): IteratorResult { return this.g.next(); } - [safeSymbolIterator](): IterableIterator { + [Symbol.iterator](): IterableIterator { // /*DEBUG*/ this.closeCurrentStream(); return this.g; } From 9a3c46460276b6c9645f48d1cd4ce2d82ea3704c Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 6 Aug 2024 23:15:29 +0000 Subject: [PATCH 05/12] fix wrapper --- .../src/check/model/commands/CommandWrapper.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/fast-check/src/check/model/commands/CommandWrapper.ts b/packages/fast-check/src/check/model/commands/CommandWrapper.ts index d859e07b6a0..660b2c9c3e5 100644 --- a/packages/fast-check/src/check/model/commands/CommandWrapper.ts +++ b/packages/fast-check/src/check/model/commands/CommandWrapper.ts @@ -3,6 +3,8 @@ import { hasAsyncToStringMethod, hasToStringMethod, toStringMethod, + WithAsyncToStringMethod, + WithToStringMethod, } from '../../../utils/stringify'; import { cloneMethod, hasCloneMethod } from '../../symbols'; import type { ICommand } from '../command/ICommand'; @@ -14,22 +16,20 @@ import type { ICommand } from '../command/ICommand'; export class CommandWrapper implements ICommand { - [toStringMethod]?: () => string; - [asyncToStringMethod]?: () => Promise; - hasRan = false; constructor(readonly cmd: ICommand) { if (hasToStringMethod(cmd)) { const method = cmd[toStringMethod]; - this[toStringMethod] = function toStringMethod(): string { + (this as unknown as WithToStringMethod)[toStringMethod] = function toStringMethod(): string { return method.call(cmd); }; } if (hasAsyncToStringMethod(cmd)) { const method = cmd[asyncToStringMethod]; - this[asyncToStringMethod] = function asyncToStringMethod(): Promise { - return method.call(cmd); - }; + (this as unknown as WithAsyncToStringMethod)[asyncToStringMethod] = + function asyncToStringMethod(): Promise { + return method.call(cmd); + }; } } check(m: Readonly): CheckAsync extends false ? boolean : Promise { From 1c74c1317ad0f560289254f959f6567ba613fcc8 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Tue, 6 Aug 2024 23:15:51 +0000 Subject: [PATCH 06/12] lint wrapper --- .../fast-check/src/check/model/commands/CommandWrapper.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/fast-check/src/check/model/commands/CommandWrapper.ts b/packages/fast-check/src/check/model/commands/CommandWrapper.ts index 660b2c9c3e5..08524151e90 100644 --- a/packages/fast-check/src/check/model/commands/CommandWrapper.ts +++ b/packages/fast-check/src/check/model/commands/CommandWrapper.ts @@ -1,10 +1,11 @@ +import type { + WithAsyncToStringMethod, + WithToStringMethod} from '../../../utils/stringify'; import { asyncToStringMethod, hasAsyncToStringMethod, hasToStringMethod, - toStringMethod, - WithAsyncToStringMethod, - WithToStringMethod, + toStringMethod } from '../../../utils/stringify'; import { cloneMethod, hasCloneMethod } from '../../symbols'; import type { ICommand } from '../command/ICommand'; From c41a10de55b3a8a988025c8d01a5ef2edad2d50e Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Wed, 7 Aug 2024 08:01:46 +0000 Subject: [PATCH 07/12] trick to pass isolatedDeclarations on unpublished --- .../check/model/commands/CommandsIterable.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/fast-check/src/check/model/commands/CommandsIterable.ts b/packages/fast-check/src/check/model/commands/CommandsIterable.ts index a4b855b4107..ecd9fb7cec8 100644 --- a/packages/fast-check/src/check/model/commands/CommandsIterable.ts +++ b/packages/fast-check/src/check/model/commands/CommandsIterable.ts @@ -1,4 +1,4 @@ -import { cloneMethod } from '../../symbols'; +import { cloneMethod, WithCloneMethod } from '../../symbols'; import type { CommandWrapper } from './CommandWrapper'; /** @@ -14,12 +14,6 @@ export class CommandsIterable> { return this.commands[Symbol.iterator](); } - [cloneMethod](): CommandsIterable { - return new CommandsIterable( - this.commands.map((c) => c.clone()), - this.metadataForReplay, - ); - } toString(): string { const serializedCommands = this.commands .filter((c) => c.hasRan) @@ -29,3 +23,17 @@ export class CommandsIterable)[cloneMethod] = + function ( + this: CommandsIterable, + ): CommandsIterable { + return new CommandsIterable( + this.commands.map((c) => c.clone()), + this.metadataForReplay, + ); + }; From 3c71345b5f6c7f74962c9633ecc26591a4857bbe Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sat, 10 Aug 2024 08:50:29 +0000 Subject: [PATCH 08/12] fix vitest and jest? --- packages/jest/src/internals/TestBuilder.ts | 6 ++---- packages/vitest/src/internals/TestBuilder.ts | 7 ++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/jest/src/internals/TestBuilder.ts b/packages/jest/src/internals/TestBuilder.ts index 0e0c344913e..2a4bdacbe7f 100644 --- a/packages/jest/src/internals/TestBuilder.ts +++ b/packages/jest/src/internals/TestBuilder.ts @@ -138,7 +138,7 @@ export type FastCheckItBuilder = T & /** * Build the enriched version of {it,test}, the one with added `.prop` */ -function enrichWithTestProp any>( +export function buildTest any>( testFn: T, jest: JestExtra, fc: FcExtra, @@ -148,7 +148,7 @@ function enrichWithTestProp any>( for (const key in testFn) { if (typeof testFn[key] === 'function') { atLeastOneExtra = true; - extraKeys[key] = key !== 'each' ? enrichWithTestProp(testFn[key] as any, jest, fc) : testFn[key]; + extraKeys[key] = key !== 'each' ? buildTest(testFn[key] as any, jest, fc) : testFn[key]; } } if (!atLeastOneExtra) { @@ -160,5 +160,3 @@ function enrichWithTestProp any>( } return Object.assign(enrichedTestFn, extraKeys) as FastCheckItBuilder; } - -export const buildTest = enrichWithTestProp; diff --git a/packages/vitest/src/internals/TestBuilder.ts b/packages/vitest/src/internals/TestBuilder.ts index 0e5789a1f07..9d9c4d2ec25 100644 --- a/packages/vitest/src/internals/TestBuilder.ts +++ b/packages/vitest/src/internals/TestBuilder.ts @@ -137,7 +137,7 @@ export type FastCheckItBuilder = T & /** * Build the enriched version of {it,test}, the one with added `.prop` */ -function enrichWithTestProp any>( +export function buildTest any>( testFn: T, fc: FcExtra, ancestors: Set = new Set(), @@ -148,8 +148,7 @@ function enrichWithTestProp any>( const key = unsafeKey as keyof typeof testFn & string; if (!ancestors.has(key) && typeof testFn[key] === 'function') { atLeastOneExtra = true; - extraKeys[key] = - key !== 'each' ? enrichWithTestProp(testFn[key] as any, fc, new Set([...ancestors, key])) : testFn[key]; + extraKeys[key] = key !== 'each' ? buildTest(testFn[key] as any, fc, new Set([...ancestors, key])) : testFn[key]; } } if (!atLeastOneExtra) { @@ -161,5 +160,3 @@ function enrichWithTestProp any>( } return Object.assign(enrichedTestFn, extraKeys) as FastCheckItBuilder; } - -export const buildTest = enrichWithTestProp; From 4212214d99183fb0e44432c5921e1018de42579e Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sat, 10 Aug 2024 09:20:06 +0000 Subject: [PATCH 09/12] Revert breaking parts --- .../check/model/commands/CommandWrapper.ts | 17 +++++++------- .../check/model/commands/CommandsIterable.ts | 22 ++++++------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/packages/fast-check/src/check/model/commands/CommandWrapper.ts b/packages/fast-check/src/check/model/commands/CommandWrapper.ts index 08524151e90..d859e07b6a0 100644 --- a/packages/fast-check/src/check/model/commands/CommandWrapper.ts +++ b/packages/fast-check/src/check/model/commands/CommandWrapper.ts @@ -1,11 +1,8 @@ -import type { - WithAsyncToStringMethod, - WithToStringMethod} from '../../../utils/stringify'; import { asyncToStringMethod, hasAsyncToStringMethod, hasToStringMethod, - toStringMethod + toStringMethod, } from '../../../utils/stringify'; import { cloneMethod, hasCloneMethod } from '../../symbols'; import type { ICommand } from '../command/ICommand'; @@ -17,20 +14,22 @@ import type { ICommand } from '../command/ICommand'; export class CommandWrapper implements ICommand { + [toStringMethod]?: () => string; + [asyncToStringMethod]?: () => Promise; + hasRan = false; constructor(readonly cmd: ICommand) { if (hasToStringMethod(cmd)) { const method = cmd[toStringMethod]; - (this as unknown as WithToStringMethod)[toStringMethod] = function toStringMethod(): string { + this[toStringMethod] = function toStringMethod(): string { return method.call(cmd); }; } if (hasAsyncToStringMethod(cmd)) { const method = cmd[asyncToStringMethod]; - (this as unknown as WithAsyncToStringMethod)[asyncToStringMethod] = - function asyncToStringMethod(): Promise { - return method.call(cmd); - }; + this[asyncToStringMethod] = function asyncToStringMethod(): Promise { + return method.call(cmd); + }; } } check(m: Readonly): CheckAsync extends false ? boolean : Promise { diff --git a/packages/fast-check/src/check/model/commands/CommandsIterable.ts b/packages/fast-check/src/check/model/commands/CommandsIterable.ts index ecd9fb7cec8..a4b855b4107 100644 --- a/packages/fast-check/src/check/model/commands/CommandsIterable.ts +++ b/packages/fast-check/src/check/model/commands/CommandsIterable.ts @@ -1,4 +1,4 @@ -import { cloneMethod, WithCloneMethod } from '../../symbols'; +import { cloneMethod } from '../../symbols'; import type { CommandWrapper } from './CommandWrapper'; /** @@ -14,6 +14,12 @@ export class CommandsIterable> { return this.commands[Symbol.iterator](); } + [cloneMethod](): CommandsIterable { + return new CommandsIterable( + this.commands.map((c) => c.clone()), + this.metadataForReplay, + ); + } toString(): string { const serializedCommands = this.commands .filter((c) => c.hasRan) @@ -23,17 +29,3 @@ export class CommandsIterable)[cloneMethod] = - function ( - this: CommandsIterable, - ): CommandsIterable { - return new CommandsIterable( - this.commands.map((c) => c.clone()), - this.metadataForReplay, - ); - }; From 26861e42c3d98721defbd72899163034e7932dc5 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Sat, 10 Aug 2024 09:21:30 +0000 Subject: [PATCH 10/12] Dropping isolatedDeclarations for fc --- packages/fast-check/tsconfig.json | 5 ++++- packages/fast-check/tsconfig.publish.types.json | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/fast-check/tsconfig.json b/packages/fast-check/tsconfig.json index 51bf44c3454..d9d57199ff6 100644 --- a/packages/fast-check/tsconfig.json +++ b/packages/fast-check/tsconfig.json @@ -1,3 +1,6 @@ { - "extends": "../../tsconfig.common.json" + "extends": "../../tsconfig.common.json", + "compilerOptions": { + "isolatedDeclarations": false + } } diff --git a/packages/fast-check/tsconfig.publish.types.json b/packages/fast-check/tsconfig.publish.types.json index db9f4fc2a17..b691e239a2d 100644 --- a/packages/fast-check/tsconfig.publish.types.json +++ b/packages/fast-check/tsconfig.publish.types.json @@ -1,7 +1,8 @@ { "extends": "../../tsconfig.publish.types.json", "compilerOptions": { - "outDir": "lib/types/" + "outDir": "lib/types/", + "isolatedDeclarations": false }, "include": ["src/"] } From 98851bc2c5f9a66b717df65d4f9c1c27ed263295 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Thu, 28 Nov 2024 19:11:22 +0000 Subject: [PATCH 11/12] drop useless, targeting next major rather than minor --- packages/fast-check/tsconfig.json | 4 +--- packages/fast-check/tsconfig.publish.types.json | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/fast-check/tsconfig.json b/packages/fast-check/tsconfig.json index d9d57199ff6..8457f39769a 100644 --- a/packages/fast-check/tsconfig.json +++ b/packages/fast-check/tsconfig.json @@ -1,6 +1,4 @@ { "extends": "../../tsconfig.common.json", - "compilerOptions": { - "isolatedDeclarations": false - } + "compilerOptions": {} } diff --git a/packages/fast-check/tsconfig.publish.types.json b/packages/fast-check/tsconfig.publish.types.json index b691e239a2d..db9f4fc2a17 100644 --- a/packages/fast-check/tsconfig.publish.types.json +++ b/packages/fast-check/tsconfig.publish.types.json @@ -1,8 +1,7 @@ { "extends": "../../tsconfig.publish.types.json", "compilerOptions": { - "outDir": "lib/types/", - "isolatedDeclarations": false + "outDir": "lib/types/" }, "include": ["src/"] } From 2d1d7e129fb3ce486cbd984545d36f013be496c8 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Thu, 28 Nov 2024 19:13:45 +0000 Subject: [PATCH 12/12] oups useless --- packages/fast-check/tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/fast-check/tsconfig.json b/packages/fast-check/tsconfig.json index 8457f39769a..51bf44c3454 100644 --- a/packages/fast-check/tsconfig.json +++ b/packages/fast-check/tsconfig.json @@ -1,4 +1,3 @@ { - "extends": "../../tsconfig.common.json", - "compilerOptions": {} + "extends": "../../tsconfig.common.json" }