UpdateExpression.js 959 B

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