source: imaps-frontend/node_modules/jsx-ast-utils/lib/values/expressions/UpdateExpression.js

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