'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { nodeTypes, isAnonymousFunction, isComponentByName, isExport, hasReactFCTypeAnnotation, isDestructuringBinding, isObjectDestructuringBinding } from '@flint/infra/analysis';

var __defProp=Object['defineProperty'],__name=(_0x8d9087,_0xccb68a)=>__defProp(_0x8d9087,'name',{'value':_0xccb68a,'configurable':!![]});const ruleName='must-not-destructure-function-parameters';const anyFunctionSelector=[nodeTypes['functionDeclaration'],nodeTypes['functionExpression'],nodeTypes['arrowFunctionExpression']]['join'](',\x20'),ruleContent='\x0a###\x20**Must\x20not**\x20destructure\x20function\x20parameters.\x0a\x0a####\x20Wrong\x0a\x0aexport\x20function\x20handleFoo({\x20bar,\x20buz\x20})\x20{\x0a\x20\x20\x20\x20return\x20bar\x20+\x20buz;\x0a}\x0a\x0aexport\x20const\x20buildFoo\x20=\x20([bar,\x20quux])\x20=>\x20bar\x20+\x20quux;\x0a\x0a####\x20Correct\x0a\x0aexport\x20function\x20handleFoo(foo)\x20{\x0a\x20\x20\x20\x20return\x20foo.bar\x20+\x20foo.buz;\x0a}\x0a\x0afunction\x20handleFoo({\x20bar,\x20buz\x20})\x20{\x0a\x20\x20\x20\x20return\x20bar\x20+\x20buz;\x0a}\x0a\x0aexport\x20const\x20buildFoo\x20=\x20(foo)\x20=>\x20{\x0a\x20\x20\x20\x20return\x20foo[0]\x20+\x20foo[1];\x0a};\x0a\x0aconst\x20buildFoo\x20=\x20([bar,\x20quux])\x20=>\x20bar\x20+\x20quux;\x0a\x0ainterface\x20Props\x20{\x0a\x20\x20\x20\x20bar:\x20string;\x0a}\x0a\x0aconst\x20Foo:\x20React.FC<Props>\x20=\x20({\x20bar\x20})\x20=>\x20{\x0a\x0a\x20\x20\x20\x20return\x20<h1>{bar}</h1>;\x0a};\x0a\x0aarray.map(({\x20name\x20})\x20=>\x20{\x0a\x20\x20\x20\x20return\x20name\x0a})\x0a\x0a####\x20Why\x0a\x0aKeeping\x20parameters\x20explicit\x20improves\x20readability\x20and\x20makes\x20signatures\x20easier\x20to\x20scan\x20and\x20refactor.\x20Destructuring\x20is\x20allowed\x20for\x20the\x20first\x20parameter\x20of\x20React.FC\x20components\x20(props).';var mustNotDestructureFunctionParameters = createEslintRule(ruleName,ruleContent,_0x3510be=>{return {[anyFunctionSelector]:_0x4670ab=>{if(!isExportedFunction(_0x4670ab)||isAnonymousFunction(_0x4670ab)||isComponentByName(_0x4670ab))return;reportDestructuringParameters(_0x4670ab,_0x3510be);}};});function isExportedFunction(_0x3a98e7){let _0x59f6d9=![];return _0x3a98e7['parent']&&isExport(_0x3a98e7['parent'])&&(_0x59f6d9=!![]),(_0x3a98e7['type']===nodeTypes['arrowFunctionExpression']||_0x3a98e7['type']===nodeTypes['functionExpression'])&&_0x3a98e7['parent']?.['type']===nodeTypes['variableDeclarator']&&_0x3a98e7['parent']['parent']?.['type']===nodeTypes['variableDeclaration']&&_0x3a98e7['parent']['parent']['parent']&&isExport(_0x3a98e7['parent']['parent']['parent'])&&(_0x59f6d9=!![]),_0x59f6d9;}__name(isExportedFunction,'isExportedFunction');function reportDestructuringParameters(_0x2bb39c,_0xb8a586){const _0x3102f4=hasReactFCTypeAnnotation(_0x2bb39c);_0x2bb39c['params']['forEach']((_0x2d546a,_0xc74095)=>{isDestructuringBinding(_0x2d546a)&&!isAllowedReactFCPropsDestructuring(_0x2d546a,_0xc74095,_0x3102f4)&&_0xb8a586['report']({'node':_0x2d546a,'messageId':ruleName});});}__name(reportDestructuringParameters,'reportDestructuringParameters');function isAllowedReactFCPropsDestructuring(_0x4285a2,_0x59f449,_0x107704){return _0x107704&&_0x59f449===-0x2*-0x1046+-0x1199+-0xef3&&isObjectDestructuringBinding(_0x4285a2);}__name(isAllowedReactFCPropsDestructuring,'isAllowedReactFCPropsDestructuring');

export { mustNotDestructureFunctionParameters as default, ruleName };
