Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public applyMutations(node: IdentifiedNode, copy: (obj: T, deep?: boolean) => T): IdentifiedNode[] {
const nodes: IdentifiedNode[] = [];
// !a -> a
if (node.type === Syntax.UnaryExpression && node.operator === '!') {
const mutatedNode = copy(node.argument as Expression & Identified) as IdentifiedNode;
mutatedNode.nodeID = node.nodeID;
nodes.push(mutatedNode);
}
// true -> false or false -> true
if (node.type === Syntax.Literal && typeof node.value === 'boolean') {
const mutatedNode = copy(node);
mutatedNode.value = !mutatedNode.value;
nodes.push(mutatedNode);
}
return nodes;
}
constructor(node, moduleName) {
this.node = node;
this.name = moduleName;
this.dependencyArray = null;
this.factory = null;
const args = node.arguments;
let i = 0;
let params;
if ( args[i].type === Syntax.Literal ) {
// assert(String)
this.name = args[i++].value;
}
if ( args[i].type === Syntax.ArrayExpression ) {
this.dependencyArray = args[i++];
this.dependencies = this.dependencyArray.elements.map( (elem) => {
if ( !isString(elem) ) {
throw new TypeError();
}
return ModuleName.resolveRelativeRequireJSName(this.name, elem.value);
});
this.dependencyInsertionIdx = this.dependencyArray.elements.length;
}
if ( args[i].type === Syntax.FunctionExpression ) {
function getPropertyKey(property) {
if ( property.key.type === Syntax.Identifier ) {
return property.key.name;
} else if ( property.key.type === Syntax.Literal ) {
return String(property.key.value);
} else {
throw new Error();
}
}
private booleanLiteralNode(nodeID: number, value: boolean): estree.SimpleLiteral & Identified {
return {
nodeID,
raw: value.toString(),
type: Syntax.Literal,
value
};
}