Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Switch to object spreading rather than Object.assign #5635

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-cameras-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fast-check": major
---

♻️ Switch to object spreading rather than `Object.assign` (#5300)
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, constraints);
// 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
2 changes: 1 addition & 1 deletion website/docs/migration/from-3.x-to-4.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Simple migration guide to fast-check v4 starting from fast-check v3
| ECMAScript specification | ES2020 | ES2017 |
| TypeScript _(optional)_ | ≥5.0 | ≥4.1 |

Related pull requests: [#5577](https://github.com/dubzzz/fast-check/pull/5577), [#5605](https://github.com/dubzzz/fast-check/pull/5605), [#5617](https://github.com/dubzzz/fast-check/pull/5617), [#5634](https://github.com/dubzzz/fast-check/pull/5634)
Related pull requests: [#5577](https://github.com/dubzzz/fast-check/pull/5577), [#5605](https://github.com/dubzzz/fast-check/pull/5605), [#5617](https://github.com/dubzzz/fast-check/pull/5617), [#5634](https://github.com/dubzzz/fast-check/pull/5634), [#5635](https://github.com/dubzzz/fast-check/pull/5635)

## Update to latest v3.x

Expand Down
Loading