@systemfsoftware/stryker-js-svelte 0.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # @systemfsoftware/stryker-js-svelte
2
+
3
+ ## 0.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - First release. `.svelte` files are instrumented — script blocks and template
8
+ expressions on the Svelte 5 modern AST — and their mutants are reported under
9
+ the `svelte` language.
10
+
11
+ Svelte 5 is an optional peer dependency (`^5.0.0`). The compiler is resolved
12
+ from your project when the plugin loads. When no compiler is installed, when
13
+ it exports no usable compiler surface, or when the installed major version is
14
+ not 5, the run stops before instrumentation as a configuration error naming
15
+ the peer.
16
+
17
+ Enable the plugin by installing it and adding it to `plugins`. Its format
18
+ carries the Svelte compiler version it resolved, so upgrading the compiler
19
+ invalidates the mutant results an earlier incremental run remembered for
20
+ `.svelte` files.
package/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright (c) 2026 Ryan Lee (systemfsoftware)
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright 2026 Ryan Lee (systemfsoftware)
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @systemfsoftware/stryker-js-svelte
2
+
3
+ ![version](https://img.shields.io/npm/v/@systemfsoftware/stryker-js-svelte)
4
+ ![license](https://img.shields.io/npm/l/@systemfsoftware/stryker-js-svelte)
5
+
6
+ > Framework plugin that makes Svelte 5 components first-class mutation targets.
7
+
8
+ Install the package and add it to `plugins`. The `Framework` contribution it
9
+ exports — named `svelte` — claims `.svelte` files.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pnpm add -D @systemfsoftware/stryker-js-svelte
15
+ ```
16
+
17
+ Add the package name to `plugins` in your StrykerJS config:
18
+
19
+ ```ts
20
+ import { StrykerConfig } from '@systemfsoftware/stryker-js/config'
21
+
22
+ export default StrykerConfig.define({
23
+ testRunner: 'vitest',
24
+ plugins: ['@systemfsoftware/stryker-js-svelte'],
25
+ mutate: ['src/**/*.svelte'],
26
+ })
27
+ ```
28
+
29
+ Svelte 5 itself is an optional peer dependency (`^5.0.0`), installed in the
30
+ project you mutate:
31
+
32
+ ```bash
33
+ pnpm add -D svelte
34
+ ```
35
+
36
+ ## What gets mutated
37
+
38
+ The instance script, the optional module script, and every template expression
39
+ the Svelte 5 compiler reports on the modern AST are handed to the core's own
40
+ parser and mutated as ordinary JavaScript or TypeScript — a `lang="ts"`
41
+ attribute selects the script format — and each region is printed back where it
42
+ came from, so the surrounding component does not move.
43
+
44
+ Mutants inside a component are activated by a small header the plugin places in
45
+ the component's module script. A component no mutant lands in is left
46
+ byte-for-byte alone.
47
+
48
+ ## Missing or unsupported compiler
49
+
50
+ The compiler is resolved from your project when the plugin module is evaluated,
51
+ never from a copy bundled at publish time. The supported range is `^5.0.0`
52
+ (the `svelte` entry under `peerDependencies`). When no compiler is installed,
53
+ when the installed one does not export the `VERSION` string and `parse`
54
+ function the plugin needs, or when the installed major version is not 5, the
55
+ plugin exports a refusal naming the peer instead of its framework, and the run
56
+ stops before instrumentation as a configuration error.
57
+
58
+ ## Boundaries
59
+
60
+ - The package depends inward only: on
61
+ [`@systemfsoftware/stryker-framework-interface`](https://www.npmjs.com/package/@systemfsoftware/stryker-framework-interface).
62
+ It has no Effect dependency and never depends on the instrumenter or the host.
63
+
64
+ ## Contributing
65
+
66
+ Development setup and workflow: [AGENTS.md](../AGENTS.md).
67
+
68
+ ## License
69
+
70
+ [Apache 2.0](LICENSE)
@@ -0,0 +1,4 @@
1
+ import { FrameworkContribution } from "@systemfsoftware/stryker-framework-interface";
2
+ //#region src/mod.d.ts
3
+ export declare const strykerFrameworks: readonly FrameworkContribution[];
4
+ //#endregion
package/dist/index.mjs ADDED
@@ -0,0 +1,388 @@
1
+ //#region package.json
2
+ var peerDependencies = { "svelte": "^5.0.0" };
3
+ //#endregion
4
+ //#region src/compiler.ts
5
+ const isObject = (value) => typeof value === "object" && value !== null;
6
+ const compilerOf = (module) => shapedModule(isShaped(module) ? module : void 0);
7
+ const shapedModule = (module) => module === void 0 ? void 0 : shapedVersion(module);
8
+ const shapedVersion = (module) => shapedParse(module["VERSION"], module["parse"]);
9
+ const shapedParse = (version, parse) => typeof version === "string" ? parsedVersion(version, parse) : void 0;
10
+ const parsedVersion = (version, parse) => isParseFn(parse) ? {
11
+ VERSION: version,
12
+ parse
13
+ } : void 0;
14
+ const isParseFn = (value) => typeof value === "function";
15
+ const isShaped = (module) => objectWith(module, "VERSION");
16
+ const objectWith = (module, key) => isObject(module) && key in module;
17
+ //#endregion
18
+ //#region src/discovery.ts
19
+ const PARSE_FILENAME = "component.svelte";
20
+ const NON_ERROR_FAILURE = "the svelte compiler reported a failure that is not an Error";
21
+ const discoveredOf = (compiler, rawContent) => {
22
+ const root = compiler.parse(rawContent, {
23
+ filename: PARSE_FILENAME,
24
+ modern: true
25
+ });
26
+ return {
27
+ root,
28
+ regions: regionsOf(root)
29
+ };
30
+ };
31
+ const attemptedDiscovery = (compiler, rawContent) => failedDiscovery(safeDiscovery(compiler, rawContent));
32
+ const safeDiscovery = (compiler, rawContent) => {
33
+ try {
34
+ return { discovery: discoveredOf(compiler, rawContent) };
35
+ } catch (cause) {
36
+ return { cause };
37
+ }
38
+ };
39
+ const failedDiscovery = ({ discovery, cause }) => discovery === void 0 ? failedResult(cause) : parsedDiscovery(discovery);
40
+ const failedResult = (cause) => ({
41
+ kind: "ParseFailed",
42
+ message: failureMessageOf(cause)
43
+ });
44
+ const parsedDiscovery = (discovery) => ({
45
+ kind: "Parsed",
46
+ value: discovery
47
+ });
48
+ const failureMessageOf = (cause) => messageText(cause instanceof Error ? cause.message : void 0);
49
+ const messageText = (message) => message ?? NON_ERROR_FAILURE;
50
+ const byStart$1 = (left, right) => left.start - right.start;
51
+ const regionsOf = (root) => [
52
+ scriptRegion(root.module, true),
53
+ scriptRegion(root.instance, false),
54
+ ...regionsFromFragment(root.fragment)
55
+ ].filter((region) => region !== void 0).toSorted(byStart$1);
56
+ const scriptRegion = (script, isModuleScript) => definedValue(script) ? locatedScript(script, isModuleScript) : void 0;
57
+ const locatedScript = (script, isModuleScript) => ({
58
+ start: script.content.start,
59
+ end: script.content.end,
60
+ isExpression: false,
61
+ scriptFormat: scriptFormatOf(script),
62
+ isModuleScript
63
+ });
64
+ const scriptFormatOf = (script) => script.attributes.some((attribute) => attribute.name === "lang" && declaresTs(attribute.value)) ? "ts" : "js";
65
+ const declaresTs = (value) => Array.isArray(value) && value.some((part) => part.type === "Text" && part.data === "ts");
66
+ const regionsFromFragment = (fragment) => fragment.nodes.flatMap((node) => nodeRegions(node));
67
+ const foundRegion = (expression) => ({
68
+ start: expression.start,
69
+ end: expression.end,
70
+ isExpression: true,
71
+ scriptFormat: "js",
72
+ isModuleScript: false
73
+ });
74
+ const foundRegions = (value) => value.flatMap(partRegion);
75
+ const partRegion = (part) => part.type === "ExpressionTag" ? [tagExpression(part)] : [];
76
+ const tagExpression = (tag) => foundRegion(tag.expression);
77
+ const valueExpressions = (value) => {
78
+ if (Array.isArray(value)) return foundRegions(value);
79
+ return singleTag(value);
80
+ };
81
+ const singleTag = (value) => isSingleTag(value) ? [tagExpression(value)] : [];
82
+ const isSingleTag = (value) => !Array.isArray(value) && value !== true;
83
+ const nodeRegions = (node) => {
84
+ switch (node.type) {
85
+ case "Text":
86
+ case "Comment":
87
+ case "DebugTag":
88
+ case "AttachTag": return [];
89
+ case "ExpressionTag":
90
+ case "HtmlTag":
91
+ case "RenderTag": return [foundRegion(node.expression)];
92
+ case "ConstTag":
93
+ case "DeclarationTag": return declarationRegions(node);
94
+ case "IfBlock": return ifRegions(node);
95
+ case "EachBlock": return eachRegions(node);
96
+ case "AwaitBlock": return awaitRegions(node);
97
+ case "KeyBlock": return [foundRegion(node.expression), ...regionsFromFragment(node.fragment)];
98
+ case "SnippetBlock": return regionsFromFragment(node.body);
99
+ }
100
+ return elementRegions(node);
101
+ };
102
+ const declarationRegions = (node) => initRegion(node.declaration.declarations.at(0)?.init);
103
+ const initRegion = (init) => definedValue(init) ? [foundRegion(init)] : [];
104
+ const definedValue = (value) => value !== void 0 && value !== null;
105
+ const ifRegions = (node) => [
106
+ foundRegion(node.test),
107
+ ...regionsFromFragment(node.consequent),
108
+ ...optionalFragment(node.alternate)
109
+ ];
110
+ const optionalFragment = (fragment) => definedValue(fragment) ? regionsFromFragment(fragment) : [];
111
+ const eachRegions = (node) => [
112
+ foundRegion(node.expression),
113
+ ...optionalRegion(node.key),
114
+ ...regionsFromFragment(node.body),
115
+ ...optionalFragment(node.fallback)
116
+ ];
117
+ const optionalRegion = (expression) => definedValue(expression) ? [foundRegion(expression)] : [];
118
+ const awaitRegions = (node) => [
119
+ foundRegion(node.expression),
120
+ ...optionalFragment(node.pending),
121
+ ...optionalFragment(node.then),
122
+ ...optionalFragment(node.catch)
123
+ ];
124
+ const elementRegions = (element) => [
125
+ ...element.attributes.flatMap((attribute) => attributeRegions(attribute)),
126
+ ...regionsFromFragment(element.fragment),
127
+ ...componentExpression(element)
128
+ ];
129
+ const componentExpression = (element) => {
130
+ if (element.type === "SvelteComponent") return [foundRegion(element.expression)];
131
+ return elementTag(element);
132
+ };
133
+ const elementTag = (element) => element.type === "SvelteElement" ? [foundRegion(element.tag)] : [];
134
+ const attributeRegions = (attribute) => {
135
+ switch (attribute.type) {
136
+ case "SpreadAttribute":
137
+ case "AttachTag":
138
+ case "BindDirective":
139
+ case "ClassDirective": return [foundRegion(attribute.expression)];
140
+ case "AnimateDirective":
141
+ case "OnDirective":
142
+ case "TransitionDirective":
143
+ case "UseDirective": return nullableExpression(attribute.expression);
144
+ case "Attribute":
145
+ case "StyleDirective": return valueExpressions(attribute.value);
146
+ case "LetDirective": return [];
147
+ }
148
+ };
149
+ const nullableExpression = (expression) => definedValue(expression) ? [foundRegion(expression)] : [];
150
+ //#endregion
151
+ //#region src/framework.ts
152
+ const CONTRACT_VERSION = "1";
153
+ const NEWLINE = "\n";
154
+ const NO_CHECK = "// @ts-nocheck";
155
+ const TS_LANGUAGE = "ts";
156
+ const DIRECTIVE_PATTERN = /^(\s*)@(ts-[a-z-]+).*$/;
157
+ const STARTING_COMMENT = /^\s*\/\*[\s\S]*?\*\//;
158
+ const svelteFramework = (compiler) => ({
159
+ kind: "Framework",
160
+ name: "svelte",
161
+ claim: svelteClaim(compiler.VERSION),
162
+ parse: (rawContent, context) => parseDocument(compiler, rawContent, context),
163
+ transform: (document, context) => placedDocument(compiler, document, context),
164
+ print: (document, context) => printedDocument(document, context),
165
+ disableTypeChecks: (rawContent) => noCheckedDocument(compiler, rawContent)
166
+ });
167
+ const svelteClaim = (ownerVersion) => ({
168
+ formatId: "svelte",
169
+ extensions: [".svelte"],
170
+ language: "svelte",
171
+ ownerVersion,
172
+ contractVersion: CONTRACT_VERSION
173
+ });
174
+ const parseDocument = (compiler, rawContent, context) => attemptParse(() => documentOf(rawContent, context, discoveredOf(compiler, rawContent)));
175
+ const attemptParse = (parse) => {
176
+ try {
177
+ return {
178
+ kind: "Parsed",
179
+ value: parse()
180
+ };
181
+ } catch (cause) {
182
+ return {
183
+ kind: "ParseFailed",
184
+ message: failureMessageOf(cause)
185
+ };
186
+ }
187
+ };
188
+ const documentOf = (rawContent, context, discovery) => ({
189
+ formatId: "svelte",
190
+ rawContent,
191
+ regions: discovery.regions.map((located) => regionOf(rawContent, context, located))
192
+ });
193
+ const regionOf = (rawContent, context, located) => ({
194
+ start: located.start,
195
+ end: located.end,
196
+ isExpression: located.isExpression,
197
+ scriptAst: context.parseScript(rawContent.substring(located.start, located.end), located.scriptFormat)
198
+ });
199
+ const placedDocument = (compiler, document, context) => {
200
+ const header = context.instrumentationHeader();
201
+ return document.regions.map((region) => stripPlacedHeader(region.scriptAst, header)).some((wasPlaced) => wasPlaced) ? headerDocument(compiler, document, header) : document;
202
+ };
203
+ const statementIdentity = (statement) => `${statement.type}:${statement.start}:${statement.end}`;
204
+ const stripPlacedHeader = (program, header) => header.length === 0 ? false : stripPrefix(program, header);
205
+ const stripPrefix = (program, header) => {
206
+ return header.every(headerPrefix(program)) ? removePrefix(program, header) : false;
207
+ };
208
+ const removePrefix = (program, header) => {
209
+ program.body.splice(0, header.length);
210
+ return true;
211
+ };
212
+ const headerPrefix = (program) => (expected, index) => sameStatement(program.body.at(index), expected);
213
+ const sameStatement = (present, expected) => present !== void 0 && statementIdentity(present) === statementIdentity(expected);
214
+ const headerDocument = (compiler, document, header) => placedHeaderDocument(document, header, attemptedDiscovery(compiler, document.rawContent));
215
+ const placedHeaderDocument = (document, header, discovery) => modulePlaced(document, header, discovery, locatedModuleRegion(document, discovery));
216
+ const locatedModuleRegion = (document, discovery) => discovery.kind === "Parsed" ? moduleRegionOf(document, discovery.value) : void 0;
217
+ const moduleRegionOf = (document, discovery) => matchingModule(document, locatedModule(discovery));
218
+ const locatedModule = (discovery) => discovery.regions.find((region) => region.isModuleScript);
219
+ const matchingModule = (document, located) => located === void 0 ? void 0 : document.regions.find(sharesSpan(located));
220
+ const sharesSpan = (located) => (region) => region.start === located.start && region.end === located.end;
221
+ const modulePlaced = (document, header, discovery, moduleRegion) => {
222
+ if (moduleRegion !== void 0) {
223
+ moduleRegion.scriptAst.body.unshift(...header);
224
+ return document;
225
+ }
226
+ return prependModuleScript(document, header, parsedFormat(discovery));
227
+ };
228
+ const parsedFormat = (discovery) => definedFormat(instanceRegionOf(discovery.kind === "Parsed" ? discovery.value : void 0));
229
+ const definedFormat = (region) => formatOrJs(optionalFormat(region));
230
+ const optionalFormat = (region) => region?.scriptFormat;
231
+ const formatOrJs = (format) => format ?? "js";
232
+ const instanceRegionOf = (discovery) => discovery?.regions.find((region) => !region.isModuleScript && !region.isExpression);
233
+ const moduleOpenTag = (scriptFormat) => scriptFormat === TS_LANGUAGE ? "<script module lang=\"ts\">\n" : "<script module>\n";
234
+ const prependModuleScript = (document, header, scriptFormat) => {
235
+ const openTag = moduleOpenTag(scriptFormat);
236
+ const block = `${openTag}\n<\/script>\n`;
237
+ return {
238
+ ...document,
239
+ rawContent: `${block}${document.rawContent}`,
240
+ regions: [emptyModuleRegion(openTag, header), ...document.regions.map(shiftRegion(block.length))]
241
+ };
242
+ };
243
+ const emptyModuleRegion = (openTag, header) => ({
244
+ start: openTag.length,
245
+ end: openTag.length,
246
+ isExpression: false,
247
+ scriptAst: moduleProgramOf(header)
248
+ });
249
+ const shiftRegion = (offset) => (region) => ({
250
+ ...region,
251
+ start: region.start + offset,
252
+ end: region.end + offset
253
+ });
254
+ const moduleProgramOf = (header) => ({
255
+ type: "Program",
256
+ sourceType: "module",
257
+ body: [...header],
258
+ hashbang: null
259
+ });
260
+ const printedDocument = (document, context) => {
261
+ let printed = "";
262
+ let cursor = 0;
263
+ for (const region of document.regions.toSorted(byStart)) {
264
+ printed += document.rawContent.substring(cursor, region.start);
265
+ printed += printedRegion(region, context);
266
+ cursor = region.end;
267
+ }
268
+ return printed + document.rawContent.substring(cursor);
269
+ };
270
+ const byStart = (left, right) => left.start - right.start;
271
+ const printedRegion = (region, context) => {
272
+ const printed = context.printScript(region.scriptAst);
273
+ return region.isExpression ? unpunctuated(printed) : framedScript(printed);
274
+ };
275
+ const unpunctuated = (printed) => strippedSemicolon(printed.trimEnd());
276
+ const strippedSemicolon = (trimmed) => trimmed.endsWith(";") ? trimmed.slice(0, -1) : trimmed;
277
+ const framedScript = (printed) => `${NEWLINE}${printed}${NEWLINE}`;
278
+ const noCheckedDocument = (compiler, rawContent) => {
279
+ const discovery = attemptedDiscovery(compiler, rawContent);
280
+ if (discovery.kind === "ParseFailed") return discovery;
281
+ return {
282
+ kind: "Parsed",
283
+ value: noCheckedContent(rawContent, discovery.value)
284
+ };
285
+ };
286
+ const noCheckedContent = (rawContent, discovery) => {
287
+ const scripts = scriptRegionsOf(discovery);
288
+ return applyRightToLeft(rawContent, [...scriptSplices(rawContent, discovery, scripts), ...outsideDirectives(discovery.root.comments, scripts)]);
289
+ };
290
+ const scriptRegionsOf = (discovery) => discovery.regions.filter((region) => !region.isExpression);
291
+ const scriptSplices = (rawContent, discovery, scripts) => scripts.map(scriptSplice(rawContent, discovery.root.comments));
292
+ const scriptSplice = (rawContent, comments) => (region) => ({
293
+ start: region.start,
294
+ end: region.end,
295
+ replacement: framedScript(regionReplacement(rawContent, region, comments))
296
+ });
297
+ const regionReplacement = (rawContent, region, comments) => prefixWithNoCheck(applyRightToLeft(bodyOf(rawContent, region), innerSplices(region, comments)));
298
+ const bodyOf = (rawContent, region) => rawContent.substring(region.start, region.end);
299
+ const innerSplices = (region, comments) => containedComments(region, comments).map(regionSplice(region)).filter(definedSplice);
300
+ const regionSplice = (region) => (comment) => directiveSplice(comment, -region.start);
301
+ const containedComments = (region, comments) => comments.filter(inRegion(region));
302
+ const inRegion = (region) => (comment) => comment.start >= region.start && comment.end <= region.end;
303
+ const definedSplice = (splice) => splice !== void 0;
304
+ const outsideDirectives = (comments, scripts) => comments.filter(outsideScripts(scripts)).map(topLevelSplice).filter(definedSplice);
305
+ const outsideScripts = (scripts) => (comment) => !scripts.some(containsComment(comment));
306
+ const topLevelSplice = (comment) => directiveSplice(comment, 0);
307
+ const containsComment = (comment) => (region) => comment.start >= region.start && comment.end <= region.end;
308
+ const directiveSplice = (comment, offset) => directiveCapture(DIRECTIVE_PATTERN.exec(comment.value), comment, offset);
309
+ const directiveCapture = (match, comment, offset) => match === null ? void 0 : directiveRanges(comment, offset, match.input);
310
+ const directiveRanges = (comment, offset, value) => {
311
+ const atSign = value.indexOf("@");
312
+ return rangeSplice(comment.start + offset + atSign + 2, directiveToken(value.substring(atSign + 1)));
313
+ };
314
+ const directiveToken = (afterAt) => afterAt.substring(0, tokenEnd(afterAt));
315
+ const tokenEnd = (text) => {
316
+ const end = text.search(/[^a-z-]/);
317
+ return end === -1 ? text.length : end;
318
+ };
319
+ const rangeSplice = (start, directive) => ({
320
+ start,
321
+ end: start + directive.length + 1,
322
+ replacement: ""
323
+ });
324
+ const applyRightToLeft = (text, splices) => accumulateSplices(text, splices.toSorted(byDescendingStart), text.length, "");
325
+ const accumulateSplices = (text, splices, tail, out) => {
326
+ const head = splices.at(0);
327
+ return head === void 0 ? `${text.substring(0, tail)}${out}` : splicedTail(text, splices, head, tail, out);
328
+ };
329
+ const splicedTail = (text, splices, head, tail, out) => accumulateSplices(text, splices.slice(1), head.start, `${head.replacement}${text.substring(head.end, tail)}${out}`);
330
+ const byDescendingStart = (left, right) => right.start - left.start;
331
+ const prefixWithNoCheck = (code) => code.startsWith("#") ? withHashbangNoCheck(code) : withCommentNoCheck(code);
332
+ const withHashbangNoCheck = (code) => {
333
+ const newLineIndex = code.indexOf(NEWLINE);
334
+ return newLineIndex <= 0 ? code : hashbangSplice(code, newLineIndex);
335
+ };
336
+ const hashbangSplice = (code, newLineIndex) => `${code.substring(0, newLineIndex)}${NEWLINE}${NO_CHECK}${NEWLINE}${code.substring(newLineIndex + 1)}`;
337
+ const withCommentNoCheck = (code) => commentPrefix(STARTING_COMMENT.exec(code)?.at(0), code);
338
+ const commentPrefix = (leadingComment, code) => leadingComment === void 0 ? `${NO_CHECK}${NEWLINE}${code}` : commentSplice(code, leadingComment);
339
+ const commentSplice = (code, leadingComment) => `${leadingComment}${NEWLINE}${NO_CHECK}${NEWLINE}${code.substring(leadingComment.length)}`;
340
+ //#endregion
341
+ //#region src/peer.ts
342
+ const COMPILER_SPECIFIER = "svelte/compiler";
343
+ const PLUGIN_NAME = "svelte";
344
+ const PLUGIN_PEER = "svelte";
345
+ const NOT_FOUND_CODES = {
346
+ ERR_MODULE_NOT_FOUND: true,
347
+ MODULE_NOT_FOUND: true
348
+ };
349
+ const SUPPORTED_RANGE = peerDependencies.svelte;
350
+ const majorOf = (version) => Number.parseInt(version.replace(/^\D+/, ""), 10);
351
+ const SUPPORTED_MAJOR = majorOf(SUPPORTED_RANGE);
352
+ const loadPeer = async (specifier) => import(specifier).then(loadedPeer, refusedPeer);
353
+ const contributionOf = async (load) => decideContribution(await load());
354
+ const loadedPeer = (module) => ({
355
+ kind: "Loaded",
356
+ module
357
+ });
358
+ const refusedPeer = (cause) => missingPeer(cause);
359
+ const missingPeer = (cause) => knownCode(codeOf(cause)) ? { kind: "Missing" } : Promise.reject(cause);
360
+ const knownCode = (code) => code !== void 0 && isKnownCode(code);
361
+ const isKnownCode = (code) => NOT_FOUND_CODES[code] === true;
362
+ const codeOf = (cause) => codedText(codedCause(cause));
363
+ const codedCause = (cause) => keyedCause(objectCause(cause));
364
+ const objectCause = (cause) => isObject(cause) ? cause : void 0;
365
+ const keyedCause = (cause) => cause === void 0 ? void 0 : codedKey(cause);
366
+ const codedKey = (cause) => "code" in cause ? cause : void 0;
367
+ const codedText = (cause) => textOf(cause?.["code"]);
368
+ const textOf = (value) => typeof value === "string" ? value : void 0;
369
+ const decideContribution = (loaded) => loaded.kind === "Missing" ? missingRefusal() : peerContribution(loaded.module);
370
+ const missingRefusal = () => refusalOf("PeerMissing", `the "${PLUGIN_PEER}" peer is not installed`);
371
+ const peerContribution = (module) => unrecognizedOf(compilerOf(module));
372
+ const unrecognizedOf = (compiler) => compiler === void 0 ? unrecognizedRefusal() : versionContribution(compiler);
373
+ const unrecognizedRefusal = () => refusalOf("PeerUnrecognized", `the "${COMPILER_SPECIFIER}" module must export a VERSION string and a parse function`);
374
+ const versionContribution = (compiler) => versionMatches(compiler.VERSION) ? svelteFramework(compiler) : versionRefusal(compiler.VERSION);
375
+ const versionMatches = (version) => majorOf(version) === SUPPORTED_MAJOR;
376
+ const versionRefusal = (version) => refusalOf("PeerVersionUnsupported", `svelte ${version} is not supported (expected ${SUPPORTED_RANGE})`);
377
+ const refusalOf = (reason, detail) => ({
378
+ kind: "FrameworkRefusal",
379
+ name: PLUGIN_NAME,
380
+ reason,
381
+ peer: PLUGIN_PEER,
382
+ detail
383
+ });
384
+ //#endregion
385
+ //#region src/mod.ts
386
+ const strykerFrameworks = [await contributionOf(() => loadPeer(COMPILER_SPECIFIER))];
387
+ //#endregion
388
+ export { strykerFrameworks };
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@systemfsoftware/stryker-js-svelte",
3
+ "license": "Apache-2.0",
4
+ "version": "0.0.0",
5
+ "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/systemfsoftware/stryker-js-effect.git",
9
+ "directory": "packages/frameworks/svelte"
10
+ },
11
+ "homepage": "https://github.com/systemfsoftware/stryker-js-effect/tree/main/packages/frameworks/svelte#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/systemfsoftware/stryker-js-effect/issues"
14
+ },
15
+ "description": "Stryker framework plugin for Svelte components: claims .svelte files, resolves the svelte compiler from the project install, and refuses the run with a typed reason when the compiler is missing or too old.",
16
+ "keywords": [
17
+ "stryker",
18
+ "stryker-mutator",
19
+ "mutation-testing",
20
+ "svelte",
21
+ "framework",
22
+ "plugin"
23
+ ],
24
+ "type": "module",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.mjs"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "strykerFramework": {
36
+ "extensions": [
37
+ ".svelte"
38
+ ]
39
+ },
40
+ "dependencies": {
41
+ "@systemfsoftware/stryker-framework-interface": "^0.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@effect/tsgo": "^0.45.0",
45
+ "@microsoft/api-extractor": "^7",
46
+ "@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
47
+ "@systemfsoftware/tsconfig": "^2.0.1",
48
+ "@types/estree": "^1.0.5",
49
+ "@types/node": "^24",
50
+ "@vitest/coverage-v8": "^5",
51
+ "oxc-parser": "^0.150.0",
52
+ "oxlint": "^1",
53
+ "rimraf": "^6.1.3",
54
+ "svelte": "^5",
55
+ "tsdown": "^0.23.0",
56
+ "typescript": "^7",
57
+ "vitest": "^5",
58
+ "@systemfsoftware/vitest-config": "^0.1.0",
59
+ "@systemfsoftware/oxlint-ignorer-config": "^0.1.1",
60
+ "@systemfsoftware/tsdown-config": "^0.1.0"
61
+ },
62
+ "peerDependencies": {
63
+ "svelte": "^5.0.0"
64
+ },
65
+ "peerDependenciesMeta": {
66
+ "svelte": {
67
+ "optional": true
68
+ }
69
+ },
70
+ "publishConfig": {
71
+ "access": "public",
72
+ "provenance": true
73
+ },
74
+ "scripts": {
75
+ "build": "tsdown",
76
+ "clean": "rimraf dist",
77
+ "typecheck": "tsc -b",
78
+ "test": "vitest run",
79
+ "lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
80
+ "attw": "attw --pack .",
81
+ "api:check": "api-extractor run",
82
+ "api:update": "api-extractor run --local",
83
+ "lint:tsgo": "effect-tsgo diagnostics --project tsconfig.app.json --format ${TSGO_FORMAT:-text} && effect-tsgo diagnostics --project tsconfig.test.json --format ${TSGO_FORMAT:-text}"
84
+ }
85
+ }