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