'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, getFunctionName, isHookByName, isComponentLikeFunction, isAnonymousOneTimeLambda, isSmallLambda, isHookCall, isNewExpression, isCallbackExpression, isIdentifier } from '@flint/infra/analysis';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { runtimeConstructors } from '../../../base-repo/constants/runtime-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x19ae1a,_0x555b7e)=>__defProp(_0x19ae1a,'name',{'value':_0x555b7e,'configurable':!![]});const ruleName='must-not-declare-func-inside-another-func';const constants={'messageIds':{'mustNotDeclareFuncInsideAnotherFunc':'mustNotDeclareFuncInsideAnotherFunc'},'meta':{'type':ruleTypes['suggestion'],'docs':{'description':'Moving\x20the\x20inner\x20function\x20outside\x20makes\x20it\x20reusable,\x20more\x20efficient,\x20and\x20easier\x20to\x20read.'},'messages':{'mustNotDeclareFuncInsideAnotherFunc':'must-not-declare-func-inside-another-func\x0a###\x20**Must\x20not**\x20declare\x20function\x20inside\x20another\x20function.\x0a\x0aExcept\x20in\x20React\x20components.\x0a\x0a####\x20Wrong\x0a\x0afunction\x20foo()\x20{\x0a\x20\x20\x20\x20const\x20bar\x20=\x20()\x20=>\x20{...};\x0a}\x0a\x0a####\x20Correct\x0a\x0afunction\x20foo()\x20{\x0a\x20\x20\x20\x20bar()\x0a}\x0a\x0afunction\x20bar()\x20{...}\x0a\x0a####\x20Why\x0a\x0aDeclaring\x20functions\x20inside\x20other\x20functions\x20creates\x20a\x20new\x20instance\x20each\x20time,\x20using\x20extra\x20memory\x20and\x20slowing\x20performance\x20if\x20they\x20don’t\x20rely\x20on\x20the\x20outer\x20function’s\x20scope.\x20Moving\x20the\x20inner\x20function\x20outside\x20makes\x20it\x20reusable,\x20more\x20efficient,\x20and\x20easier\x20to\x20read.'},'schema':[]}},ruleCreator=ESLintUtils['RuleCreator'],createRule=ruleCreator(_0x425585=>''+url+_0x425585),mustNotDeclareFuncInsideAnotherFunc=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x36fd0d){const _0x327202=[],_0x16fdd3=new Set([nodeTypes['methodDefinition'],nodeTypes['property'],nodeTypes['callExpression'],nodeTypes['assignmentExpression'],nodeTypes['returnStatement']]),_0x4f5918=[nodeTypes['functionDeclaration'],nodeTypes['functionExpression'],nodeTypes['arrowFunctionExpression']]['join'](',');return {[_0x4f5918]:_0x2ee88c=>{const _0x54469f=_0x327202['at'](-(-0x29b*0x1+0x2*0x4a2+0x6a8*-0x1));_0x54469f&&_0x54469f['nestedFunctions']['push'](_0x2ee88c),_0x327202['push']({'node':_0x2ee88c,'containsHookCall':![],'nestedFunctions':[]});},'CallExpression':__name(_0x37f956=>{const _0xcc2ff3=_0x327202['at'](-(0x19ac+0x17c4+0x9e3*-0x5));if(!_0xcc2ff3)return;isHookCall(_0x37f956['callee'])&&(_0xcc2ff3['containsHookCall']=!![]);},'CallExpression'),[_0x4f5918+':exit']:()=>{const _0x30b305=_0x327202['pop']();if(!_0x30b305)return;const _0x4b3290=getFunctionName(_0x30b305['node']);if(!_0x4b3290)return;const _0x39244e=isHookByName(_0x4b3290)&&_0x30b305['containsHookCall'],_0x730c7e=isComponentLikeFunction(_0x30b305['node']),_0x1c838b=_0x39244e||_0x730c7e;if(!_0x1c838b)for(const _0x102e0f of _0x30b305['nestedFunctions']){const _0x2e250f=_0x102e0f['parent']&&_0x16fdd3['has'](_0x102e0f['parent']['type']),_0x144de0=isPromiseExecutorFunction(_0x102e0f),_0x5da4d5=isAnonymousOneTimeLambda(_0x102e0f),_0x48d372=isSmallLambda(_0x102e0f);!_0x2e250f&&!_0x144de0&&!_0x5da4d5&&!_0x48d372&&_0x36fd0d['report']({'node':_0x102e0f,'messageId':constants['messageIds']['mustNotDeclareFuncInsideAnotherFunc']});}}};}});function isPromiseExecutorFunction(_0x518838){const _0x14e907=_0x518838['parent'];return !_0x14e907||!isNewExpression(_0x14e907)||!isCallbackExpression(_0x518838)||!isIdentifier(_0x14e907['callee'])||_0x14e907['callee']['name']!==runtimeConstructors['promise']?![]:_0x14e907['arguments']['at'](-0x2*0x704+-0x169*-0xb+-0x17b)===_0x518838;}__name(isPromiseExecutorFunction,'isPromiseExecutorFunction');

export { mustNotDeclareFuncInsideAnotherFunc as default, ruleName };
