'use strict';
import { nodeTypes } from '@flint/infra/analysis/function-analysis';
import { iterateDescendants, hasFunctionAncestor } from '@flint/infra/analysis/tree-analysis';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { isBlockStatement, isArrayReturnStatement, isReturnStatement } from '@flint/infra/analysis/node-type-type-guards';

var __defProp=Object['defineProperty'],__name=(_0x2bcfd1,_0x1b6ee1)=>__defProp(_0x2bcfd1,'name',{'value':_0x1b6ee1,'configurable':!![]});function collectReturnExpressionsFromFunction(_0x414c59,_0x41594e,_0x393920={'ignoreNestedFunctions':![]}){let _0x2deea0;return isBlockStatement(_0x414c59['body'])?_0x2deea0=collectReturnExpressions(_0x414c59['body'],_0x41594e,_0x393920):_0x2deea0=[_0x414c59['body']],_0x2deea0;}__name(collectReturnExpressionsFromFunction,'collectReturnExpressionsFromFunction');function hasArrayReturn(_0x36aa03){const _0x183bcb=_0x36aa03['body'];if(!_0x183bcb||_0x183bcb['type']!==nodeTypes['blockStatement'])return ![];return containsArrayReturn(_0x183bcb['body']);}__name(hasArrayReturn,'hasArrayReturn');function isBareReturn(_0x11344f){if(_0x11344f['type']!==nodeTypes['returnStatement'])return ![];if(!_0x11344f['argument'])return !![];return _0x11344f['argument']['type']===nodeTypes['identifier']&&_0x11344f['argument']['name']===jsBasicTypes['undefined'];}__name(isBareReturn,'isBareReturn');function collectBareReturns(_0x68321b){const _0x6b3c35=[];for(const _0x48b3c0 of _0x68321b){_0x6b3c35['push'](...collectBareReturnsFromStatement(_0x48b3c0));}return _0x6b3c35;}__name(collectBareReturns,'collectBareReturns');function collectReturnExpressions(_0x180605,_0x310c5f,_0x4a7788={'ignoreNestedFunctions':![]}){const _0x22c15e=[];for(const _0x3ea27c of iterateDescendants(_0x180605,_0x310c5f)){isReturnWithExpression(_0x3ea27c,_0x180605,_0x4a7788['ignoreNestedFunctions'])&&_0x22c15e['push'](_0x3ea27c['value']['argument']);}return _0x22c15e;}__name(collectReturnExpressions,'collectReturnExpressions');function containsArrayReturn(_0x14f0c8){let _0x5b196e=![];for(const _0x4b8375 of _0x14f0c8){(isArrayReturnStatement(_0x4b8375)||_0x4b8375['type']===nodeTypes['ifStatement']&&containsArrayReturnInIf(_0x4b8375))&&(_0x5b196e=!![]);}return _0x5b196e;}__name(containsArrayReturn,'containsArrayReturn');function containsArrayReturnInIf(_0x454bc7){const _0x2549db=_0x454bc7['consequent'],_0x56ab94=_0x454bc7['alternate'],_0x358ecf=_0x2549db&&isArrayReturnStatement(_0x2549db)||_0x2549db?.['type']===nodeTypes['blockStatement']&&containsArrayReturn(_0x2549db['body']);if(_0x358ecf)return !![];let _0xb01c0e=![];return _0x56ab94&&(_0xb01c0e=isArrayReturnStatement(_0x56ab94)||_0x56ab94['type']===nodeTypes['blockStatement']&&containsArrayReturn(_0x56ab94['body'])||_0x56ab94['type']===nodeTypes['ifStatement']&&containsArrayReturnInIf(_0x56ab94)),_0xb01c0e;}__name(containsArrayReturnInIf,'containsArrayReturnInIf');function collectBareReturnsFromStatement(_0x34ff61){const _0x942772=_0x34ff61['type'];let _0x4d9811=[];if(_0x942772===nodeTypes['returnStatement']){if(isBareReturn(_0x34ff61))_0x4d9811=[_0x34ff61];}else {if(_0x942772===nodeTypes['ifStatement'])_0x4d9811=collectBareReturnsFromIf(_0x34ff61);else _0x942772===nodeTypes['blockStatement']&&(_0x4d9811=collectBareReturns(_0x34ff61['body']));}return _0x4d9811;}__name(collectBareReturnsFromStatement,'collectBareReturnsFromStatement');function collectBareReturnsFromIf(_0x4d92f1){const _0x4ee730=[];let _0x1c0b30=[];const _0x462228=_0x4d92f1['consequent'];if(_0x462228['type']===nodeTypes['returnStatement']&&isBareReturn(_0x462228))_0x1c0b30=[_0x462228];else _0x462228['type']===nodeTypes['blockStatement']&&(_0x1c0b30=collectBareReturns(_0x462228['body']));_0x4ee730['push'](..._0x1c0b30);if(_0x4d92f1['alternate']){_0x1c0b30=[];if(_0x4d92f1['alternate']['type']===nodeTypes['returnStatement']&&isBareReturn(_0x4d92f1['alternate']))_0x1c0b30=[_0x4d92f1['alternate']];else {if(_0x4d92f1['alternate']['type']===nodeTypes['blockStatement'])_0x1c0b30=collectBareReturns(_0x4d92f1['alternate']['body']);else _0x4d92f1['alternate']['type']===nodeTypes['ifStatement']&&(_0x1c0b30=collectBareReturnsFromIf(_0x4d92f1['alternate']));}_0x4ee730['push'](..._0x1c0b30);}return _0x4ee730;}__name(collectBareReturnsFromIf,'collectBareReturnsFromIf');function isReturnWithExpression(_0x43c92a,_0x5bfdd,_0x344b05=![]){const _0x36212c=isReturnStatement(_0x43c92a['value'])&&!!_0x43c92a['value']['argument'],_0x4fc62a=hasFunctionAncestor(_0x43c92a['metadata'],_0x5bfdd);return _0x36212c&&(!_0x344b05||!_0x4fc62a);}__name(isReturnWithExpression,'isReturnWithExpression');

export { collectBareReturns, collectReturnExpressions, collectReturnExpressionsFromFunction, hasArrayReturn, isBareReturn };
