Skip to content

Commit 19c62dc

Browse files
authored
♻️ Switch to object spreading rather than Object.assign (#5300)
**Description** <!-- Please provide a short description and potentially linked issues justifying the need for this PR --> As we dropped support for versions of Node not supporting object spreading we can now use it barely everywhere needed. Fix #5299 <!-- * Your PR is fixing a bug or regression? Check for existing issues related to this bug and link them --> <!-- * Your PR is adding a new feature? Make sure there is a related issue or discussion attached to it --> <!-- You can provide any additional context to help into understanding what's this PR is attempting to solve: reproduction of a bug, code snippets... --> **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) <!-- More about contributing at https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md --> **Advanced** <!-- How to fill the advanced section is detailed below! --> - [x] Category: Refactoring - [x] Impacts: Force users to rely on more modern versions of Node <!-- [Category] Please use one of the categories below, it will help us into better understanding the urgency of the PR --> <!-- * ✨ Introduce new features --> <!-- * 📝 Add or update documentation --> <!-- * ✅ Add or update tests --> <!-- * 🐛 Fix a bug --> <!-- * 🏷️ Add or update types --> <!-- * ⚡️ Improve performance --> <!-- * _Other(s):_ ... --> <!-- [Impacts] Please provide a comma separated list of the potential impacts that might be introduced by this change --> <!-- * Generated values: Can your change impact any of the existing generators in terms of generated values, if so which ones? when? --> <!-- * Shrink values: Can your change impact any of the existing generators in terms of shrink values, if so which ones? when? --> <!-- * Performance: Can it require some typings changes on user side? Please give more details --> <!-- * Typings: Is there a potential performance impact? In which cases? -->
1 parent 998f001 commit 19c62dc

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

packages/fast-check/src/arbitrary/string.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ export type StringConstraints = StringSharedConstraints & {
3535
unit?: 'grapheme' | 'grapheme-composite' | 'grapheme-ascii' | 'binary' | 'binary-ascii' | Arbitrary<string>;
3636
};
3737

38-
const safeObjectAssign = Object.assign;
39-
4038
/** @internal */
4139
function extractUnitArbitrary(constraints: Pick<StringConstraints, 'unit'>): Arbitrary<string> {
4240
if (typeof constraints.unit === 'object') {
@@ -69,9 +67,6 @@ export function string(constraints: StringConstraints = {}): Arbitrary<string> {
6967
const charArbitrary = extractUnitArbitrary(constraints);
7068
const unmapper = patternsToStringUnmapperFor(charArbitrary, constraints);
7169
const experimentalCustomSlices = createSlicesForString(charArbitrary, constraints);
72-
// TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+
73-
const enrichedConstraints: ArrayConstraintsInternal<string> = safeObjectAssign(safeObjectAssign({}, constraints), {
74-
experimentalCustomSlices,
75-
});
70+
const enrichedConstraints: ArrayConstraintsInternal<string> = { ...constraints, experimentalCustomSlices };
7671
return array(charArbitrary, enrichedConstraints).map(patternsToStringMapper, unmapper);
7772
}

packages/fast-check/src/arbitrary/webUrl.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import type { SizeForArbitrary } from './_internals/helpers/MaxLengthFromMinLeng
1212
import { relativeSizeToSize, resolveSize } from './_internals/helpers/MaxLengthFromMinLength';
1313
import { webPath } from './webPath';
1414

15-
const safeObjectAssign = Object.assign;
16-
1715
/**
1816
* Constraints to be applied on {@link webUrl}
1917
* @remarks Since 1.14.0
@@ -69,10 +67,7 @@ export function webUrl(constraints?: WebUrlConstraints): Arbitrary<string> {
6967
c.authoritySettings !== undefined && c.authoritySettings.size !== undefined
7068
? relativeSizeToSize(c.authoritySettings.size, resolvedSize)
7169
: resolvedSize;
72-
// TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+
73-
const resolvedAuthoritySettings = safeObjectAssign(safeObjectAssign({}, c.authoritySettings), {
74-
size: resolvedAuthoritySettingsSize,
75-
});
70+
const resolvedAuthoritySettings = { ...c.authoritySettings, size: resolvedAuthoritySettingsSize };
7671
const validSchemes = c.validSchemes || ['http', 'https'];
7772
const schemeArb = constantFrom(...validSchemes);
7873
const authorityArb = webAuthority(resolvedAuthoritySettings);

packages/fast-check/src/check/arbitrary/definition/Arbitrary.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { Stream } from '../../../stream/Stream';
33
import { cloneMethod, hasCloneMethod } from '../../symbols';
44
import { Value } from './Value';
55

6-
const safeObjectAssign = Object.assign;
7-
86
/**
97
* Abstract class able to generate values on type `T`
108
*
@@ -201,11 +199,11 @@ class ChainArbitrary<T, U> extends Arbitrary<U> {
201199
: Stream.nil<Value<U>>()
202200
).join(
203201
context.chainedArbitrary.shrink(value, context.chainedContext).map((dst) => {
204-
// TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+
205-
const newContext: ChainArbitraryContext<T, U> = safeObjectAssign(safeObjectAssign({}, context), {
202+
const newContext: ChainArbitraryContext<T, U> = {
203+
...context,
206204
chainedContext: dst.context,
207205
stoppedForOriginal: true,
208-
});
206+
};
209207
return new Value(dst.value_, newContext);
210208
}),
211209
);

packages/fast-check/src/check/runner/Runner.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import type { IAsyncProperty } from '../property/AsyncProperty';
1717
import type { IProperty } from '../property/Property';
1818
import type { Value } from '../arbitrary/definition/Value';
1919

20-
const safeObjectAssign = Object.assign;
21-
2220
/** @internal */
2321
function runIt<Ts>(
2422
property: IRawProperty<Ts>,
@@ -100,10 +98,10 @@ function check<Ts>(rawProperty: IRawProperty<Ts>, params?: Parameters<Ts>): unkn
10098
throw new Error('Invalid property encountered, please use a valid property');
10199
if (rawProperty.run == null)
102100
throw new Error('Invalid property encountered, please use a valid property not an arbitrary');
103-
const qParams: QualifiedParameters<Ts> = QualifiedParameters.read<Ts>(
104-
// TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+
105-
safeObjectAssign(safeObjectAssign({}, readConfigureGlobal() as Parameters<Ts>), params),
106-
);
101+
const qParams: QualifiedParameters<Ts> = QualifiedParameters.read<Ts>({
102+
...(readConfigureGlobal() as Parameters<Ts>),
103+
...params,
104+
});
107105
if (qParams.reporter !== null && qParams.asyncReporter !== null)
108106
throw new Error('Invalid parameters encountered, reporter and asyncReporter cannot be specified together');
109107
if (qParams.asyncReporter !== null && !rawProperty.isAsync())

0 commit comments

Comments
 (0)