OptionalMemberExpression.js 697 B

12345678910111213141516171819
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = extractValueFromOptionalMemberExpression;
  6. /**
  7. * Extractor function for a OptionalMemberExpression type value node.
  8. * A member expression is accessing a property on an object `obj.property`.
  9. *
  10. * @param - value - AST Value object with type `OptionalMemberExpression`
  11. * @returns - The extracted value converted to correct type
  12. * and maintaing `obj?.property` convention.
  13. */
  14. function extractValueFromOptionalMemberExpression(value) {
  15. // eslint-disable-next-line global-require
  16. var getValue = require('./index.js').default;
  17. return getValue(value.object) + '?.' + getValue(value.property);
  18. }