eslint-plugin-de-morgan
Version:
ESLint plugin for transforming negated boolean expressions via De Morgan’s laws
22 lines (21 loc) • 764 B
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
const isLogicalExpression = require('./is-logical-expression.js')
let isInParentheses = (start, end, sourceCode) =>
sourceCode[start - 1] === '(' && sourceCode[end] === ')'
let findOutermostParenthesizedNode = (node, sourceCode) => {
let current = node
let [start, end] = current.range
if (isInParentheses(start, end, sourceCode)) {
return current
}
while (current.parent && isLogicalExpression.isLogicalExpression(current)) {
current = current.parent
;[start, end] = current.range
if (isInParentheses(start, end, sourceCode)) {
return current
}
}
return current
}
exports.findOutermostParenthesizedNode = findOutermostParenthesizedNode