File |
Mutation score |
# Killed |
# Survived |
# Timeout |
# No coverage |
# Errors |
Total detected |
Total undetected |
Total mutants |
|
---|---|---|---|---|---|---|---|---|---|---|
parserUtils.js |
|
24/27 | 24 | 3 | 0 | 0 | 0 | 24 | 3 | 27 |
"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 (1code !== undefined2true3falsecode === 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 && []nodes || [];
if (7false8true9!_.isArray(abstractSyntaxTree) && _.isObject(abstractSyntaxTree) && abstractSyntaxTree.type || _.isUndefined(abstractSyntaxTree.nodeID)10!_.isArray(abstractSyntaxTree) && _.isObject(abstractSyntaxTree) || abstractSyntaxTree.type11!_.isArray(abstractSyntaxTree) || _.isObject(abstractSyntaxTree)!_.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 (14false15true16childNode instanceof Object || !(childNode instanceof Array)childNode instanceof Object && !(childNode instanceof Array)) 17{
}{
collectFrozenNodes(childNode, nodes);
}
else if (18false19truechildNode instanceof Array) 20{
}{
_.forEach(childNode, function (arrayChild) 21{
}{
if (22false23true24arrayChild instanceof Object || !(arrayChild instanceof Array)arrayChild 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