@systemfsoftware/stryker-js-instrumenter 0.1.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.
@@ -0,0 +1,246 @@
1
+ import { BaseContext, Injector, PluginKind } from "@systemfsoftware/stryker-js-plugin-api/plugin";
2
+ import { FileDescription, Mutant, MutateDescription, Position } from "@systemfsoftware/stryker-js-plugin-api/core";
3
+ import { types } from "@babel/core";
4
+ import { I } from "@systemfsoftware/stryker-js-util";
5
+ import { Ignorer } from "@systemfsoftware/stryker-js-plugin-api/ignore";
6
+ import { Logger } from "@systemfsoftware/stryker-js-plugin-api/logging";
7
+ //#region src/instrumenter-tokens.d.ts
8
+ declare const instrumenterTokens: Readonly<{
9
+ readonly createParser: 'instrumenterCreateParser';
10
+ readonly print: 'instrumenterPrint';
11
+ readonly transform: 'instrumenterTransform';
12
+ }>;
13
+ //#endregion
14
+ //#region src/syntax/index.d.ts
15
+ declare enum AstFormat {
16
+ Html = "html",
17
+ JS = "js",
18
+ TS = "ts",
19
+ Tsx = "tsx",
20
+ Svelte = "svelte"
21
+ }
22
+ interface AstByFormat {
23
+ [AstFormat.Html]: HtmlAst;
24
+ [AstFormat.JS]: JSAst;
25
+ [AstFormat.TS]: TSAst;
26
+ [AstFormat.Tsx]: TsxAst;
27
+ [AstFormat.Svelte]: SvelteAst;
28
+ }
29
+ type Ast = HtmlAst | JSAst | SvelteAst | TSAst | TsxAst;
30
+ type ScriptAst = JSAst | TSAst | TsxAst;
31
+ interface BaseAst {
32
+ originFileName: string;
33
+ rawContent: string;
34
+ root: Ast['root'];
35
+ offset?: Position;
36
+ }
37
+ /**
38
+ * Represents an Html AST.
39
+ */
40
+ interface HtmlAst extends BaseAst {
41
+ format: AstFormat.Html;
42
+ root: HtmlRootNode;
43
+ }
44
+ /**
45
+ * Represents a TS AST
46
+ */
47
+ interface JSAst extends BaseAst {
48
+ format: AstFormat.JS;
49
+ root: types.File;
50
+ }
51
+ /**
52
+ * Represents a TS AST
53
+ */
54
+ interface TSAst extends BaseAst {
55
+ format: AstFormat.TS;
56
+ root: types.File;
57
+ }
58
+ /**
59
+ * Represents a TS AST
60
+ */
61
+ interface TsxAst extends BaseAst {
62
+ format: AstFormat.Tsx;
63
+ root: types.File;
64
+ }
65
+ /**
66
+ * Represents a Svelte AST
67
+ */
68
+ interface SvelteAst extends BaseAst {
69
+ format: AstFormat.Svelte;
70
+ root: SvelteRootNode;
71
+ }
72
+ /**
73
+ * Represents the root node of an HTML AST
74
+ * We've taken a shortcut here, instead of representing the entire AST, we're only representing the script tags.
75
+ * We might need to expand this in the future if we would ever want to support mutating the actual HTML (rather than only the JS/TS)
76
+ */
77
+ interface HtmlRootNode {
78
+ scripts: ScriptAst[];
79
+ }
80
+ interface SvelteRootNode {
81
+ moduleScript?: TemplateScript;
82
+ additionalScripts: TemplateScript[];
83
+ }
84
+ /**
85
+ * Represents a svelte script or binding expression
86
+ * We've taken a shortcut here, instead of representing the entire AST, we're only representing the script tags and expression bindings.
87
+ */
88
+ interface TemplateScript {
89
+ ast: ScriptAst;
90
+ range: Range;
91
+ isExpression: boolean;
92
+ }
93
+ interface Range {
94
+ start: number;
95
+ end: number;
96
+ }
97
+ //#endregion
98
+ //#region src/parsers/parser-options.d.ts
99
+ interface ParserOptions {
100
+ plugins: unknown[] | null;
101
+ }
102
+ //#endregion
103
+ //#region src/parsers/create-parser.d.ts
104
+ declare function createParser(parserOptions: ParserOptions): {
105
+ <T extends AstFormat>(code: string, fileName: string, formatOverride: T): Promise<AstByFormat[T]>;
106
+ (code: string, fileName: string, formatOverride?: AstFormat): Promise<Ast>;
107
+ };
108
+ //#endregion
109
+ //#region src/printers/index.d.ts
110
+ declare function print(file: Ast): string;
111
+ //#endregion
112
+ //#region src/mutant.d.ts
113
+ interface Mutable {
114
+ mutatorName: string;
115
+ ignoreReason?: string | undefined;
116
+ replacement: types.Node;
117
+ }
118
+ declare class Mutant$1 implements Mutable {
119
+ readonly id: string;
120
+ readonly fileName: string;
121
+ readonly original: types.Node;
122
+ readonly offset: Position;
123
+ readonly replacementCode: string;
124
+ readonly replacement: types.Node;
125
+ readonly mutatorName: string;
126
+ readonly ignoreReason: string | undefined;
127
+ constructor(id: string, fileName: string, original: types.Node, specs: Mutable, offset?: Position);
128
+ toApiMutant(): Mutant;
129
+ /**
130
+ * Applies the mutant in (a copy of) the AST, without changing provided AST.
131
+ * Can the tree itself (in which case the replacement is returned),
132
+ * or can be nested in the given tree.
133
+ *
134
+ * Returns a plain node rather than the argument's own type: whether the
135
+ * replacement fits a given position is the placer's claim, and the placer
136
+ * checks it with a Babel predicate. A generic return would have to assert it
137
+ * here, where nothing can check it.
138
+ * @param originalTree The original node, which will be treated as readonly
139
+ */
140
+ applied(originalTree: types.Node): types.Node;
141
+ }
142
+ //#endregion
143
+ //#region src/transformers/mutant-collector.d.ts
144
+ declare class MutantCollector {
145
+ private readonly _mutants;
146
+ get mutants(): readonly Mutant$1[];
147
+ /**
148
+ * Adds mutants to the internal mutant list.
149
+ * @param fileName file name that houses the mutant
150
+ * @param original The node to mutate
151
+ * @param mutables the named node mutation to be added
152
+ * @param contextPath the context where these mutants are found and should be placed as close by as possible
153
+ * @param offset offset of mutant nodes
154
+ * @returns The mutant (for testability)
155
+ */
156
+ collect(fileName: string, original: types.Node, mutable: Mutable, offset?: Position): Mutant$1;
157
+ hasPlacedMutants(fileName: string): boolean;
158
+ }
159
+ //#endregion
160
+ //#region src/mutators/mutator-options.d.ts
161
+ interface MutatorOptions {
162
+ excludedMutations: string[];
163
+ noHeader?: boolean;
164
+ }
165
+ //#endregion
166
+ //#region src/transformers/transformer-options.d.ts
167
+ interface TransformerOptions extends MutatorOptions {
168
+ ignorers: Ignorer[];
169
+ }
170
+ //#endregion
171
+ //#region src/transformers/transformer.d.ts
172
+ /**
173
+ * Transform the AST by generating mutants and placing them in the AST.
174
+ * Supports all AST formats supported by Stryker.
175
+ * @param ast The Abstract Syntax Tree
176
+ * @param mutantCollector the mutant collector that will be used to register and administer mutants
177
+ * @param transformerContext the options used during transforming
178
+ */
179
+ declare function transform(ast: Ast, mutantCollector: I<MutantCollector>, transformerContext: Omit<TransformerContext, 'transform'>): void;
180
+ type AstTransformer<T extends AstFormat> = (ast: AstByFormat[T], mutantCollector: I<MutantCollector>, context: TransformerContext) => void;
181
+ interface TransformerContext {
182
+ transform: AstTransformer<AstFormat>;
183
+ options: TransformerOptions;
184
+ mutateDescription: MutateDescription;
185
+ logger: Logger;
186
+ }
187
+ //#endregion
188
+ //#region src/create-instrumenter.d.ts
189
+ interface InstrumenterContext extends BaseContext {
190
+ [instrumenterTokens.createParser]: typeof createParser;
191
+ [instrumenterTokens.print]: typeof print;
192
+ [instrumenterTokens.transform]: typeof transform;
193
+ }
194
+ declare function createInstrumenter(injector: Injector<BaseContext>): Instrumenter;
195
+ declare namespace createInstrumenter {
196
+ var inject: ["$injector"];
197
+ }
198
+ //#endregion
199
+ //#region src/file.d.ts
200
+ interface File extends FileDescription {
201
+ name: string;
202
+ content: string;
203
+ }
204
+ //#endregion
205
+ //#region src/disable-type-checks.d.ts
206
+ /**
207
+ * Disables TypeScript type checking for a single file by inserting `// @ts-nocheck` commands.
208
+ * It also does this for *.js files, as they can be type checked by typescript as well.
209
+ * Other file types are silently ignored
210
+ *
211
+ * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#-ts-nocheck-in-typescript-files
212
+ */
213
+ declare function disableTypeChecks(file: File, options: ParserOptions): Promise<File>;
214
+ //#endregion
215
+ //#region src/frameworks/index.d.ts
216
+ declare const strykerPlugins: import("@systemfsoftware/stryker-js-plugin-api/plugin").ClassPlugin<PluginKind.Ignore, []>[];
217
+ declare const frameworkPluginsFileUrl: string;
218
+ //#endregion
219
+ //#region src/instrument-result.d.ts
220
+ interface InstrumentResult {
221
+ files: readonly File[];
222
+ mutants: readonly Mutant[];
223
+ }
224
+ //#endregion
225
+ //#region src/instrumenter-options.d.ts
226
+ interface InstrumenterOptions extends ParserOptions, TransformerOptions {}
227
+ //#endregion
228
+ //#region src/instrumenter.d.ts
229
+ /**
230
+ * The instrumenter is responsible for
231
+ * * Generating mutants based on source files
232
+ * * Instrumenting the source code with the mutants placed in `mutant switches`.
233
+ * * Adding mutant coverage expressions in the source code.
234
+ * @see https://github.com/stryker-mutator/stryker-js/issues/1514
235
+ */
236
+ declare class Instrumenter {
237
+ private readonly logger;
238
+ private readonly _createParser;
239
+ private readonly _print;
240
+ private readonly _transform;
241
+ static inject: ["logger", "instrumenterCreateParser", "instrumenterPrint", "instrumenterTransform"];
242
+ constructor(logger: Logger, _createParser?: typeof createParser, _print?: typeof print, _transform?: typeof transform);
243
+ instrument(files: readonly File[], options: InstrumenterOptions): Promise<InstrumentResult>;
244
+ }
245
+ //#endregion
246
+ export { File, InstrumentResult, Instrumenter, InstrumenterContext, InstrumenterOptions, type ParserOptions, createInstrumenter, disableTypeChecks, frameworkPluginsFileUrl, strykerPlugins };