|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
993 bytes
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Extractor function for a UnaryExpression type value node.
|
|---|
| 3 | * A unary expression is an expression with a unary operator.
|
|---|
| 4 | * For example, !"foobar" will evaluate to false, so this will return false.
|
|---|
| 5 | *
|
|---|
| 6 | * @param - value - AST Value object with type `UnaryExpression`
|
|---|
| 7 | * @returns - The extracted value converted to correct type.
|
|---|
| 8 | */
|
|---|
| 9 | export default function extractValueFromUnaryExpression(value) {
|
|---|
| 10 | // eslint-disable-next-line global-require
|
|---|
| 11 | const getValue = require('.').default;
|
|---|
| 12 | const { operator, argument } = value;
|
|---|
| 13 |
|
|---|
| 14 | switch (operator) {
|
|---|
| 15 | case '-':
|
|---|
| 16 | return -getValue(argument);
|
|---|
| 17 | case '+':
|
|---|
| 18 | return +getValue(argument); // eslint-disable-line no-implicit-coercion
|
|---|
| 19 | case '!':
|
|---|
| 20 | return !getValue(argument);
|
|---|
| 21 | case '~':
|
|---|
| 22 | return ~getValue(argument); // eslint-disable-line no-bitwise
|
|---|
| 23 | case 'delete':
|
|---|
| 24 | // I believe delete statements evaluate to true.
|
|---|
| 25 | return true;
|
|---|
| 26 | case 'typeof':
|
|---|
| 27 | case 'void':
|
|---|
| 28 | default:
|
|---|
| 29 | return undefined;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.