1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const plugin_1 = require("@stryker-mutator/api/plugin");
|
4 | const copy_1 = require("./helpers/copy");
|
5 | const tokens_1 = require("./helpers/tokens");
|
6 | class JavaScriptMutator {
|
7 | constructor(log, mutators, parser) {
|
8 | this.log = log;
|
9 | this.mutators = mutators;
|
10 | this.parser = parser;
|
11 | }
|
12 | mutate(inputFiles) {
|
13 | const mutants = [];
|
14 | inputFiles.forEach(file => {
|
15 | const ast = this.parser.parse(file.textContent);
|
16 | this.parser.getNodes(ast).forEach(node => {
|
17 | this.mutators.forEach(mutator => {
|
18 | const mutatedNodes = mutator.mutate(node, copy_1.default);
|
19 | if (mutatedNodes) {
|
20 | const newMutants = this.generateMutants(mutatedNodes, mutator.name, file.name);
|
21 | mutants.push(...newMutants);
|
22 | }
|
23 | });
|
24 | });
|
25 | });
|
26 | return mutants;
|
27 | }
|
28 | generateMutants(mutatedNodes, mutatorName, fileName) {
|
29 | const mutants = [];
|
30 | mutatedNodes.forEach(node => {
|
31 | const replacement = this.parser.generateCode(node);
|
32 | if (node.start !== null && node.end !== null) {
|
33 | const range = [node.start, node.end];
|
34 | const mutant = {
|
35 | fileName,
|
36 | mutatorName,
|
37 | range,
|
38 | replacement
|
39 | };
|
40 | this.log.trace(`Generated mutant for mutator ${mutatorName} in file ${fileName} with replacement code "${replacement}"`);
|
41 | mutants.push(mutant);
|
42 | }
|
43 | });
|
44 | return mutants;
|
45 | }
|
46 | }
|
47 | exports.JavaScriptMutator = JavaScriptMutator;
|
48 | JavaScriptMutator.inject = plugin_1.tokens(plugin_1.commonTokens.logger, tokens_1.NODE_MUTATORS_TOKEN, tokens_1.PARSER_TOKEN);
|
49 |
|
\ | No newline at end of file |