From 15fa6d04cc841a8e59a40a031290ae9104f50eae Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Fri, 27 Sep 2024 22:40:30 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Switch=20to=20object=20spr?= =?UTF-8?q?eading=20rather=20than=20`Object.assign`=20(#5300)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** As we dropped support for versions of Node not supporting object spreading we can now use it barely everywhere needed. Fix #5299 **Checklist** — _Don't delete this checklist and make sure you do the following before opening the PR_ - [x] The name of my PR follows [gitmoji](https://gitmoji.dev/) specification - [x] My PR references one of several related issues (if any) - [x] New features or breaking changes must come with an associated Issue or Discussion - [x] My PR does not add any new dependency without an associated Issue or Discussion - [x] My PR includes bumps details, please run `yarn bump` and flag the impacts properly - [x] My PR adds relevant tests and they would have failed without my PR (when applicable) **Advanced** - [x] Category: Refactoring - [x] Impacts: Force users to rely on more modern versions of Node --- packages/fast-check/src/arbitrary/string.ts | 7 +------ packages/fast-check/src/arbitrary/webUrl.ts | 7 +------ .../src/check/arbitrary/definition/Arbitrary.ts | 8 +++----- packages/fast-check/src/check/runner/Runner.ts | 10 ++++------ 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/packages/fast-check/src/arbitrary/string.ts b/packages/fast-check/src/arbitrary/string.ts index c251011903b..bf5baecf7c4 100644 --- a/packages/fast-check/src/arbitrary/string.ts +++ b/packages/fast-check/src/arbitrary/string.ts @@ -35,8 +35,6 @@ export type StringConstraints = StringSharedConstraints & { unit?: 'grapheme' | 'grapheme-composite' | 'grapheme-ascii' | 'binary' | 'binary-ascii' | Arbitrary; }; -const safeObjectAssign = Object.assign; - /** @internal */ function extractUnitArbitrary(constraints: Pick): Arbitrary { if (typeof constraints.unit === 'object') { @@ -69,9 +67,6 @@ export function string(constraints: StringConstraints = {}): Arbitrary { const charArbitrary = extractUnitArbitrary(constraints); const unmapper = patternsToStringUnmapperFor(charArbitrary, constraints); const experimentalCustomSlices = createSlicesForString(charArbitrary, unmapper); - // TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+ - const enrichedConstraints: ArrayConstraintsInternal = safeObjectAssign(safeObjectAssign({}, constraints), { - experimentalCustomSlices, - }); + const enrichedConstraints: ArrayConstraintsInternal = { ...constraints, experimentalCustomSlices }; return array(charArbitrary, enrichedConstraints).map(patternsToStringMapper, unmapper); } diff --git a/packages/fast-check/src/arbitrary/webUrl.ts b/packages/fast-check/src/arbitrary/webUrl.ts index 1b6cc979632..0bb1dc7686e 100644 --- a/packages/fast-check/src/arbitrary/webUrl.ts +++ b/packages/fast-check/src/arbitrary/webUrl.ts @@ -12,8 +12,6 @@ import type { SizeForArbitrary } from './_internals/helpers/MaxLengthFromMinLeng import { relativeSizeToSize, resolveSize } from './_internals/helpers/MaxLengthFromMinLength'; import { webPath } from './webPath'; -const safeObjectAssign = Object.assign; - /** * Constraints to be applied on {@link webUrl} * @remarks Since 1.14.0 @@ -69,10 +67,7 @@ export function webUrl(constraints?: WebUrlConstraints): Arbitrary { c.authoritySettings !== undefined && c.authoritySettings.size !== undefined ? relativeSizeToSize(c.authoritySettings.size, resolvedSize) : resolvedSize; - // TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+ - const resolvedAuthoritySettings = safeObjectAssign(safeObjectAssign({}, c.authoritySettings), { - size: resolvedAuthoritySettingsSize, - }); + const resolvedAuthoritySettings = { ...c.authoritySettings, size: resolvedAuthoritySettingsSize }; const validSchemes = c.validSchemes || ['http', 'https']; const schemeArb = constantFrom(...validSchemes); const authorityArb = webAuthority(resolvedAuthoritySettings); diff --git a/packages/fast-check/src/check/arbitrary/definition/Arbitrary.ts b/packages/fast-check/src/check/arbitrary/definition/Arbitrary.ts index f5b95522206..c077626a7a5 100644 --- a/packages/fast-check/src/check/arbitrary/definition/Arbitrary.ts +++ b/packages/fast-check/src/check/arbitrary/definition/Arbitrary.ts @@ -3,8 +3,6 @@ import { Stream } from '../../../stream/Stream'; import { cloneMethod, hasCloneMethod } from '../../symbols'; import { Value } from './Value'; -const safeObjectAssign = Object.assign; - /** * Abstract class able to generate values on type `T` * @@ -201,11 +199,11 @@ class ChainArbitrary extends Arbitrary { : Stream.nil>() ).join( context.chainedArbitrary.shrink(value, context.chainedContext).map((dst) => { - // TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+ - const newContext: ChainArbitraryContext = safeObjectAssign(safeObjectAssign({}, context), { + const newContext: ChainArbitraryContext = { + ...context, chainedContext: dst.context, stoppedForOriginal: true, - }); + }; return new Value(dst.value_, newContext); }), ); diff --git a/packages/fast-check/src/check/runner/Runner.ts b/packages/fast-check/src/check/runner/Runner.ts index e6378dcb552..f8fa67cf158 100644 --- a/packages/fast-check/src/check/runner/Runner.ts +++ b/packages/fast-check/src/check/runner/Runner.ts @@ -17,8 +17,6 @@ import type { IAsyncProperty } from '../property/AsyncProperty'; import type { IProperty } from '../property/Property'; import type { Value } from '../arbitrary/definition/Value'; -const safeObjectAssign = Object.assign; - /** @internal */ function runIt( property: IRawProperty, @@ -100,10 +98,10 @@ function check(rawProperty: IRawProperty, params?: Parameters): unkn throw new Error('Invalid property encountered, please use a valid property'); if (rawProperty.run == null) throw new Error('Invalid property encountered, please use a valid property not an arbitrary'); - const qParams: QualifiedParameters = QualifiedParameters.read( - // TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+ - safeObjectAssign(safeObjectAssign({}, readConfigureGlobal() as Parameters), params), - ); + const qParams: QualifiedParameters = QualifiedParameters.read({ + ...(readConfigureGlobal() as Parameters), + ...params, + }); if (qParams.reporter !== null && qParams.asyncReporter !== null) throw new Error('Invalid parameters encountered, reporter and asyncReporter cannot be specified together'); if (qParams.asyncReporter !== null && !rawProperty.isAsync())