MCPcopy Index your code
hub / github.com/nodejs/node / findEnclosingFunction

Function findEnclosingFunction

tools/eslint-rules/must-call-assert.js:24–59  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

22 node.parent.arguments.length === 1 && node.parent.arguments[0] === node;
23
24function findEnclosingFunction(node) {
25 while (true) {
26 node = node.parent;
27 if (!node) break;
28
29 if (node.type !== 'ArrowFunctionExpression' && node.type !== 'FunctionExpression') continue;
30
31 if (node.parent?.type === 'CallExpression') {
32 if (node.parent.callee === node) continue; // IIFE
33
34 if (
35 node.parent.callee.type === 'MemberExpression' &&
36 (
37 node.parent.callee.object.type === 'ArrayExpression' ||
38 node.parent.callee.object.type === 'Identifier' ||
39 isObjectKeysOrEntries(node.parent.callee.object)
40 ) &&
41 (
42 node.parent.callee.property.name === 'forEach' ||
43 (node.parent.callee.property.name === 'map' && isPromiseAllCallArg(node.parent))
44 )
45 ) continue; // `[].forEach()` call
46 } else if (node.parent?.type === 'NewExpression') {
47 if (node.parent.callee.type === 'Identifier' && node.parent.callee.name === 'Promise') continue;
48 } else if (node.parent?.type === 'Property') {
49 const ancestor = node.parent.parent?.parent;
50 if (ancestor?.type === 'CallExpression' &&
51 ancestor.callee.type === 'Identifier' &&
52 /^spawnSyncAnd(Exit(WithoutError)?|Assert)$/.test(ancestor.callee.name)) {
53 continue;
54 }
55 }
56 break;
57 }
58 return node;
59}
60
61function isMustCallOrMustCallAtLeast(str) {
62 return str === 'mustCall' || str === 'mustCallAtLeast' || str === 'mustSucceed';

Callers 1

Calls 3

isObjectKeysOrEntriesFunction · 0.85
isPromiseAllCallArgFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected