123456789101112131415161718192021222324252627282930313233343536 |
- /**
- * Library: isPromise
- * Makes sure that an Expression node is part of a promise.
- */
- 'use strict'
- const PROMISE_STATICS = require('./promise-statics')
- function isPromise(expression) {
- return (
- // hello.then()
- (expression.type === 'CallExpression' &&
- expression.callee.type === 'MemberExpression' &&
- expression.callee.property.name === 'then') ||
- // hello.catch()
- (expression.type === 'CallExpression' &&
- expression.callee.type === 'MemberExpression' &&
- expression.callee.property.name === 'catch') ||
- // hello.finally()
- (expression.type === 'CallExpression' &&
- expression.callee.type === 'MemberExpression' &&
- expression.callee.property.name === 'finally') ||
- // somePromise.ANYTHING()
- (expression.type === 'CallExpression' &&
- expression.callee.type === 'MemberExpression' &&
- isPromise(expression.callee.object)) ||
- // Promise.STATIC_METHOD()
- (expression.type === 'CallExpression' &&
- expression.callee.type === 'MemberExpression' &&
- expression.callee.object.type === 'Identifier' &&
- expression.callee.object.name === 'Promise' &&
- PROMISE_STATICS[expression.callee.property.name])
- )
- }
- module.exports = isPromise
|