CallExpression.js 860 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = extractValueFromCallExpression;
  6. /**
  7. * Extractor function for a CallExpression type value node.
  8. * A call expression looks like `bar()`
  9. * This will return `bar` as the value to indicate its existence,
  10. * since we can not execute the function bar in a static environment.
  11. *
  12. * @param - value - AST Value object with type `CallExpression`
  13. * @returns - The extracted value converted to correct type.
  14. */
  15. function extractValueFromCallExpression(value) {
  16. // eslint-disable-next-line global-require
  17. var getValue = require('./index.js').default;
  18. var args = Array.isArray(value.arguments) ? value.arguments.map(function (x) {
  19. return getValue(x);
  20. }).join(', ') : '';
  21. return '' + getValue(value.callee) + (value.optional ? '?.' : '') + '(' + args + ')';
  22. }