Stryker

parserUtils.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
parserUtils.js
88%
24/27 24 3 0 0 0 24 3 27

Code

"use strict";
var _ = require('lodash');
var esprima = require('esprima');
var escodegen = require('escodegen');
/**
 * Utility class for parsing and generating code.
 * @constructor
 */
var esprimaOptions = {
    comment: true,
    loc: true,
    range: true,
    tokens: true,
};
/**
 * Parses code to generate an Abstract Syntax Tree.
 * @function
 * @param code - The code which has to be parsed.
 * @returns {Object} The generated Abstract Syntax Tree.
 */
function parse(code) 0{
    if (123code === undefined) 4{
        throw new Error('Code parameter cannot be undefined');
    }
    var abstractSyntaxTree = esprima.parse(code, esprimaOptions);
    return abstractSyntaxTree;
}
exports.parse = parse;
;
/**
 * Finds all nodes which have a 'type' property and freezes them.
 * @function
 * @param abstractSyntaxTree - The current part of the abstract syntax tree which will be investigated.
 * @returns  All nodes with a type.
 */
function collectFrozenNodes(abstractSyntaxTree, nodes) 5{
    nodes = 6nodes || [];
    if (7891011!_.isArray(abstractSyntaxTree) && _.isObject(abstractSyntaxTree) && abstractSyntaxTree.type && _.isUndefined(abstractSyntaxTree.nodeID)) 12{
        abstractSyntaxTree.nodeID = nodes.length;
        nodes.push(abstractSyntaxTree);
    }
    Object.freeze(abstractSyntaxTree);
    _.forOwn(abstractSyntaxTree, function (childNode, i) 13{
        if (141516childNode instanceof Object && !(childNode instanceof Array)) 17{
            collectFrozenNodes(childNode, nodes);
        }
        else if (1819childNode instanceof Array) 20{
            _.forEach(childNode, function (arrayChild) 21{
                if (222324arrayChild instanceof Object && !(arrayChild instanceof Array)) 25{
                    collectFrozenNodes(arrayChild, nodes);
                }
            });
        }
    });
    return nodes;
}
exports.collectFrozenNodes = collectFrozenNodes;
;
/**
   * Parses a Node to generate code.
   * @param The Node which has to be transformed into code.
   * @returns The generated code.
   */
function generate(node) 26{
    return escodegen.generate(node);
}
exports.generate = generate;
;
//# sourceMappingURL=parserUtils.js.map