Stryker

RemoveConditionalsMutator.js - Stryker report

Summary

File Based on all code Based on code coverage
RemoveConditionalsMutator.js
100%
16/16 100% 16/16

Code

"use strict";
var esprima_1 = require('esprima');
/**
 * Represents a mutator which can remove the conditional clause from statements.
 */
var RemoveConditionalsMutator = (function () 0{
    function RemoveConditionalsMutator() 1{
        this.name = 'RemoveConditionals';
        this.types = [esprima_1.Syntax.DoWhileStatement, esprima_1.Syntax.IfStatement, esprima_1.Syntax.ForStatement, esprima_1.Syntax.WhileStatement];
    }

    RemoveConditionalsMutator.prototype.applyMutations = function (node, copy) 2{
        var nodes = [];
        if (34this.canMutate(node)) 5{
            var mutatedFalseNode = copy(node.test);
            this.mutateTestExpression(mutatedFalseNode, false);
            nodes.push(mutatedFalseNode);
            if (678node.type === esprima_1.Syntax.IfStatement) 9{
                var mutatedTrueNode = copy(node.test);
                this.mutateTestExpression(mutatedTrueNode, true);
                nodes.push(mutatedTrueNode);
            }

        }

        return nodes;
    };
    RemoveConditionalsMutator.prototype.mutateTestExpression = function (node, newValue) 10{
        node.type = esprima_1.Syntax.Literal;
        node.value = newValue;
    };
    RemoveConditionalsMutator.prototype.canMutate = function (node) 11{
        return !!(12node && 1314this.types.indexOf(node.type) >= 0);
    };
    ;
    RemoveConditionalsMutator.prototype.copyNode = function (node) 15{
        return JSON.parse(JSON.stringify(node));
    };
    return RemoveConditionalsMutator;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = RemoveConditionalsMutator;
//# sourceMappingURL=RemoveConditionalsMutator.js.map