is-inside-promise.js 470 B

123456789101112131415
  1. 'use strict'
  2. function isInsidePromise(node) {
  3. const isFunctionExpression =
  4. node.type === 'FunctionExpression' ||
  5. node.type === 'ArrowFunctionExpression'
  6. const parent = node.parent || {}
  7. const callee = parent.callee || {}
  8. const name = (callee.property && callee.property.name) || ''
  9. const parentIsPromise = name === 'then' || name === 'catch'
  10. const isInCB = isFunctionExpression && parentIsPromise
  11. return isInCB
  12. }
  13. module.exports = isInsidePromise