ConditionalExpression.js 666 B

12345678910111213141516171819202122
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = extractValueFromConditionalExpression;
  6. /**
  7. * Extractor function for a ConditionalExpression type value node.
  8. *
  9. * @param - value - AST Value object with type `ConditionalExpression`
  10. * @returns - The extracted value converted to correct type.
  11. */
  12. function extractValueFromConditionalExpression(value) {
  13. // eslint-disable-next-line global-require
  14. var getValue = require('./index.js').default;
  15. var test = value.test,
  16. alternate = value.alternate,
  17. consequent = value.consequent;
  18. return getValue(test) ? getValue(consequent) : getValue(alternate);
  19. }