'use strict';
import { TSESLint } from '@typescript-eslint/utils';
import { isVariableDeclaration, isIdentifier, isMemberExpression, isVariableDefinition, isVariableDeclarator, isFunction, isObjectExpression, isProperty } from '@flint/infra/analysis/node-type-type-guards';
import { collectVariableNamesFromPattern, isIdentifierReference, unwrapExpression } from '@flint/infra/analysis/expression-analysis';
import { nodeTypes } from '@flint/infra/analysis/function-analysis';
import { variableDeclarationKinds } from '@flint/infra/analysis/module-analysis';
import { isNameMatch, getPropertyName } from '@flint/infra/analysis/name-analysis';
import { flintRuleIdentifiers } from '@flint/infra/constants/shared-string-identifiers';
import { findVariable } from '@typescript-eslint/utils/ast-utils';
import { first, firstOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x32e53e,_0x3fc6f9)=>__defProp(_0x32e53e,'name',{'value':_0x3fc6f9,'configurable':!![]});const globalObjectNames=[flintRuleIdentifiers['window'],'self',flintRuleIdentifiers['global'],'globalThis'];function getDeclaredVariableNames(_0x488a08){const _0x49b31=new Set();if(!_0x488a08)return _0x49b31;if(_0x488a08['type']!==nodeTypes['blockStatement'])return _0x49b31;for(const _0x4b6d79 of _0x488a08['body']){if(isVariableDeclaration(_0x4b6d79))for(const _0x13a7c5 of _0x4b6d79['declarations']){collectVariableNamesFromPattern(_0x13a7c5['id'],_0x49b31);}}return _0x49b31;}__name(getDeclaredVariableNames,'getDeclaredVariableNames');function getReference(_0x451036,_0x13fa10){return _0x13fa10['getScope'](_0x451036)['references']['find'](_0x789501=>_0x789501['identifier']===_0x451036);}__name(getReference,'getReference');function isGlobalObject(_0x4460a2,_0x30d149){const _0xac374d=getReference(_0x4460a2,_0x30d149)?.['resolved'];return isIdentifier(_0x4460a2)&&globalObjectNames['some'](_0x1a70ce=>isNameMatch(_0x4460a2,_0x1a70ce))&&(!_0xac374d||_0xac374d['scope']['type']===TSESLint['Scope']['ScopeType']['global']);}__name(isGlobalObject,'isGlobalObject');function isGlobalObjectConstructor(_0x13e71a,_0xaa1d45){if(!isIdentifier(_0x13e71a)||_0x13e71a['name']!==flintRuleIdentifiers['object'])return ![];const _0x2f78bf=getReference(_0x13e71a,_0xaa1d45)?.['resolved'];return !_0x2f78bf||_0x2f78bf['scope']['type']===TSESLint['Scope']['ScopeType']['global'];}__name(isGlobalObjectConstructor,'isGlobalObjectConstructor');function isTopLevelVariable(_0x5e9a49){return _0x5e9a49['scope']['type']===TSESLint['Scope']['ScopeType']['module']||_0x5e9a49['scope']['type']===TSESLint['Scope']['ScopeType']['global'];}__name(isTopLevelVariable,'isTopLevelVariable');function getObjectPropsUsagesCount(_0x2978ad,_0x150835){const _0x4dba66=new Map(),_0x36fb5f=_0x2978ad['references']['filter'](_0x215da6=>!_0x215da6['init']);for(const _0x299498 of _0x36fb5f){let _0x3154a4,_0x4df409=_0x299498['identifier']['parent'],_0x1f0d46=_0x150835;while(isMemberExpression(_0x4df409)){const _0x56a82f=getPropertyName(_0x4df409),_0x56a1f6=_0x1f0d46['find'](_0x3ef0bc=>_0x3ef0bc['type']===nodeTypes['property']&&getPropertyName(_0x3ef0bc)===_0x56a82f);_0x56a1f6&&_0x56a1f6['type']===nodeTypes['property']&&(_0x56a1f6['value']['type']===nodeTypes['objectExpression']?(_0x1f0d46=_0x56a1f6['value']['properties'],_0x3154a4=_0x56a1f6):(_0x4dba66['set'](_0x56a1f6,(_0x4dba66['get'](_0x56a1f6)??0x2227+-0x6*0x58d+-0x1f*0x7)+(0x1*-0x1b2d+0x26c7+-0xb99)),_0x3154a4=void(-0x1e63+0xe1+0x1d82))),_0x4df409=_0x4df409['parent'];}_0x3154a4&&_0x4dba66['set'](_0x3154a4,(_0x4dba66['get'](_0x3154a4)??0x410+0x9*-0x134+0x1*0x6c4)+(0x973*-0x1+0x2cf*0x4+-0xc*0x26));}return _0x4dba66;}__name(getObjectPropsUsagesCount,'getObjectPropsUsagesCount');function isVariableImportedFrom(_0x3d87f2,_0x1eb13f){let _0x22dad1=![];if(first(_0x3d87f2['defs'])['type']===nodeTypes['importBinding']){const _0x2e7e71=first(_0x3d87f2['defs'])['node'];_0x2e7e71['parent']['type']===nodeTypes['importDeclaration']&&_0x2e7e71['parent']['source']['type']===nodeTypes['literal']&&_0x2e7e71['parent']['source']['value']===_0x1eb13f&&(_0x22dad1=!![]);}return _0x22dad1;}__name(isVariableImportedFrom,'isVariableImportedFrom');function getDefinition(_0x5dbbe0,_0x595e7c){const _0x540457=findVariable(_0x595e7c['getScope'](_0x5dbbe0),_0x5dbbe0);return firstOrUndefined(_0x540457?.['defs']??[]);}__name(getDefinition,'getDefinition');function getFunctionByCallee(_0x4e6133,_0x3d683f){let _0xa36168;if(isIdentifier(_0x4e6133))_0xa36168=getFunctionByName(_0x4e6133['name'],_0x3d683f);else isMemberExpression(_0x4e6133)&&(_0xa36168=getFunctionByMemberCallee(_0x4e6133,_0x3d683f));return _0xa36168;}__name(getFunctionByCallee,'getFunctionByCallee');function getFunctionByName(_0x241c38,_0x30c442){const _0x18d831=getVariableDefinitionNodeByName(_0x241c38,_0x30c442);return _0x18d831?getFunctionNodeFromDefinition(_0x18d831):void(0xa2+-0x1*0x1277+0x11d5);}__name(getFunctionByName,'getFunctionByName');function isConstVariableReference(_0x1827ff,_0x2f1023){let _0x1661e0=![];if(isIdentifierReference(_0x1827ff)){const _0x5080b4=getDefinition(_0x1827ff,_0x2f1023);if(isVariableDefinition(_0x5080b4)&&isVariableDeclarator(_0x5080b4['node'])){const _0x1cc3b5=_0x5080b4['node']['parent'];_0x1661e0=isVariableDeclaration(_0x1cc3b5)&&_0x1cc3b5['kind']===variableDeclarationKinds['const'];}}return _0x1661e0;}__name(isConstVariableReference,'isConstVariableReference');function getFunctionNodeFromDefinition(_0x4bccde){let _0x3f6750;if(isFunction(_0x4bccde))_0x3f6750=_0x4bccde;else isVariableDeclarator(_0x4bccde)&&_0x4bccde['init']&&isFunction(_0x4bccde['init'])&&(_0x3f6750=_0x4bccde['init']);return _0x3f6750;}__name(getFunctionNodeFromDefinition,'getFunctionNodeFromDefinition');function getFunctionByMemberCallee(_0x19e600,_0x536e33){let _0x30952e;if(!_0x19e600['computed']&&isIdentifier(_0x19e600['object'])&&isIdentifier(_0x19e600['property'])){const _0x4c30ce=getObjectExpressionByName(_0x19e600['object']['name'],_0x536e33);_0x4c30ce&&(_0x30952e=getFunctionFromObjectProperty(_0x4c30ce['properties'],_0x19e600['property']['name']));}return _0x30952e;}__name(getFunctionByMemberCallee,'getFunctionByMemberCallee');function getObjectExpressionByName(_0x220162,_0x4ea5e1){const _0x5351ea=getVariableDefinitionNodeByName(_0x220162,_0x4ea5e1);if(_0x5351ea&&isVariableDeclarator(_0x5351ea)&&_0x5351ea['init']){const _0x336e14=unwrapExpression(_0x5351ea['init']);if(isObjectExpression(_0x336e14))return _0x336e14;}return void(-0x617*0x3+-0xada+0x69*0x47);}__name(getObjectExpressionByName,'getObjectExpressionByName');function getVariableDefinitionNodeByName(_0x1f37c8,_0xe309dc){let _0x1a10be=_0xe309dc;while(_0x1a10be){const _0x3cf80b=_0x1a10be['variables']['find'](_0x7f6ae6=>_0x7f6ae6['identifiers']['some'](_0x3d0781=>isNameMatch(_0x3d0781,_0x1f37c8))),_0x4fbf48=firstOrUndefined(_0x3cf80b?.['defs']??[])?.['node'];if(_0x4fbf48)return _0x4fbf48;_0x1a10be=_0x1a10be['upper']??void(0xc52+0x317+-0xf69);}return void(-0x7c1+-0x1*-0x2105+-0x1944);}__name(getVariableDefinitionNodeByName,'getVariableDefinitionNodeByName');function getFunctionFromObjectProperty(_0x471265,_0x2aff8f){let _0x731029;for(const _0xb1c09 of _0x471265){if(isProperty(_0xb1c09)){const _0x16ee54=_0xb1c09['key'],_0x375d9b=!_0xb1c09['computed']&&isNameMatch(_0x16ee54,_0x2aff8f);if(_0x375d9b&&isFunction(_0xb1c09['value'])){_0x731029=_0xb1c09['value'];break;}}}return _0x731029;}__name(getFunctionFromObjectProperty,'getFunctionFromObjectProperty');

export { getDeclaredVariableNames, getDefinition, getFunctionByCallee, getFunctionByName, getObjectPropsUsagesCount, getReference, isConstVariableReference, isGlobalObject, isGlobalObjectConstructor, isTopLevelVariable, isVariableImportedFrom };
