UNPKG

stryker

Version:
43 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var esprima_1 = require("esprima"); /** * Represents a mutator which can remove the conditional clause from statements. */ var RemoveConditionalsMutator = /** @class */ (function () { function RemoveConditionalsMutator() { this.name = 'RemoveConditionals'; this.types = [esprima_1.Syntax.DoWhileStatement, esprima_1.Syntax.IfStatement, esprima_1.Syntax.ForStatement, esprima_1.Syntax.WhileStatement, esprima_1.Syntax.ConditionalExpression]; } RemoveConditionalsMutator.prototype.applyMutations = function (node, copy) { if (this.canMutate(node)) { var nodes = []; if (node.test) { nodes.push(this.booleanLiteralNode(node.test.nodeID, false)); } else { var mutatedNode = copy(node); mutatedNode.test = this.booleanLiteralNode(-1, false); nodes.push(mutatedNode); } if (node.type === esprima_1.Syntax.IfStatement || node.type === esprima_1.Syntax.ConditionalExpression) { nodes.push(this.booleanLiteralNode(node.test.nodeID, true)); } return nodes; } }; RemoveConditionalsMutator.prototype.booleanLiteralNode = function (nodeID, value) { return { nodeID: nodeID, raw: value.toString(), type: esprima_1.Syntax.Literal, value: value }; }; RemoveConditionalsMutator.prototype.canMutate = function (node) { return this.types.indexOf(node.type) >= 0; }; return RemoveConditionalsMutator; }()); exports.default = RemoveConditionalsMutator; //# sourceMappingURL=RemoveConditionalsMutator.js.map