Skip to content

Commit d81eecd

Browse files
authored
♻️ Switch to object spreading rather than Object.assign
As we dropped support for versions of Node not supporting object spreading we can now use it barely everywhere needed. Fix #5299
1 parent 5c94bd9 commit d81eecd

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, unmapper);
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)