@schema-hub/stryker-zod-mutator 0.0.14 → 0.0.16
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.
- package/package.json +3 -6
- package/sbom.cdx.json +15 -15
- package/stryker-zod-mutator/ast.js +1 -88
- package/stryker-zod-mutator/ast.js.map +1 -1
- package/stryker-zod-mutator/behavior-mutations.js +5 -61
- package/stryker-zod-mutator/behavior-mutations.js.map +1 -1
- package/stryker-zod-mutator/binding-resolution.js +3 -293
- package/stryker-zod-mutator/binding-resolution.js.map +1 -1
- package/stryker-zod-mutator/check-mutations.js +5 -153
- package/stryker-zod-mutator/check-mutations.js.map +1 -1
- package/stryker-zod-mutator/collection-mutations.js +5 -159
- package/stryker-zod-mutator/collection-mutations.js.map +1 -1
- package/stryker-zod-mutator/declarator-init-id.js +2 -12
- package/stryker-zod-mutator/declarator-init-id.js.map +1 -1
- package/stryker-zod-mutator/filesystem-module-loader.js +2 -61
- package/stryker-zod-mutator/filesystem-module-loader.js.map +1 -1
- package/stryker-zod-mutator/masked-schema-references.js +4 -114
- package/stryker-zod-mutator/masked-schema-references.js.map +1 -1
- package/stryker-zod-mutator/mutation-catalog.js +7 -16
- package/stryker-zod-mutator/mutation-catalog.js.map +1 -1
- package/stryker-zod-mutator/mutation-definition.js +2 -16
- package/stryker-zod-mutator/mutation-definition.js.map +1 -1
- package/stryker-zod-mutator/mutations.js +3 -16
- package/stryker-zod-mutator/mutations.js.map +1 -1
- package/stryker-zod-mutator/object-mutations.js +6 -114
- package/stryker-zod-mutator/object-mutations.js.map +1 -1
- package/stryker-zod-mutator/operator.js +0 -95
- package/stryker-zod-mutator/operator.js.map +1 -1
- package/stryker-zod-mutator/presence-mutations.js +6 -83
- package/stryker-zod-mutator/presence-mutations.js.map +1 -1
- package/stryker-zod-mutator/primitive-mutations.js +2 -33
- package/stryker-zod-mutator/primitive-mutations.js.map +1 -1
- package/stryker-zod-mutator/reference-mutations.js +4 -58
- package/stryker-zod-mutator/reference-mutations.js.map +1 -1
- package/stryker-zod-mutator/registry.js +2 -50
- package/stryker-zod-mutator/registry.js.map +1 -1
- package/stryker-zod-mutator/schema-call-mutations.js +6 -93
- package/stryker-zod-mutator/schema-call-mutations.js.map +1 -1
- package/stryker-zod-mutator/zod-bindings.js +2 -214
- package/stryker-zod-mutator/zod-bindings.js.map +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import '@babel/types';
|
|
2
|
+
import "./ast.js";
|
|
3
|
+
import "./mutation-definition.js";
|
|
4
|
+
import "./schema-call-mutations.js";
|
|
5
|
+
import "./zod-bindings.js";
|
|
6
6
|
const stringCheckNames = new Set(['min', 'max', 'length', 'nonempty', 'regex', 'includes', 'startsWith', 'endsWith']);
|
|
7
7
|
const stringMiniCheckNames = new Set([
|
|
8
8
|
'minLength',
|
|
@@ -55,152 +55,4 @@ const strictnessSwaps = new Map([
|
|
|
55
55
|
const stringLengthLowerBoundNames = new Set(['min', 'minLength']);
|
|
56
56
|
const collectionLengthLowerBoundNames = new Set(['min', 'minSize', 'minLength']);
|
|
57
57
|
const noLengthLowerBoundNames = new Set();
|
|
58
|
-
const stringCheckConfig = {
|
|
59
|
-
methodNames: stringCheckNames,
|
|
60
|
-
miniNames: stringMiniCheckNames,
|
|
61
|
-
lengthLowerBoundNames: stringLengthLowerBoundNames
|
|
62
|
-
};
|
|
63
|
-
const numberCheckConfig = {
|
|
64
|
-
methodNames: numberCheckNames,
|
|
65
|
-
miniNames: numberMiniCheckNames,
|
|
66
|
-
lengthLowerBoundNames: noLengthLowerBoundNames
|
|
67
|
-
};
|
|
68
|
-
const collectionCheckConfig = {
|
|
69
|
-
methodNames: collectionCheckNames,
|
|
70
|
-
miniNames: collectionMiniCheckNames,
|
|
71
|
-
lengthLowerBoundNames: collectionLengthLowerBoundNames
|
|
72
|
-
};
|
|
73
|
-
function numericArgumentValue(call) {
|
|
74
|
-
const argument = call.arguments[0];
|
|
75
|
-
if (babel.isNumericLiteral(argument)) {
|
|
76
|
-
return argument.value;
|
|
77
|
-
}
|
|
78
|
-
if (babel.isUnaryExpression(argument) && argument.operator === '-' && babel.isNumericLiteral(argument.argument)) {
|
|
79
|
-
return -argument.argument.value;
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
function isVacuousLengthBound(name, call, lengthLowerBoundNames) {
|
|
84
|
-
const value = numericArgumentValue(call);
|
|
85
|
-
return name !== null && value !== null && value <= 0 && lengthLowerBoundNames.has(name);
|
|
86
|
-
}
|
|
87
|
-
function meaningfulBoundaryMutants(mutants, name, call, lengthLowerBoundNames) {
|
|
88
|
-
if (!isVacuousLengthBound(name, call, lengthLowerBoundNames)) {
|
|
89
|
-
return mutants;
|
|
90
|
-
}
|
|
91
|
-
return mutants.filter(function (mutant) {
|
|
92
|
-
return (numericArgumentValue(mutant) ?? 1) > 0;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function removeChecksFromCheckCall(call, bindings, names, lengthLowerBoundNames) {
|
|
96
|
-
if (!babel.isMemberExpression(call.callee) || getMemberName(call.callee) !== 'check') {
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
return call.arguments.flatMap(function (argument, index) {
|
|
100
|
-
if (!babel.isCallExpression(argument) ||
|
|
101
|
-
!names.has(getZodCallName(bindings, argument) ?? '') ||
|
|
102
|
-
isVacuousLengthBound(getZodCallName(bindings, argument), argument, lengthLowerBoundNames)) {
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
const clone = babel.cloneNode(call, true);
|
|
106
|
-
clone.arguments = clone.arguments.filter(function (_check, checkIndex) {
|
|
107
|
-
return checkIndex !== index;
|
|
108
|
-
});
|
|
109
|
-
return [clone];
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function mutateCheckCallBoundaries(call, bindings, names, lengthLowerBoundNames) {
|
|
113
|
-
if (!babel.isMemberExpression(call.callee) || getMemberName(call.callee) !== 'check') {
|
|
114
|
-
return [];
|
|
115
|
-
}
|
|
116
|
-
return call.arguments.flatMap(function (argument, index) {
|
|
117
|
-
if (!babel.isCallExpression(argument) || !names.has(getZodCallName(bindings, argument) ?? '')) {
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
const mutants = meaningfulBoundaryMutants(numericArgumentMutations(argument, 0), getZodCallName(bindings, argument), argument, lengthLowerBoundNames);
|
|
121
|
-
return mutants.map(function (mutatedCheck) {
|
|
122
|
-
const clone = babel.cloneNode(call, true);
|
|
123
|
-
clone.arguments[index] = mutatedCheck;
|
|
124
|
-
return clone;
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function removeSchemaMethodChecks(path, bindings, config) {
|
|
129
|
-
const call = callNode(path);
|
|
130
|
-
if (call === null) {
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
const methodName = babel.isMemberExpression(call.callee) ? getMemberName(call.callee) : null;
|
|
134
|
-
const methodRemovals = isVacuousLengthBound(methodName, call, config.lengthLowerBoundNames)
|
|
135
|
-
? []
|
|
136
|
-
: removeMethod(call, bindings, config.methodNames);
|
|
137
|
-
return [
|
|
138
|
-
...methodRemovals,
|
|
139
|
-
...removeChecksFromCheckCall(call, bindings, config.miniNames, config.lengthLowerBoundNames)
|
|
140
|
-
];
|
|
141
|
-
}
|
|
142
|
-
function mutateSchemaBoundaries(path, bindings, config) {
|
|
143
|
-
const call = callNode(path);
|
|
144
|
-
if (call === null) {
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
if (babel.isMemberExpression(call.callee) && config.methodNames.has(getMemberName(call.callee) ?? '')) {
|
|
148
|
-
return meaningfulBoundaryMutants(numericArgumentMutations(call, 0), getMemberName(call.callee), call, config.lengthLowerBoundNames);
|
|
149
|
-
}
|
|
150
|
-
return mutateCheckCallBoundaries(call, bindings, config.miniNames, config.lengthLowerBoundNames);
|
|
151
|
-
}
|
|
152
|
-
function memberCallName(call) {
|
|
153
|
-
return call !== null && babel.isMemberExpression(call.callee)
|
|
154
|
-
? getMemberName(call.callee)
|
|
155
|
-
: null;
|
|
156
|
-
}
|
|
157
|
-
function swapStrictness(path) {
|
|
158
|
-
const call = callNode(path);
|
|
159
|
-
const methodName = memberCallName(call);
|
|
160
|
-
const replacement = strictnessSwaps.get(methodName ?? '');
|
|
161
|
-
if (call === null || replacement === undefined || !babel.isMemberExpression(call.callee)) {
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
const clone = babel.cloneNode(call, true);
|
|
165
|
-
clone.callee = babel.memberExpression(call.callee.object, babel.identifier(replacement));
|
|
166
|
-
return [clone];
|
|
167
|
-
}
|
|
168
|
-
function stringFormatReplacementStyle(path, bindings) {
|
|
169
|
-
const call = callNode(path);
|
|
170
|
-
const callName = call === null ? null : getZodCallName(bindings, call);
|
|
171
|
-
if (call === null || callName === null || !stringFormatFactoryNames.has(callName)) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
return expressionStyle(bindings, call);
|
|
175
|
-
}
|
|
176
|
-
function replaceStringFormat(path, bindings) {
|
|
177
|
-
const style = stringFormatReplacementStyle(path, bindings);
|
|
178
|
-
if (style === null) {
|
|
179
|
-
return [];
|
|
180
|
-
}
|
|
181
|
-
const replacement = buildZodCall(bindings, style, 'string', []);
|
|
182
|
-
return replacement === null ? [] : [replacement];
|
|
183
|
-
}
|
|
184
|
-
export const checkMutationDefinitions = [
|
|
185
|
-
createDefinition('ZodStringCheckRemove', function (path, bindings) {
|
|
186
|
-
return removeSchemaMethodChecks(path, bindings, stringCheckConfig);
|
|
187
|
-
}),
|
|
188
|
-
createDefinition('ZodStringBoundaryChange', function (path, bindings) {
|
|
189
|
-
return mutateSchemaBoundaries(path, bindings, stringCheckConfig);
|
|
190
|
-
}),
|
|
191
|
-
createDefinition('ZodStringFormatToString', replaceStringFormat),
|
|
192
|
-
createDefinition('ZodNumberCheckRemove', function (path, bindings) {
|
|
193
|
-
return removeSchemaMethodChecks(path, bindings, numberCheckConfig);
|
|
194
|
-
}),
|
|
195
|
-
createDefinition('ZodNumberBoundaryChange', function (path, bindings) {
|
|
196
|
-
return mutateSchemaBoundaries(path, bindings, numberCheckConfig);
|
|
197
|
-
}),
|
|
198
|
-
createDefinition('ZodNumberStrictnessSwap', swapStrictness),
|
|
199
|
-
createDefinition('ZodCollectionCheckRemove', function (path, bindings) {
|
|
200
|
-
return removeSchemaMethodChecks(path, bindings, collectionCheckConfig);
|
|
201
|
-
}),
|
|
202
|
-
createDefinition('ZodCollectionBoundaryChange', function (path, bindings) {
|
|
203
|
-
return mutateSchemaBoundaries(path, bindings, collectionCheckConfig);
|
|
204
|
-
})
|
|
205
|
-
];
|
|
206
58
|
//# sourceMappingURL=check-mutations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-mutations.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/check-mutations.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"check-mutations.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/check-mutations.ts"],"names":[],"mappings":"AAAA,OAAuB,cAAc,CAAC;AAEtC,OAKO,UAAU,CAAC;AAClB,OAAoE,0BAA0B,CAAC;AAC/F,OAA6B,4BAA4B,CAAC;AAC1D,OAKO,mBAAmB,CAAC;AAE3B,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,CAAE,CAAC,CAAC;AACxH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACjC,WAAW;IACX,WAAW;IACX,QAAQ;IACR,OAAO;IACP,UAAU;IACV,YAAY;IACZ,UAAU;CACb,CAAC,CAAC;AACH,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC7B,KAAK;IACL,KAAK;IACL,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,UAAU;IACV,aAAa;IACb,UAAU;IACV,aAAa;IACb,YAAY;IACZ,KAAK;CACR,CAAC,CAAC;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,CAAE,CAAC,CAAC;AACvG,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAE,CAAC,CAAC;AACrF,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,CAAE,CAAC,CAAC;AAC/G,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACrC,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;CACT,CAAC,CAAC;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC5B,CAAE,IAAI,EAAE,KAAK,CAAE;IACf,CAAE,KAAK,EAAE,IAAI,CAAE;IACf,CAAE,IAAI,EAAE,KAAK,CAAE;IACf,CAAE,KAAK,EAAE,IAAI,CAAE;IACf,CAAE,UAAU,EAAE,aAAa,CAAE;IAC7B,CAAE,aAAa,EAAE,UAAU,CAAE;IAC7B,CAAE,UAAU,EAAE,aAAa,CAAE;IAC7B,CAAE,aAAa,EAAE,UAAU,CAAE;CAChC,CAAC,CAAC;AACH,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAC,CAAE,KAAK,EAAE,WAAW,CAAE,CAAC,CAAC;AACpE,MAAM,+BAA+B,GAAG,IAAI,GAAG,CAAC,CAAE,KAAK,EAAE,SAAS,EAAE,WAAW,CAAE,CAAC,CAAC;AACnF,MAAM,uBAAuB,GAAwB,IAAI,GAAG,EAAE,CAAC"}
|
|
@@ -1,160 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
function replaceFactory(path, bindings, replacement) {
|
|
7
|
-
const call = callNode(path);
|
|
8
|
-
if (call === null || getZodCallName(bindings, call) !== replacement.sourceName) {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
const style = expressionStyle(bindings, call);
|
|
12
|
-
const args = replacement.mapArguments(call);
|
|
13
|
-
if (style === null || args === null) {
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
const replacementCall = buildZodCall(bindings, style, replacement.targetName, args);
|
|
17
|
-
return replacementCall === null ? [] : [replacementCall];
|
|
18
|
-
}
|
|
19
|
-
function tupleArray(call) {
|
|
20
|
-
const argument = call.arguments[0];
|
|
21
|
-
return babel.isArrayExpression(argument) ? argument : null;
|
|
22
|
-
}
|
|
23
|
-
function removeTupleItems(path, bindings) {
|
|
24
|
-
const call = callNode(path);
|
|
25
|
-
if (call === null || getZodCallName(bindings, call) !== 'tuple') {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
const items = tupleArray(call);
|
|
29
|
-
if (items === null) {
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
return items.elements.flatMap(function (element, index) {
|
|
33
|
-
if (!isExpressionNode(element)) {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
const clone = babel.cloneNode(call, true);
|
|
37
|
-
clone.arguments[0] = replaceArrayItem(items, index);
|
|
38
|
-
return [clone];
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function addTupleRest(path, bindings) {
|
|
42
|
-
const call = callNode(path);
|
|
43
|
-
if (call === null || getZodCallName(bindings, call) !== 'tuple' || call.arguments.length > 1) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
const items = tupleArray(call);
|
|
47
|
-
const restSchema = items?.elements.find(isExpressionNode);
|
|
48
|
-
if (restSchema === undefined) {
|
|
49
|
-
return [];
|
|
50
|
-
}
|
|
51
|
-
const clone = babel.cloneNode(call, true);
|
|
52
|
-
clone.arguments.push(cloneExpression(restSchema));
|
|
53
|
-
return [clone];
|
|
54
|
-
}
|
|
55
|
-
function removeTupleRest(path, bindings) {
|
|
56
|
-
const call = callNode(path);
|
|
57
|
-
if (call === null) {
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
if (getZodCallName(bindings, call) !== 'tuple' || call.arguments.length <= 1) {
|
|
61
|
-
return removeMethod(call, bindings, new Set(['rest']));
|
|
62
|
-
}
|
|
63
|
-
const clone = babel.cloneNode(call, true);
|
|
64
|
-
clone.arguments = clone.arguments.slice(0, 1);
|
|
65
|
-
return [clone];
|
|
66
|
-
}
|
|
67
|
-
function hasInfiniteStringKey(bindings, call) {
|
|
68
|
-
const key = call.arguments[0];
|
|
69
|
-
return isExpressionNode(key) && babel.isCallExpression(key) && getZodCallName(bindings, key) === 'string';
|
|
70
|
-
}
|
|
71
|
-
function swapRecordFactory(path, bindings) {
|
|
72
|
-
const call = callNode(path);
|
|
73
|
-
const currentName = call === null ? null : getZodCallName(bindings, call);
|
|
74
|
-
if (call === null || currentName === null || !['record', 'partialRecord', 'looseRecord'].includes(currentName)) {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
if (hasInfiniteStringKey(bindings, call)) {
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
return ['record', 'partialRecord', 'looseRecord']
|
|
81
|
-
.filter(function (target) {
|
|
82
|
-
return target !== currentName;
|
|
83
|
-
})
|
|
84
|
-
.flatMap(function (target) {
|
|
85
|
-
return replaceZodCallee(bindings, call, target) ?? [];
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
function removeArrayOptions(path, bindings, callNames, argumentIndex) {
|
|
89
|
-
const call = callNode(path);
|
|
90
|
-
if (call === null || !callNames.has(getZodCallName(bindings, call) ?? '')) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
const options = call.arguments[argumentIndex];
|
|
94
|
-
if (!babel.isArrayExpression(options)) {
|
|
95
|
-
return [];
|
|
96
|
-
}
|
|
97
|
-
return options.elements.flatMap(function (element, index) {
|
|
98
|
-
if (!isExpressionNode(element)) {
|
|
99
|
-
return [];
|
|
100
|
-
}
|
|
101
|
-
const clone = babel.cloneNode(call, true);
|
|
102
|
-
clone.arguments[argumentIndex] = replaceArrayItem(options, index);
|
|
103
|
-
return [clone];
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function mutateNumericLiteral(path, bindings) {
|
|
107
|
-
const call = callNode(path);
|
|
108
|
-
if (call === null || getZodCallName(bindings, call) !== 'literal') {
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
return numericArgumentMutations(call, 0);
|
|
112
|
-
}
|
|
113
|
-
function arrayItemArgument(call) {
|
|
114
|
-
const item = call.arguments[0];
|
|
115
|
-
return item !== undefined && isExpressionNode(item)
|
|
116
|
-
? [babel.arrayExpression([cloneExpression(item)])]
|
|
117
|
-
: null;
|
|
118
|
-
}
|
|
119
|
-
function hasSingleTupleItem(call, items) {
|
|
120
|
-
return items?.elements.length === 1 && call.arguments.length === 1;
|
|
121
|
-
}
|
|
122
|
-
function singleTupleItem(call) {
|
|
123
|
-
const items = tupleArray(call);
|
|
124
|
-
const item = items?.elements[0];
|
|
125
|
-
if (item === undefined || !hasSingleTupleItem(call, items) || !isExpressionNode(item)) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
return [cloneExpression(item)];
|
|
129
|
-
}
|
|
130
|
-
export const collectionMutationDefinitions = [
|
|
131
|
-
createDefinition('ZodArrayToTuple', function (path, bindings) {
|
|
132
|
-
return replaceFactory(path, bindings, {
|
|
133
|
-
sourceName: 'array',
|
|
134
|
-
targetName: 'tuple',
|
|
135
|
-
mapArguments: arrayItemArgument
|
|
136
|
-
});
|
|
137
|
-
}),
|
|
138
|
-
createDefinition('ZodTupleToArray', function (path, bindings) {
|
|
139
|
-
return replaceFactory(path, bindings, {
|
|
140
|
-
sourceName: 'tuple',
|
|
141
|
-
targetName: 'array',
|
|
142
|
-
mapArguments: singleTupleItem
|
|
143
|
-
});
|
|
144
|
-
}),
|
|
145
|
-
createDefinition('ZodTupleItemRemove', removeTupleItems),
|
|
146
|
-
createDefinition('ZodTupleRestAdd', addTupleRest),
|
|
147
|
-
createDefinition('ZodTupleRestRemove', removeTupleRest),
|
|
148
|
-
createDefinition('ZodRecordFactorySwap', swapRecordFactory),
|
|
149
|
-
createDefinition('ZodUnionOptionRemove', function (path, bindings) {
|
|
150
|
-
return [
|
|
151
|
-
...removeArrayOptions(path, bindings, new Set(['union']), 0),
|
|
152
|
-
...removeArrayOptions(path, bindings, new Set(['discriminatedUnion']), 1)
|
|
153
|
-
];
|
|
154
|
-
}),
|
|
155
|
-
createDefinition('ZodEnumValueRemove', function (path, bindings) {
|
|
156
|
-
return removeArrayOptions(path, bindings, new Set(['enum']), 0);
|
|
157
|
-
}),
|
|
158
|
-
createDefinition('ZodNumericLiteralChange', mutateNumericLiteral)
|
|
159
|
-
];
|
|
1
|
+
import '@babel/types';
|
|
2
|
+
import "./ast.js";
|
|
3
|
+
import "./mutation-definition.js";
|
|
4
|
+
import "./schema-call-mutations.js";
|
|
5
|
+
import "./zod-bindings.js";
|
|
160
6
|
//# sourceMappingURL=collection-mutations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-mutations.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/collection-mutations.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"collection-mutations.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/collection-mutations.ts"],"names":[],"mappings":"AAAA,OAAuB,cAAc,CAAC;AAEtC,OASO,UAAU,CAAC;AAClB,OAAoE,0BAA0B,CAAC;AAC/F,OAA6B,4BAA4B,CAAC;AAC1D,OAMO,mBAAmB,CAAC"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export function declaratorInitId(declaratorPath, node) {
|
|
4
|
-
if (declaratorPath === null || !babel.isVariableDeclarator(declaratorPath.node)) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const { init, id } = declaratorPath.node;
|
|
8
|
-
if (!isExpressionNode(init)) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
return init === node && babel.isIdentifier(id) ? id : null;
|
|
12
|
-
}
|
|
1
|
+
import '@babel/types';
|
|
2
|
+
import "./ast.js";
|
|
13
3
|
//# sourceMappingURL=declarator-init-id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarator-init-id.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/declarator-init-id.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"declarator-init-id.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/declarator-init-id.ts"],"names":[],"mappings":"AAAA,OAAuB,cAAc,CAAC;AAEtC,OAAoD,UAAU,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'node:path';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import
|
|
4
|
-
const babelPlugins = ['typescript', 'jsx'];
|
|
3
|
+
import '@babel/parser';
|
|
5
4
|
const fallbackCompilerOptions = {
|
|
6
5
|
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
7
6
|
allowImportingTsExtensions: true,
|
|
@@ -10,62 +9,4 @@ const fallbackCompilerOptions = {
|
|
|
10
9
|
const programCache = new Map();
|
|
11
10
|
const resolutionCache = new Map();
|
|
12
11
|
const compilerOptionsCache = new Map();
|
|
13
|
-
function parseProgram(source, fileName) {
|
|
14
|
-
try {
|
|
15
|
-
return parse(source, { sourceType: 'module', plugins: Array.from(babelPlugins), sourceFilename: fileName })
|
|
16
|
-
.program;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function readAndParse(absolutePath) {
|
|
23
|
-
const source = ts.sys.readFile(absolutePath);
|
|
24
|
-
return source === undefined ? null : parseProgram(source, absolutePath);
|
|
25
|
-
}
|
|
26
|
-
function loadProgram(absolutePath) {
|
|
27
|
-
if (!programCache.has(absolutePath)) {
|
|
28
|
-
programCache.set(absolutePath, readAndParse(absolutePath));
|
|
29
|
-
}
|
|
30
|
-
return programCache.get(absolutePath) ?? null;
|
|
31
|
-
}
|
|
32
|
-
function readCompilerOptions(configPath) {
|
|
33
|
-
if (configPath === '') {
|
|
34
|
-
return fallbackCompilerOptions;
|
|
35
|
-
}
|
|
36
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
37
|
-
const parsed = ts.parseJsonConfigFileContent(configFile.config ?? {}, ts.sys, dirname(configPath));
|
|
38
|
-
return parsed.options;
|
|
39
|
-
}
|
|
40
|
-
function compilerOptionsFor(fromFileName) {
|
|
41
|
-
const configPath = ts.findConfigFile(dirname(fromFileName), ts.sys.fileExists) ?? '';
|
|
42
|
-
const cached = compilerOptionsCache.get(configPath);
|
|
43
|
-
if (cached !== undefined) {
|
|
44
|
-
return cached;
|
|
45
|
-
}
|
|
46
|
-
const options = readCompilerOptions(configPath);
|
|
47
|
-
compilerOptionsCache.set(configPath, options);
|
|
48
|
-
return options;
|
|
49
|
-
}
|
|
50
|
-
function isProjectSource(fileName) {
|
|
51
|
-
return !fileName.includes('/node_modules/') && !fileName.endsWith('.d.ts');
|
|
52
|
-
}
|
|
53
|
-
function resolveOnce(specifier, fromFileName) {
|
|
54
|
-
const result = ts.resolveModuleName(specifier, fromFileName, compilerOptionsFor(fromFileName), ts.sys);
|
|
55
|
-
const resolved = result.resolvedModule?.resolvedFileName;
|
|
56
|
-
return resolved !== undefined && isProjectSource(resolved) ? resolved : null;
|
|
57
|
-
}
|
|
58
|
-
function resolveModulePath(specifier, fromFileName) {
|
|
59
|
-
const key = `${fromFileName}\n${specifier}`;
|
|
60
|
-
if (!resolutionCache.has(key)) {
|
|
61
|
-
resolutionCache.set(key, resolveOnce(specifier, fromFileName));
|
|
62
|
-
}
|
|
63
|
-
return resolutionCache.get(key) ?? null;
|
|
64
|
-
}
|
|
65
|
-
function loadModule(specifier, fromFileName) {
|
|
66
|
-
const resolved = resolveModulePath(specifier, fromFileName);
|
|
67
|
-
const program = resolved === null ? null : loadProgram(resolved);
|
|
68
|
-
return program === null || resolved === null ? null : { program, fileName: resolved };
|
|
69
|
-
}
|
|
70
|
-
export const filesystemResolverEnv = { loadModule };
|
|
71
12
|
//# sourceMappingURL=filesystem-module-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesystem-module-loader.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/filesystem-module-loader.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"filesystem-module-loader.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/filesystem-module-loader.ts"],"names":[],"mappings":"AAAA,OAAwB,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAsB,eAAe,CAAC;AAItC,MAEM,uBAAuB,GAAiC;IAC1D,gBAAgB,EAAE,EAAE,CAAC,oBAAoB,CAAC,OAAO;IACjD,0BAA0B,EAAE,IAAI;IAChC,OAAO,EAAE,IAAI;CAChB,CAAC;AAEF,MAAM,YAAY,GAAG,IAAI,GAAG,EAA0B,CAAC;AACvD,MAAM,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAC;AACzD,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAwC,CAAC"}
|
|
@@ -1,120 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import '@babel/types';
|
|
2
|
+
import "./ast.js";
|
|
3
|
+
import "./declarator-init-id.js";
|
|
4
|
+
import "./zod-bindings.js";
|
|
5
5
|
const unionFactoryNames = new Set(['union', 'discriminatedUnion']);
|
|
6
6
|
const maskingWrappersByAddedWrapper = new Map([
|
|
7
7
|
['nullable', new Set(['nullable', 'nullish'])],
|
|
8
8
|
['optional', new Set(['optional', 'nullish'])]
|
|
9
9
|
]);
|
|
10
|
-
function isNonExportedModuleConst(declarationPath) {
|
|
11
|
-
const declaration = declarationPath?.node;
|
|
12
|
-
const container = declarationPath?.parentPath?.node;
|
|
13
|
-
return babel.isVariableDeclaration(declaration) &&
|
|
14
|
-
declaration.kind === 'const' &&
|
|
15
|
-
babel.isProgram(container);
|
|
16
|
-
}
|
|
17
|
-
function constIdForInit(path) {
|
|
18
|
-
const declaratorPath = path.parentPath;
|
|
19
|
-
const id = declaratorInitId(declaratorPath, path.node);
|
|
20
|
-
return id !== null && isNonExportedModuleConst(declaratorPath?.parentPath ?? null) ? id : null;
|
|
21
|
-
}
|
|
22
|
-
function isUnionCall(unionCallPath, bindings) {
|
|
23
|
-
const unionCall = unionCallPath.node;
|
|
24
|
-
return babel.isCallExpression(unionCall) && unionFactoryNames.has(getZodCallName(bindings, unionCall) ?? '');
|
|
25
|
-
}
|
|
26
|
-
function constIdForUnionOption(path, bindings) {
|
|
27
|
-
const optionsPath = path.parentPath;
|
|
28
|
-
if (optionsPath === null || !babel.isArrayExpression(optionsPath.node)) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const unionCallPath = optionsPath.parentPath;
|
|
32
|
-
if (unionCallPath === null || !isUnionCall(unionCallPath, bindings)) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return constIdForInit(unionCallPath);
|
|
36
|
-
}
|
|
37
|
-
function topLevelPathConstId(path, bindings) {
|
|
38
|
-
return constIdForInit(path) ?? constIdForUnionOption(path, bindings);
|
|
39
|
-
}
|
|
40
|
-
function childNodes(node) {
|
|
41
|
-
return Object.values(node).flatMap(function (value) {
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
return value.filter(babel.isNode);
|
|
44
|
-
}
|
|
45
|
-
return babel.isNode(value) ? [value] : [];
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function collectIdentifierUses(node, name, ancestors) {
|
|
49
|
-
const [parent, grandparent] = ancestors;
|
|
50
|
-
const here = parent !== undefined && babel.isIdentifier(node) && node.name === name
|
|
51
|
-
? [{ node, parent, grandparent }]
|
|
52
|
-
: [];
|
|
53
|
-
const deeper = [node, ...ancestors];
|
|
54
|
-
return here.concat(childNodes(node).flatMap(function (child) {
|
|
55
|
-
return collectIdentifierUses(child, name, deeper);
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
function isPropertyOrMemberName(use) {
|
|
59
|
-
const { node, parent } = use;
|
|
60
|
-
if (babel.isObjectProperty(parent) || babel.isObjectMethod(parent)) {
|
|
61
|
-
return parent.key === node && !parent.computed;
|
|
62
|
-
}
|
|
63
|
-
return babel.isMemberExpression(parent) && parent.property === node && !parent.computed;
|
|
64
|
-
}
|
|
65
|
-
function isTypeOnlyReference(use) {
|
|
66
|
-
return babel.isTSTypeQuery(use.parent);
|
|
67
|
-
}
|
|
68
|
-
function isReference(use) {
|
|
69
|
-
return babel.isReferenced(use.node, use.parent, use.grandparent);
|
|
70
|
-
}
|
|
71
|
-
function isForeignBinding(use, constIdNode) {
|
|
72
|
-
return use.node !== constIdNode && !isReference(use) && !isPropertyOrMemberName(use);
|
|
73
|
-
}
|
|
74
|
-
function maskedAsWrapperArgument(use, maskingWrappers, bindings) {
|
|
75
|
-
const { node, parent } = use;
|
|
76
|
-
if (!babel.isCallExpression(parent)) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
const firstArgument = parent.arguments[0];
|
|
80
|
-
if (!isExpressionNode(firstArgument)) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
if (firstArgument !== node) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
return maskingWrappers.has(getZodCallName(bindings, parent) ?? '');
|
|
87
|
-
}
|
|
88
|
-
function maskedAsWrapperReceiver(use, maskingWrappers) {
|
|
89
|
-
const { node, parent, grandparent } = use;
|
|
90
|
-
if (!babel.isMemberExpression(parent) || parent.object !== node) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
if (!babel.isCallExpression(grandparent) || grandparent.callee !== parent) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
return maskingWrappers.has(getMemberName(parent) ?? '');
|
|
97
|
-
}
|
|
98
|
-
function isMaskedReference(use, maskingWrappers, bindings) {
|
|
99
|
-
return maskedAsWrapperArgument(use, maskingWrappers, bindings) || maskedAsWrapperReceiver(use, maskingWrappers);
|
|
100
|
-
}
|
|
101
|
-
export function presenceWrapperMaskedByEveryUse(path, bindings, wrapperName) {
|
|
102
|
-
const maskingWrappers = maskingWrappersByAddedWrapper.get(wrapperName);
|
|
103
|
-
const program = findProgram(path);
|
|
104
|
-
const constId = topLevelPathConstId(path, bindings);
|
|
105
|
-
if (maskingWrappers === undefined || program === null || constId === null) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
const uses = collectIdentifierUses(program, constId.name, []).filter(function (use) {
|
|
109
|
-
return !isTypeOnlyReference(use);
|
|
110
|
-
});
|
|
111
|
-
const references = uses.filter(isReference);
|
|
112
|
-
const hasForeignBinding = uses.some(function (use) {
|
|
113
|
-
return isForeignBinding(use, constId);
|
|
114
|
-
});
|
|
115
|
-
const allMasked = references.every(function (use) {
|
|
116
|
-
return isMaskedReference(use, maskingWrappers, bindings);
|
|
117
|
-
});
|
|
118
|
-
return !hasForeignBinding && references.length > 0 && allMasked;
|
|
119
|
-
}
|
|
120
10
|
//# sourceMappingURL=masked-schema-references.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"masked-schema-references.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/masked-schema-references.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"masked-schema-references.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/masked-schema-references.ts"],"names":[],"mappings":"AAAA,OAAuB,cAAc,CAAC;AAEtC,OAAgF,UAAU,CAAC;AAC3F,OAAiC,yBAAyB,CAAC;AAC3D,OAAiD,mBAAmB,CAAC;AAErE,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAE,OAAO,EAAE,oBAAoB,CAAE,CAAC,CAAC;AAErE,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAA8B;IACvE,CAAE,UAAU,EAAE,IAAI,GAAG,CAAC,CAAE,UAAU,EAAE,SAAS,CAAE,CAAC,CAAE;IAClD,CAAE,UAAU,EAAE,IAAI,GAAG,CAAC,CAAE,UAAU,EAAE,SAAS,CAAE,CAAC,CAAE;CACrD,CAAC,CAAC"}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
export const mutationDefinitions = [
|
|
9
|
-
...primitiveMutationDefinitions,
|
|
10
|
-
...presenceMutationDefinitions,
|
|
11
|
-
...objectMutationDefinitions,
|
|
12
|
-
...checkMutationDefinitions,
|
|
13
|
-
...collectionMutationDefinitions,
|
|
14
|
-
...behaviorMutationDefinitions,
|
|
15
|
-
...referenceMutationDefinitions
|
|
16
|
-
];
|
|
1
|
+
import "./behavior-mutations.js";
|
|
2
|
+
import "./check-mutations.js";
|
|
3
|
+
import "./collection-mutations.js";
|
|
4
|
+
import "./object-mutations.js";
|
|
5
|
+
import "./presence-mutations.js";
|
|
6
|
+
import "./primitive-mutations.js";
|
|
7
|
+
import "./reference-mutations.js";
|
|
17
8
|
//# sourceMappingURL=mutation-catalog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-catalog.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/mutation-catalog.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"mutation-catalog.js","sourceRoot":"","sources":["../../../../source/stryker-zod-mutator/mutation-catalog.ts"],"names":[],"mappings":"AAAA,OAA4C,yBAAyB,CAAC;AACtE,OAAyC,sBAAsB,CAAC;AAChE,OAA8C,2BAA2B,CAAC;AAE1E,OAA0C,uBAAuB,CAAC;AAClE,OAA4C,yBAAyB,CAAC;AACtE,OAA6C,0BAA0B,CAAC;AACxE,OAA6C,0BAA0B,CAAC"}
|