main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
871 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * Extractor function for a LogicalExpression type value node.
|
---|
3 | * A logical expression is `a && b` or `a || b`, so we evaluate both sides
|
---|
4 | * and return the extracted value of the expression.
|
---|
5 | *
|
---|
6 | * @param - value - AST Value object with type `LogicalExpression`
|
---|
7 | * @returns - The extracted value converted to correct type.
|
---|
8 | */
|
---|
9 | export default function extractValueFromLogicalExpression(value) {
|
---|
10 | // eslint-disable-next-line global-require
|
---|
11 | const getValue = require('.').default;
|
---|
12 | const { operator, left, right } = value;
|
---|
13 | const leftVal = getValue(left);
|
---|
14 | const rightVal = getValue(right);
|
---|
15 |
|
---|
16 | if (operator === '&&') {
|
---|
17 | return leftVal && rightVal;
|
---|
18 | }
|
---|
19 | if (operator === '??') {
|
---|
20 | // return leftVal ?? rightVal; // TODO: update to babel 7
|
---|
21 | return (leftVal === null || typeof leftVal === 'undefined') ? rightVal : leftVal;
|
---|
22 | }
|
---|
23 | return leftVal || rightVal;
|
---|
24 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.