You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
/** |
|
* 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
|
|
|