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:
788 bytes
|
Line | |
---|
1 | /**
|
---|
2 | * Extractor function for an UpdateExpression type value node.
|
---|
3 | * An update expression is an expression with an update operator.
|
---|
4 | * For example, foo++ will evaluate to foo + 1.
|
---|
5 | *
|
---|
6 | * @param - value - AST Value object with type `UpdateExpression`
|
---|
7 | * @returns - The extracted value converted to correct type.
|
---|
8 | */
|
---|
9 | export default function extractValueFromUpdateExpression(value) {
|
---|
10 | // eslint-disable-next-line global-require
|
---|
11 | const getValue = require('.').default;
|
---|
12 | const { operator, argument, prefix } = value;
|
---|
13 |
|
---|
14 | let val = getValue(argument);
|
---|
15 |
|
---|
16 | switch (operator) {
|
---|
17 | case '++':
|
---|
18 | return prefix ? ++val : val++; // eslint-disable-line no-plusplus
|
---|
19 | case '--':
|
---|
20 | return prefix ? --val : val--; // eslint-disable-line no-plusplus
|
---|
21 | default:
|
---|
22 | return undefined;
|
---|
23 | }
|
---|
24 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.