/
drndsv
/
react
Обзор
Документация
Войти
/
drndsv
/
react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/jsx-ast-utils/src/values/expressions/LogicalExpression.js
24 строки
871 B
drndsv
Initial commit
14 апр 2025, 22:53
14 апр 2025, 22:53
641ac8a
Код
Авторство
О чём код?
/** * Extractor function for a LogicalExpression type value node. * A logical expression is `a && b` or `a || b`, so we evaluate both sides * and return the extracted value of the expression. * * @param - value - AST Value object with type `LogicalExpression` * @returns - The extracted value converted to correct type. */ export default function extractValueFromLogicalExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; const { operator, left, right } = value; const leftVal = getValue(left); const rightVal = getValue(right); if (operator === '&&') { return leftVal && rightVal; } if (operator === '??') { // return leftVal ?? rightVal; // TODO: update to babel 7 return (leftVal === null || typeof leftVal === 'undefined') ? rightVal : leftVal; } return leftVal || rightVal; }