|
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:
1.1 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = extractValueFromUnaryExpression;
|
|---|
| 7 | /**
|
|---|
| 8 | * Extractor function for a UnaryExpression type value node.
|
|---|
| 9 | * A unary expression is an expression with a unary operator.
|
|---|
| 10 | * For example, !"foobar" will evaluate to false, so this will return false.
|
|---|
| 11 | *
|
|---|
| 12 | * @param - value - AST Value object with type `UnaryExpression`
|
|---|
| 13 | * @returns - The extracted value converted to correct type.
|
|---|
| 14 | */
|
|---|
| 15 | function extractValueFromUnaryExpression(value) {
|
|---|
| 16 | // eslint-disable-next-line global-require
|
|---|
| 17 | var getValue = require('.').default;
|
|---|
| 18 | var operator = value.operator,
|
|---|
| 19 | argument = value.argument;
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | switch (operator) {
|
|---|
| 23 | case '-':
|
|---|
| 24 | return -getValue(argument);
|
|---|
| 25 | case '+':
|
|---|
| 26 | return +getValue(argument); // eslint-disable-line no-implicit-coercion
|
|---|
| 27 | case '!':
|
|---|
| 28 | return !getValue(argument);
|
|---|
| 29 | case '~':
|
|---|
| 30 | return ~getValue(argument); // eslint-disable-line no-bitwise
|
|---|
| 31 | case 'delete':
|
|---|
| 32 | // I believe delete statements evaluate to true.
|
|---|
| 33 | return true;
|
|---|
| 34 | case 'typeof':
|
|---|
| 35 | case 'void':
|
|---|
| 36 | default:
|
|---|
| 37 | return undefined;
|
|---|
| 38 | }
|
|---|
| 39 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.