Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
":statement": (node: estree.Node) => {
const parent = getParent(context);
if (parent && isIfStatement(parent)) {
// we visit 'consequent' and 'alternate' and not if-statement directly in order to get scope for 'consequent'
const currentScope = context.getScope();
if (parent.consequent === node) {
const { truthy, falsy } = collectKnownIdentifiers(parent.test);
truthyMap.set(parent.consequent, transformAndFilter(truthy, currentScope));
falsyMap.set(parent.consequent, transformAndFilter(falsy, currentScope));
} else if (parent.alternate === node && isIdentifier(parent.test)) {
falsyMap.set(parent.alternate, transformAndFilter([parent.test], currentScope));
}
}
},
const checkExpr = (expr: estree.Expression) => {
if (isIdentifier(expr)) {
truthy.push(expr);
} else if (isLogicalNegation(expr)) {
if (isIdentifier(expr.argument)) {
falsy.push(expr.argument);
} else if (isLogicalNegation(expr.argument) && isIdentifier(expr.argument.argument)) {
truthy.push(expr.argument.argument);
}
}
};
function isBasicValue(node: estree.Node): boolean {
if (isLiteral(node)) {
return node.value === "" || [0, 1, null, true, false].includes(node.value as any);
}
if (isIdentifier(node)) {
return node.name === "undefined";
}
if (isUnaryExpression(node)) {
return isBasicValue(node.argument);
}
if (isObjectExpression(node)) {
return node.properties.length === 0;
}
if (isArrayExpression(node)) {
return node.elements.length === 0;
}
return false;
}
const checkExpr = (expr: estree.Expression) => {
if (isIdentifier(expr)) {
truthy.push(expr);
} else if (isLogicalNegation(expr)) {
if (isIdentifier(expr.argument)) {
falsy.push(expr.argument);
} else if (isLogicalNegation(expr.argument) && isIdentifier(expr.argument.argument)) {
truthy.push(expr.argument.argument);
}
}
};
arg => (isIdentifier(arg) ? arg.name : undefined),
);
const checkExpr = (expr: estree.Expression) => {
if (isIdentifier(expr)) {
truthy.push(expr);
} else if (isLogicalNegation(expr)) {
if (isIdentifier(expr.argument)) {
falsy.push(expr.argument);
} else if (isLogicalNegation(expr.argument) && isIdentifier(expr.argument.argument)) {
truthy.push(expr.argument.argument);
}
}
};