@fast-check/codemod 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +205 -2
  3. package/lib/allowAwait-GB5WG8dx.js +48 -0
  4. package/lib/cli.d.ts +1 -0
  5. package/lib/cli.js +49 -0
  6. package/lib/fastCheck-BCuGakPT.js +51 -0
  7. package/lib/pluginMigration-TF34gzVd.js +215 -0
  8. package/lib/reportUnsupported-DY7wlHET.js +7 -0
  9. package/lib/sampling-eUHO0ySk.js +26 -0
  10. package/lib/transforms/v5/checkToAssert.d.ts +2 -0
  11. package/lib/transforms/v5/checkToAssert.js +72 -0
  12. package/lib/transforms/v5/defaultImport.d.ts +2 -0
  13. package/lib/transforms/v5/defaultImport.js +30 -0
  14. package/lib/transforms/v5/lifecyclePlugins.d.ts +2 -0
  15. package/lib/transforms/v5/lifecyclePlugins.js +211 -0
  16. package/lib/transforms/v5/propertyToAsyncProperty.d.ts +2 -0
  17. package/lib/transforms/v5/propertyToAsyncProperty.js +135 -0
  18. package/lib/transforms/v5/randomMethods.d.ts +2 -0
  19. package/lib/transforms/v5/randomMethods.js +65 -0
  20. package/lib/transforms/v5/randomTypeFactory.d.ts +2 -0
  21. package/lib/transforms/v5/randomTypeFactory.js +64 -0
  22. package/lib/transforms/v5/runnerPlugins.d.ts +2 -0
  23. package/lib/transforms/v5/runnerPlugins.js +139 -0
  24. package/lib/transforms/v5/sample.d.ts +2 -0
  25. package/lib/transforms/v5/sample.js +32 -0
  26. package/lib/transforms/v5/statistics.d.ts +2 -0
  27. package/lib/transforms/v5/statistics.js +56 -0
  28. package/lib/transforms/v5/stringUnit.d.ts +2 -0
  29. package/lib/transforms/v5/stringUnit.js +64 -0
  30. package/lib/transforms/v6/asyncPropertyToProperty.d.ts +2 -0
  31. package/lib/transforms/v6/asyncPropertyToProperty.js +50 -0
  32. package/package.json +70 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nicolas DUBIEN
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,206 @@
1
- # Temporary Holding Version
1
+ # `@fast-check/codemod`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ![fast-check logo](https://fast-check.dev/assets/images/logo.png)
4
+
5
+ Codemods to help upgrade projects using `fast-check`.
6
+
7
+ ## Getting Started
8
+
9
+ Requires Node.js 22.12.0 or later. Run a transform on a file or directory:
10
+
11
+ ```sh
12
+ npx @fast-check/codemod@latest <transform> <path>
13
+ ```
14
+
15
+ Add `--dry --print` to preview changes without writing files. Commit your work before running a codemod, then review the diff.
16
+
17
+ Patterns that require manual migration are left unchanged and reported with their file, line, column and an explanation. These warnings do not fail the codemod.
18
+
19
+ ## Transforms
20
+
21
+ ### Migrate to v5
22
+
23
+ <details><summary><code>v5/defaultImport</code> (≥1.0.0)<sup><a href="#minimum-fast-check-version">(1)</a></sup> — Replaces default imports with namespace imports</summary>
24
+
25
+ **What is doing this codemod?**
26
+
27
+ This codemod replaces default imports from `fast-check` with namespace imports. It also handles `import type` and preserves any named imports in a separate declaration.
28
+
29
+ **Example of code change:**
30
+
31
+ ```diff
32
+ -import fc from 'fast-check';
33
+ +import * as fc from 'fast-check';
34
+ ```
35
+
36
+ </details>
37
+
38
+ <details><summary><code>v5/randomMethods</code> (≥1.0.0) — Migrates removed Random methods to bounded nextInt calls</summary>
39
+
40
+ **What is doing this codemod?**
41
+
42
+ This codemod replaces calls to `next(bits)`, `nextInt()`, `nextBoolean()` and `nextDouble()` with expressions using bounded `nextInt` calls. These methods have been dropped in `5.x`.
43
+
44
+ **Example of code change:**
45
+
46
+ ```diff
47
+ -rng.nextBoolean();
48
+ +rng.nextInt(0, 1) === 1;
49
+ ```
50
+
51
+ </details>
52
+
53
+ <details><summary><code>v5/stringUnit</code> (≥3.23.0) — Migrates Unicode flags on object and JSON arbitraries</summary>
54
+
55
+ **What is doing this codemod?**
56
+
57
+ This codemod replaces inline boolean `withUnicodeString` and `noUnicodeString` flags on `object`, `anything`, `json` and `jsonValue` with the corresponding `stringUnit` option. When the options already include `stringUnit`, it drops the redundant literal flag.
58
+
59
+ **Example of code change:**
60
+
61
+ ```diff
62
+ -fc.object({ withUnicodeString: true });
63
+ +fc.object({ stringUnit: 'binary' });
64
+ ```
65
+
66
+ </details>
67
+
68
+ <details><summary><code>v5/randomTypeFactory</code> (≥4.6.0) — Imports pure-rand v8 generator factories</summary>
69
+
70
+ **What is doing this codemod?**
71
+
72
+ This codemod updates how you customize the random generator used by fast-check, either for an individual call or through global configuration. It replaces predefined string names passed as `randomType` with their corresponding generator factories imported from `pure-rand` v8.
73
+
74
+ **Example of code change:**
75
+
76
+ ```diff
77
+ +import { congruential32 } from 'pure-rand/generator/congruential32';
78
+
79
+ -fc.configureGlobal({ randomType: 'congruential' });
80
+ +fc.configureGlobal({ randomType: congruential32 });
81
+ ```
82
+
83
+ </details>
84
+
85
+ <details><summary><code>v5/lifecyclePlugins</code> (≥4.10.0) — Moves property hooks into runner plugins</summary>
86
+
87
+ **What is doing this codemod?**
88
+
89
+ This codemod moves local before and after hooks into runner plugins. It also migrates one-time global hook configuration.
90
+
91
+ **Warning:** If another file installs a global before hook, review local hooks that call `previous()` last or omit it. A global before plugin runs first. A global after plugin runs last, so review local after hooks that call `previous()` first or omit it.
92
+
93
+ **Example of code change:**
94
+
95
+ ```diff
96
+ -fc.assert(fc.property(arb, predicate).beforeEach(setup));
97
+ +fc.assert(fc.property(arb, predicate), { plugins: [fc.beforeEach(setup)] });
98
+ ```
99
+
100
+ </details>
101
+
102
+ <details><summary><code>v5/propertyToAsyncProperty</code> (≥4.11.0) — Renames property to asyncProperty</summary>
103
+
104
+ **What is doing this codemod?**
105
+
106
+ This codemod is changing all references to `property` into references to `asyncProperty`. While doing that it converts any synchrounous assertion linked to `property` into an asynchrounous one.
107
+
108
+ **Example of code change:**
109
+
110
+ ```diff
111
+ -test('my property', () => {
112
+ - fc.assert(fc.property(arb, predicate));
113
+ +test('my property', async () => {
114
+ + await fc.assert(fc.asyncProperty(arb, predicate));
115
+ });
116
+ ```
117
+
118
+ </details>
119
+
120
+ <details><summary><code>v5/runnerPlugins</code> (≥4.11.0) — Moves runner options and custom reporters into plugins</summary>
121
+
122
+ **What is doing this codemod?**
123
+
124
+ This codemod moves local runner options and custom reporters into plugins. For a one-time global setup, it installs the corresponding plugins globally.
125
+
126
+ **Example of code change:**
127
+
128
+ ```diff
129
+ -fc.assert(property, { timeout: 500 });
130
+ +fc.assert(property, { plugins: [fc.timeout(500)] });
131
+ ```
132
+
133
+ </details>
134
+
135
+ <details><summary><code>v5/checkToAssert</code> (≥5.0.0) — Preserves RunDetails when migrating check to assert</summary>
136
+
137
+ **What is doing this codemod?**
138
+
139
+ This codemod replaces `check` calls with `assert` calls using `noDefaultPlugins: true`. It preserves access to `RunDetails` by adding a helper that captures them through a plugin’s `onAllRunsComplete` hook.
140
+
141
+ Assumes fast-check v5 after `v5/propertyToAsyncProperty`, where `check` always returns a promise. Synchronous or uncertain usages are left unchanged with a warning.
142
+
143
+ **Example of code change:**
144
+
145
+ ```diff
146
+ -const details = await fc.check(property);
147
+ +const details = await assertAndGetRunDetails(property);
148
+ if (details.failed) console.log(details.counterexample);
149
+ ```
150
+
151
+ </details>
152
+
153
+ <details><summary><code>v5/sample</code> (≥5.0.0) — Awaits samples and keeps property generation predicate-free</summary>
154
+
155
+ **What is doing this codemod?**
156
+
157
+ This codemod awaits sampling and sets `noPredicateExecution: true` for property inputs so sampling still generates values without running the predicate. When the input is unclear, it still adds `await` and reports the call for review.
158
+
159
+ **Example of code change:**
160
+
161
+ ```diff
162
+ -fc.sample(fc.integer());
163
+ +await fc.sample(fc.integer());
164
+ ```
165
+
166
+ </details>
167
+
168
+ <details><summary><code>v5/statistics</code> (≥5.0.0) — Awaits statistics and logs the result</summary>
169
+
170
+ **What is doing this codemod?**
171
+
172
+ This codemod awaits statistics and logs the result using the original logger when supplied. For property inputs it skips predicate execution and adapts the classifier to receive separate arguments. When the input is unclear, it still awaits and logs the result, preserves the classifier, and reports the call for review.
173
+
174
+ **Example of code change:**
175
+
176
+ ```diff
177
+ -fc.statistics(fc.integer(), String);
178
+ +fc.logStatistics(await fc.statistics(fc.integer(), String));
179
+ ```
180
+
181
+ </details>
182
+
183
+ ### Migrate to v6
184
+
185
+ Version 6 is not yet planned, but some APIs have already been deprecated. Following codemods help you update your code to use their replacements.
186
+
187
+ <details><summary><code>v6/asyncPropertyToProperty</code> (≥5.0.0) — Renames asyncProperty to property</summary>
188
+
189
+ **What is doing this codemod?**
190
+
191
+ This codemod replaces references to the deprecated `asyncProperty` with `property`. Since v5, `property` supports both synchronous and asynchronous predicates and `asyncProperty` is simply an alias for it.
192
+
193
+ **Example of code change:**
194
+
195
+ ```diff
196
+ -await fc.assert(fc.asyncProperty(arb, predicate));
197
+ +await fc.assert(fc.property(arb, predicate));
198
+ ```
199
+
200
+ </details>
201
+
202
+ <p id="minimum-fast-check-version">
203
+
204
+ **(1)** Versions shown as `≥x.y.z` indicate the minimum `fast-check` version required to apply the transform. For example, `≥1.0.0` requires `fast-check` 1.0.0 or later.
205
+
206
+ </p>
@@ -0,0 +1,48 @@
1
+ import { t as findBinding } from "./fastCheck-BCuGakPT.js";
2
+ // src/transforms/allowAwait.ts
3
+ function isTestApi(j, path, node, names) {
4
+ if (!j.Identifier.check(node)) return false;
5
+ if (!path.scope.lookup(node.name)) return names.includes(node.name);
6
+ const specifier = findBinding(j, path, node.name)?.parent;
7
+ return j.ImportSpecifier.check(specifier?.node) && j.Identifier.check(specifier.node.imported) && names.includes(specifier.node.imported.name) && [
8
+ "vitest",
9
+ "@jest/globals",
10
+ "node:test"
11
+ ].includes(specifier.parent.node.source.value);
12
+ }
13
+ function testCallee(j, path, node) {
14
+ if (isTestApi(j, path, node, ["it", "test"])) return { parameterized: false };
15
+ if (j.MemberExpression.check(node) && !node.computed) return testCallee(j, path, node.object);
16
+ const callee = j.CallExpression.check(node) ? node.callee : j.TaggedTemplateExpression.check(node) ? node.tag : void 0;
17
+ if (j.MemberExpression.check(callee) && !callee.computed && j.Identifier.check(callee.property) && [
18
+ "each",
19
+ "skipIf",
20
+ "runIf"
21
+ ].includes(callee.property.name)) {
22
+ const test = testCallee(j, path, callee.object);
23
+ if (test) return { parameterized: test.parameterized || callee.property.name === "each" };
24
+ }
25
+ }
26
+ function awaitContext(j, path, filename) {
27
+ let child = path;
28
+ for (let parent = path.parent; parent; child = parent, parent = parent.parent) {
29
+ const node = parent.node;
30
+ if (j.Function.check(node)) {
31
+ if (child.node !== node.body) return void 0;
32
+ if (node.async) return {};
33
+ const test = parent.parent.node;
34
+ const callee = j.CallExpression.check(test) ? testCallee(j, parent, test.callee) : void 0;
35
+ if (!(j.ArrowFunctionExpression.check(node) || j.FunctionExpression.check(node)) || !callee || !callee.parameterized && node.params.length || node.returnType || node.generator || !j.CallExpression.check(test) || test.arguments[1] !== node) return void 0;
36
+ return { functionToMakeAsync: node };
37
+ }
38
+ if (j.ClassBody.check(node) || j.TSModuleBlock.check(node)) return void 0;
39
+ if (j.Program.check(node)) return /\.c[jt]s$/i.test(filename) ? void 0 : {};
40
+ }
41
+ }
42
+ function allowAwait(j, path, filename) {
43
+ const context = awaitContext(j, path, filename);
44
+ if (!context) return false;
45
+ if (context.functionToMakeAsync) context.functionToMakeAsync.async = true;
46
+ return true;
47
+ }
48
+ export { awaitContext as n, allowAwait as t };
package/lib/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/lib/cli.js ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { existsSync } from "node:fs";
4
+ import { fileURLToPath } from "node:url";
5
+ // package.json
6
+ var exports = {
7
+ "./package.json": "./package.json",
8
+ "./cli": "./lib/cli.js",
9
+ "./transforms/v5/checkToAssert": "./lib/transforms/v5/checkToAssert.js",
10
+ "./transforms/v5/defaultImport": "./lib/transforms/v5/defaultImport.js",
11
+ "./transforms/v5/lifecyclePlugins": "./lib/transforms/v5/lifecyclePlugins.js",
12
+ "./transforms/v5/propertyToAsyncProperty": "./lib/transforms/v5/propertyToAsyncProperty.js",
13
+ "./transforms/v5/randomMethods": "./lib/transforms/v5/randomMethods.js",
14
+ "./transforms/v5/randomTypeFactory": "./lib/transforms/v5/randomTypeFactory.js",
15
+ "./transforms/v5/runnerPlugins": "./lib/transforms/v5/runnerPlugins.js",
16
+ "./transforms/v5/sample": "./lib/transforms/v5/sample.js",
17
+ "./transforms/v5/statistics": "./lib/transforms/v5/statistics.js",
18
+ "./transforms/v5/stringUnit": "./lib/transforms/v5/stringUnit.js",
19
+ "./transforms/v6/asyncPropertyToProperty": "./lib/transforms/v6/asyncPropertyToProperty.js"
20
+ };
21
+ // src/cli.ts
22
+ const transformPrefix = "./transforms/";
23
+ const allTransforms = Object.keys(exports).filter((entry) => entry.startsWith(transformPrefix)).map((entry) => entry.slice(13));
24
+ const [transform, ...args] = process.argv.slice(2);
25
+ const usage = "Usage: fast-check-codemod <transform> <path> [jscodeshift options]\nwith transform being one of: " + allTransforms.join(", ");
26
+ if (transform === "--help" || transform === "-h") console.log(usage);
27
+ else if (!allTransforms.includes(transform) || args.length === 0 || args[0].startsWith("-")) {
28
+ console.error(usage);
29
+ process.exitCode = 1;
30
+ } else if (!existsSync(args[0])) {
31
+ console.error(`Path does not exist: ${args[0]}`);
32
+ process.exitCode = 1;
33
+ } else {
34
+ const extension = import.meta.url.endsWith(".ts") ? "ts" : "js";
35
+ const result = spawnSync(process.execPath, [
36
+ ...extension === "ts" ? ["--import", import.meta.resolve("tsx")] : [],
37
+ fileURLToPath(import.meta.resolve("jscodeshift/bin/jscodeshift.js")),
38
+ "--transform",
39
+ fileURLToPath(import.meta.resolve(`./transforms/${transform}.${extension}`)),
40
+ "--no-babel",
41
+ "--extensions=js,jsx,ts,tsx,mjs,cjs,mts,cts",
42
+ "--ignore-pattern=**/node_modules/**",
43
+ "--ignore-pattern=**/.git/**",
44
+ "--fail-on-error",
45
+ ...args
46
+ ], { stdio: "inherit" });
47
+ if (result.error) console.error(result.error.message);
48
+ process.exitCode = result.status ?? 1;
49
+ }
@@ -0,0 +1,51 @@
1
+ // src/transforms/fastCheck.ts
2
+ function isReference(j, path) {
3
+ const parent = path.parent.node;
4
+ if (j.ImportSpecifier.check(parent) || j.ImportNamespaceSpecifier.check(parent) || j.ImportDefaultSpecifier.check(parent)) return false;
5
+ if (j.ExportSpecifier.check(parent) && path.name === "exported") return false;
6
+ if (j.MemberExpression.check(parent) && path.name === "property" && !parent.computed) return false;
7
+ if ((j.Property.check(parent) || j.ObjectProperty.check(parent) || j.ObjectMethod.check(parent)) && path.name === "key" && !parent.computed) return false;
8
+ return true;
9
+ }
10
+ function bindingRegion(j, binding, scope) {
11
+ for (let p = binding.parent; p && p !== scope; p = p.parent) {
12
+ if (j.VariableDeclaration.check(p.node) && p.node.kind === "var") return scope;
13
+ if (j.BlockStatement.check(p.node) || j.ForStatement.check(p.node) || j.ForInStatement.check(p.node) || j.ForOfStatement.check(p.node)) return p;
14
+ if (j.SwitchCase.check(p.node)) return p.parentPath;
15
+ }
16
+ return scope;
17
+ }
18
+ function findBinding(j, path, name) {
19
+ const enclosing = /* @__PURE__ */ new Set();
20
+ for (let p = path; p; p = p.parentPath) enclosing.add(p);
21
+ for (let scope = path.scope.lookup(name); scope; scope = scope.parent?.lookup(name)) {
22
+ const bindings = scope.getBindings()[name];
23
+ const regions = /* @__PURE__ */ new Map();
24
+ for (const binding of bindings) {
25
+ const region = bindingRegion(j, binding, scope.path);
26
+ const group = regions.get(region) ?? [];
27
+ group.push(binding);
28
+ regions.set(region, group);
29
+ }
30
+ for (const region of enclosing) {
31
+ const visible = regions.get(region);
32
+ if (visible) return visible.length === 1 ? visible[0] : void 0;
33
+ }
34
+ }
35
+ }
36
+ function isFastCheckNamespace(j, path, node) {
37
+ if (!j.Identifier.check(node)) return false;
38
+ const specifier = findBinding(j, path, node.name)?.parent;
39
+ const declaration = specifier?.parent.node;
40
+ return (j.ImportNamespaceSpecifier.check(specifier?.node) || j.ImportDefaultSpecifier.check(specifier?.node)) && j.ImportDeclaration.check(declaration) && declaration.source.value === "fast-check" && declaration.importKind !== "type";
41
+ }
42
+ function memberName(j, path, member) {
43
+ if (j.MemberExpression.check(member) && !member.computed && j.Identifier.check(member.property) && isFastCheckNamespace(j, path, member.object)) return member.property.name;
44
+ }
45
+ function importedName(j, path, node) {
46
+ if (!j.Identifier.check(node)) return memberName(j, path, node);
47
+ const specifier = findBinding(j, path, node.name)?.parent;
48
+ const declaration = specifier?.parent.node;
49
+ if (j.ImportSpecifier.check(specifier?.node) && j.Identifier.check(specifier.node.imported) && specifier.node.importKind !== "type" && j.ImportDeclaration.check(declaration) && declaration.source.value === "fast-check" && declaration.importKind !== "type") return specifier.node.imported.name;
50
+ }
51
+ export { memberName as a, isReference as i, importedName as n, isFastCheckNamespace as r, findBinding as t };
@@ -0,0 +1,215 @@
1
+ import { i as isReference, n as importedName, r as isFastCheckNamespace, t as findBinding } from "./fastCheck-BCuGakPT.js";
2
+ import { t as reportUnsupported } from "./reportUnsupported-DY7wlHET.js";
3
+ // src/transforms/pluginMigration.ts
4
+ function runnerName(j, path, call) {
5
+ const name = importedName(j, path, call.callee);
6
+ if (name) return name;
7
+ const member = call.callee;
8
+ if (!j.MemberExpression.check(member) || member.computed || !j.Identifier.check(member.property) || !j.Identifier.check(member.object)) return;
9
+ const declaration = findBinding(j, path, member.object.name)?.parent;
10
+ if (!j.VariableDeclarator.check(declaration?.node) || declaration.parent.node.kind !== "const" || !j.Identifier.check(declaration.node.id)) return;
11
+ const init = declaration.node.init;
12
+ if (j.CallExpression.check(init) && j.Identifier.check(init.callee) && init.callee.name === "require" && !declaration.scope.lookup("require") && init.arguments.length === 1 && j.StringLiteral.check(init.arguments[0]) && init.arguments[0].value === "fast-check") return member.property.name;
13
+ }
14
+ function isExpression(j, node) {
15
+ return j.Expression.check(node);
16
+ }
17
+ function readOptions(j, properties) {
18
+ const options = /* @__PURE__ */ new Map();
19
+ for (const prop of properties) {
20
+ let value;
21
+ if (prop.type === "ObjectMethod" && prop.kind === "method" && !prop.computed) {
22
+ const fn = j.functionExpression(null, prop.params, prop.body, prop.generator);
23
+ fn.async = prop.async;
24
+ fn.returnType = prop.returnType;
25
+ fn.typeParameters = prop.typeParameters;
26
+ value = fn;
27
+ } else if ((prop.type === "ObjectProperty" || prop.type === "Property") && !prop.computed && (!("kind" in prop) || prop.kind === "init") && isExpression(j, prop.value)) value = prop.value;
28
+ else return void 0;
29
+ const key = prop.key.type === "Identifier" ? prop.key.name : "value" in prop.key ? prop.key.value : void 0;
30
+ if (typeof key !== "string" || options.has(key)) return void 0;
31
+ options.set(key, value);
32
+ }
33
+ return options;
34
+ }
35
+ function isSimple(j, value) {
36
+ return j.Literal.check(value) || j.Identifier.check(value) || j.FunctionExpression.check(value) || j.ArrowFunctionExpression.check(value) || j.ArrayExpression.check(value) && value.elements.every((item) => isExpression(j, item) && isSimple(j, item));
37
+ }
38
+ function constantOptions(j, path, name) {
39
+ const declaration = findBinding(j, path, name)?.parent;
40
+ if (!declaration || !j.VariableDeclarator.check(declaration.node) || declaration.parent.node.kind !== "const" || declaration.parent.node.declarations.length !== 1 || declaration.parent.node.comments?.length || !["Program", "BlockStatement"].includes(declaration.parent.parent.node.type)) return void 0;
41
+ const init = declaration.node.init;
42
+ if (!j.ObjectExpression.check(init) || !init.properties.every((p) => (p.type === "ObjectProperty" || p.type === "Property") && !p.computed && j.Literal.check(p.value))) return void 0;
43
+ const object = declaration.get("init");
44
+ const binding = declaration.node.id;
45
+ const references = j(declaration.scope.path).find(j.Identifier, { name }).paths().filter((ref) => ref.node !== binding && isReference(j, ref) && findBinding(j, ref, name)?.node === binding);
46
+ if (references.length === 1) return { object };
47
+ if (declaration.node.id.type !== "Identifier" || declaration.node.id.typeAnnotation) return void 0;
48
+ const sharedUses = [];
49
+ for (const ref of references) {
50
+ const use = ref.parent;
51
+ if (!j.CallExpression.check(use.node) || use.node.arguments.length !== 2 || use.node.arguments[1] !== ref.node || findBinding(j, ref, name)?.parent?.node !== declaration.node) return void 0;
52
+ const runner = runnerName(j, use, use.node);
53
+ if (runner !== "assert" && runner !== "check") return void 0;
54
+ sharedUses.push(use.node);
55
+ }
56
+ return {
57
+ object,
58
+ sharedUses
59
+ };
60
+ }
61
+ function migratePluginCalls(file, api, migrate) {
62
+ const j = api.jscodeshift.withParser(/\.[cm]?ts$/.test(file.path) ? "ts" : "tsx");
63
+ const root = j(file.source);
64
+ const calls = root.find(j.CallExpression).paths();
65
+ const globalCalls = calls.filter((path) => runnerName(j, path, path.node) === "configureGlobal");
66
+ const hasCheck = calls.some((path) => runnerName(j, path, path.node) === "check");
67
+ const hasReset = calls.some((path) => runnerName(j, path, path.node) === "resetConfigureGlobal");
68
+ const sites = [];
69
+ const globalKeys = /* @__PURE__ */ new Set();
70
+ const localKeys = /* @__PURE__ */ new Set();
71
+ let needsNamespace = false;
72
+ let namespace = "fc";
73
+ for (let suffix = 2; root.find(j.Identifier, { name: namespace }).size() !== 0; ++suffix) namespace = "fc" + suffix;
74
+ for (const path of calls) {
75
+ const runner = runnerName(j, path, path.node);
76
+ if (runner !== "configureGlobal" && runner !== "check" && runner !== "assert") continue;
77
+ const index = runner === "configureGlobal" ? 0 : 1;
78
+ const args = path.node.arguments;
79
+ if (args.length < 1 || args.length > index + 1) continue;
80
+ const argument = args[index];
81
+ const constant = j.Identifier.check(argument) ? constantOptions(j, path, argument.name) : void 0;
82
+ const object = constant?.object.node ?? argument ?? j.objectExpression([]);
83
+ if (!j.ObjectExpression.check(object)) continue;
84
+ if (constant?.sharedUses && constant.sharedUses[0] !== path.node) continue;
85
+ const first = object.properties[0];
86
+ const keepsGlobal = runner === "configureGlobal" && first?.type === "SpreadElement" && first.argument.type === "CallExpression" && first.argument.arguments.length === 0 && runnerName(j, path, first.argument) === "readConfigureGlobal";
87
+ const options = readOptions(j, keepsGlobal ? object.properties.slice(1) : object.properties);
88
+ if (!options) continue;
89
+ const callee = path.node.callee;
90
+ const receiver = j.MemberExpression.check(callee) ? callee.object : void 0;
91
+ if (constant?.sharedUses && receiver) {
92
+ if (!j.Identifier.check(receiver)) continue;
93
+ const binding = findBinding(j, path, receiver.name)?.parent;
94
+ if (binding?.parent.node.type !== "ImportDeclaration" || findBinding(j, constant.object, receiver.name)?.parent?.node !== binding.node) continue;
95
+ }
96
+ const member = (name) => j.memberExpression(receiver ?? j.identifier(namespace), j.identifier(name));
97
+ const report = (message) => reportUnsupported(api, path.node, message);
98
+ const edit = migrate({
99
+ j,
100
+ runner,
101
+ call: path.node,
102
+ hasCheck,
103
+ typescript: /\.[cm]?tsx?$/.test(file.path),
104
+ typeNamespace: !receiver ? namespace : j.Identifier.check(receiver) && isFastCheckNamespace(j, path, receiver) ? receiver.name : void 0,
105
+ path,
106
+ options,
107
+ member,
108
+ importedName: (call) => runnerName(j, path, call),
109
+ report
110
+ });
111
+ const keys = runner === "configureGlobal" ? globalKeys : localKeys;
112
+ for (const key of options.keys()) keys.add(key);
113
+ for (const key of edit?.conflicts ?? []) keys.add(key);
114
+ if (edit && (!constant?.sharedUses || edit.shareLocalOptions)) sites.push({
115
+ path,
116
+ runner,
117
+ index,
118
+ object,
119
+ options,
120
+ receiver,
121
+ member,
122
+ edit,
123
+ report,
124
+ keepsGlobal,
125
+ constant
126
+ });
127
+ }
128
+ let changed = false;
129
+ for (const { path, runner, index, object, options, receiver, member, edit, report, keepsGlobal, constant } of sites) {
130
+ const global = runner === "configureGlobal";
131
+ const otherKeys = global ? localKeys : globalKeys;
132
+ if ([...edit.remove, ...edit.conflicts ?? []].some((key) => otherKeys.has(key))) {
133
+ report("Review the local override and global setup together: installed plugins accumulate.");
134
+ continue;
135
+ }
136
+ const statement = path.parent;
137
+ if (global && (globalCalls.length !== 1 || hasReset || !j.ExpressionStatement.check(statement.node) || !j.Program.check(statement.parent.node))) {
138
+ report("Review this global configuration: plugins must be installed once.");
139
+ continue;
140
+ }
141
+ const existing = options.get("plugins");
142
+ if (existing && (global || !j.ArrayExpression.check(existing))) {
143
+ report("Review the existing plugin list before merging plugins.");
144
+ continue;
145
+ }
146
+ if ([...options].some(([key, value]) => key !== "plugins" && !isSimple(j, value))) {
147
+ report("Review the evaluation order of this options object.");
148
+ continue;
149
+ }
150
+ if (existing && j.ArrayExpression.check(existing) && !isSimple(j, existing) && [...options].some(([key, value]) => edit.remove.includes(key) && j.Identifier.check(value))) {
151
+ report("Review option evaluation alongside the existing plugin factories.");
152
+ continue;
153
+ }
154
+ const keys = [...options.keys()];
155
+ const retained = object.properties.filter((_, i) => {
156
+ if (keepsGlobal && i === 0) return true;
157
+ const key = keys[keepsGlobal ? i - 1 : i];
158
+ return !edit.remove.includes(key) && !(edit.parameters && key in edit.parameters);
159
+ });
160
+ if (object.properties.some((prop) => !retained.includes(prop) && prop.comments?.length)) {
161
+ report("Review the commented options before migrating.");
162
+ continue;
163
+ }
164
+ if (edit.parameters) for (const [key, value] of Object.entries(edit.parameters)) retained.push(j.objectProperty(j.identifier(key), value));
165
+ if (constant && !constant.sharedUses) {
166
+ path.node.arguments[index] = object;
167
+ constant.object.parent.parent.prune();
168
+ }
169
+ edit.apply?.();
170
+ object.properties = retained;
171
+ if (global) {
172
+ const statements = edit.plugins.map(({ value, when }) => {
173
+ const install = j.expressionStatement(j.callExpression(member("installGlobalPlugin"), [value]));
174
+ return when ? j.ifStatement(when, j.blockStatement([install])) : install;
175
+ });
176
+ const keepSettings = retained.length > (keepsGlobal ? 1 : 0);
177
+ if (keepSettings) statements.unshift(statement.node);
178
+ if (statement.node.comments?.length && statements.length && !keepSettings) statements[0].comments = statement.node.comments;
179
+ if (statements.length) statement.replace(...statements);
180
+ else if (keepsGlobal && !statement.node.comments?.length) statement.prune();
181
+ } else {
182
+ let localOptions = object;
183
+ if (edit.property) path.node.arguments[0] = edit.property;
184
+ if (edit.plugins.length) {
185
+ const array = j.ArrayExpression.check(existing) ? existing : j.arrayExpression([]);
186
+ const elements = edit.plugins.map(({ value, when }) => when ? j.spreadElement(j.conditionalExpression(when, j.arrayExpression([value]), j.arrayExpression([]))) : value);
187
+ const before = array.elements.findIndex((item) => item !== null && edit.insertBefore?.(item));
188
+ array.elements.splice(before === -1 ? array.elements.length : before, 0, ...elements);
189
+ if (!existing) object.properties.push(j.objectProperty(j.identifier("plugins"), array));
190
+ if (edit.parameters?.noDefaultPlugins && object.properties.length === 2 && !constant?.sharedUses) {
191
+ const [first, last] = object.properties;
192
+ if (j.ObjectProperty.check(first) && j.ObjectProperty.check(last) && !first.comments?.length && !last.comments?.length) {
193
+ localOptions = j(j.template.statement`const options = {
194
+ ${first.key}: ${first.value},
195
+ ${last.key}: ${last.value},
196
+ };`).find(j.ObjectExpression).nodes()[0];
197
+ localOptions.comments = object.comments;
198
+ }
199
+ }
200
+ }
201
+ if (constant?.sharedUses) {
202
+ if (object.properties.length === 0) {
203
+ for (const use of constant.sharedUses) use.arguments.splice(index, 1);
204
+ constant.object.parent.parent.prune();
205
+ }
206
+ } else if (object.properties.length) path.node.arguments[index] = localOptions;
207
+ else path.node.arguments.splice(index, 1);
208
+ }
209
+ needsNamespace ||= !receiver && edit.plugins.length > 0;
210
+ changed = true;
211
+ }
212
+ if (needsNamespace && root.find(j.Identifier, { name: namespace }).size()) root.find(j.ImportDeclaration, { source: { value: "fast-check" } }).paths()[0].insertAfter(j.importDeclaration([j.importNamespaceSpecifier(j.identifier(namespace))], j.stringLiteral("fast-check")));
213
+ return changed ? root.toSource({ quote: "single" }) : file.source;
214
+ }
215
+ export { migratePluginCalls as t };
@@ -0,0 +1,7 @@
1
+ // src/transforms/reportUnsupported.ts
2
+ function reportUnsupported(api, node, message) {
3
+ const start = node.loc?.start;
4
+ const location = start ? ` (${start.line}:${start.column + 1})` : "";
5
+ api.report(`warning${location}: ${message}`);
6
+ }
7
+ export { reportUnsupported as t };
@@ -0,0 +1,26 @@
1
+ import { n as importedName, t as findBinding } from "./fastCheck-BCuGakPT.js";
2
+ // src/transforms/sampling.ts
3
+ function isPropertyInput(j, path) {
4
+ const input = path.get("arguments", 0);
5
+ let definition = input;
6
+ if (j.Identifier.check(input.node)) {
7
+ const binding = findBinding(j, input, input.node.name)?.parent;
8
+ if (j.VariableDeclarator.check(binding?.node) && binding.parent.node.kind === "const") definition = binding.get("init");
9
+ }
10
+ if (j.CallExpression.check(definition.node)) {
11
+ const factory = importedName(j, definition, definition.node.callee);
12
+ if (factory !== void 0) return factory === "property" || factory === "asyncProperty";
13
+ }
14
+ if (j.Identifier.check(input.node) && /^arb|arb$/i.test(input.node.name) && !/prop/i.test(input.node.name)) return false;
15
+ }
16
+ function samplingOptions(j, params) {
17
+ if (params && !j.NumericLiteral.check(params) && !j.ObjectExpression.check(params)) return;
18
+ const opts = j.ObjectExpression.check(params) ? params : j.objectExpression(params ? [j.objectProperty(j.identifier("numRuns"), params)] : []);
19
+ const keys = opts.properties.map((p) => j.ObjectProperty.check(p) && !p.computed && j.Identifier.check(p.key) ? p.key.name : void 0);
20
+ if (keys.includes(void 0) || new Set(keys).size !== keys.length || keys.includes("noPredicateExecution")) return;
21
+ return {
22
+ opts,
23
+ keys
24
+ };
25
+ }
26
+ export { samplingOptions as n, isPropertyInput as t };
@@ -0,0 +1,2 @@
1
+ import { API, FileInfo } from "jscodeshift";
2
+ export default function transform(file: FileInfo, api: API): string;