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));
}
}
},
Identifier: (node: estree.Node) => {
const id = node as estree.Identifier;
const symbol = getSymbol(id, context.getScope());
const parent = getParent(context);
if (!symbol || !parent) {
return;
}
if (
!isLogicalAnd(parent) &&
!isLogicalOrLhs(id, parent) &&
!isIfStatement(parent) &&
!isLogicalNegation(parent)
) {
return;
}
const checkIfKnownAndReport = (
map: Map,
truthy: boolean,
) => {
map.forEach(references => {
const ref = references.find(ref => ref.resolved === symbol);
if (ref) {
report(id, ref, context, truthy);
}
});
};