Skip to content

Commit

Permalink
♻️ Switch to object spreading rather than Object.assign (#5300)
Browse files Browse the repository at this point in the history
**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?
-->
  • Loading branch information
dubzzz authored Sep 27, 2024
1 parent 5c94bd9 commit 15fa6d0
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 15fa6d0

Please sign in to comment.