Skip to content

Commit

Permalink
♻️ Switch to object spreading rather than Object.assign
Browse files Browse the repository at this point in the history
As we dropped support for versions of Node not supporting object spreading we can now use it barely everywhere needed.

Fix #5299
  • Loading branch information
dubzzz authored Sep 27, 2024
1 parent 5c94bd9 commit d81eecd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
7 changes: 1 addition & 6 deletions packages/fast-check/src/arbitrary/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export type StringConstraints = StringSharedConstraints & {
unit?: 'grapheme' | 'grapheme-composite' | 'grapheme-ascii' | 'binary' | 'binary-ascii' | Arbitrary<string>;
};

const safeObjectAssign = Object.assign;

/** @internal */
function extractUnitArbitrary(constraints: Pick<StringConstraints, 'unit'>): Arbitrary<string> {
if (typeof constraints.unit === 'object') {
Expand Down Expand Up @@ -69,9 +67,6 @@ export function string(constraints: StringConstraints = {}): Arbitrary<string> {
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<string> = safeObjectAssign(safeObjectAssign({}, constraints), {
experimentalCustomSlices,
});
const enrichedConstraints: ArrayConstraintsInternal<string> = { ...constraints, experimentalCustomSlices };
return array(charArbitrary, enrichedConstraints).map(patternsToStringMapper, unmapper);
}
7 changes: 1 addition & 6 deletions packages/fast-check/src/arbitrary/webUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,10 +67,7 @@ export function webUrl(constraints?: WebUrlConstraints): Arbitrary<string> {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*
Expand Down Expand Up @@ -201,11 +199,11 @@ class ChainArbitrary<T, U> extends Arbitrary<U> {
: Stream.nil<Value<U>>()
).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<T, U> = safeObjectAssign(safeObjectAssign({}, context), {
const newContext: ChainArbitraryContext<T, U> = {
...context,
chainedContext: dst.context,
stoppedForOriginal: true,
});
};
return new Value(dst.value_, newContext);
}),
);
Expand Down
10 changes: 4 additions & 6 deletions packages/fast-check/src/check/runner/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ts>(
property: IRawProperty<Ts>,
Expand Down Expand Up @@ -100,10 +98,10 @@ function check<Ts>(rawProperty: IRawProperty<Ts>, params?: Parameters<Ts>): 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<Ts> = QualifiedParameters.read<Ts>(
// TODO - Move back to object spreading as soon as we bump support from es2017 to es2018+
safeObjectAssign(safeObjectAssign({}, readConfigureGlobal() as Parameters<Ts>), params),
);
const qParams: QualifiedParameters<Ts> = QualifiedParameters.read<Ts>({
...(readConfigureGlobal() as Parameters<Ts>),
...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())
Expand Down

0 comments on commit d81eecd

Please sign in to comment.