has-promise-callback.js 520 B

1234567891011121314151617
  1. /**
  2. * Library: Has Promise Callback
  3. * Makes sure that an Expression node is part of a promise
  4. * with callback functions (like then() or catch())
  5. */
  6. 'use strict'
  7. function hasPromiseCallback(node) {
  8. // istanbul ignore if -- only being called within `CallExpression`
  9. if (node.type !== 'CallExpression') return
  10. if (node.callee.type !== 'MemberExpression') return
  11. const propertyName = node.callee.property.name
  12. return propertyName === 'then' || propertyName === 'catch'
  13. }
  14. module.exports = hasPromiseCallback