'use strict';
import { nodeTypes } from '@flint/infra/analysis/function-analysis';
import { getStringLiterals, isStringType } from '@flint/infra/analysis/string-analysis';
import { isSideEffectExpression, isMemberExpression, isIdentifier, isProperty } from '@flint/infra/analysis/node-type-type-guards';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { isNull, isNullOrUndefinedAnalysis } from '@flint/infra/analysis/nullish-analysis';
import { isNameMatch } from '@flint/infra/analysis/name-analysis';
import { first } from '../../../fd-toolbox/server/collections/single-funcs.js';
import { iterateDescendants, hasFunctionAncestor } from '@flint/infra/analysis/tree-analysis';

var __defProp=Object['defineProperty'],__name=(_0x13d48a,_0x1af7ea)=>__defProp(_0x13d48a,'name',{'value':_0x1af7ea,'configurable':!![]});function getVariableInScope(_0x493711,_0x464a5c,_0x374fdb,_0x5ae1bb){let _0x64a437=_0x493711['getScope'](_0x464a5c),_0x35e537=_0x64a437['set']['get'](_0x374fdb);if(!_0x5ae1bb)return _0x35e537;while(!_0x35e537&&_0x64a437['upper']){_0x64a437=_0x64a437['upper'],_0x35e537=_0x64a437['set']['get'](_0x374fdb);}return _0x35e537;}__name(getVariableInScope,'getVariableInScope');function isEnvironmentVariableAssignment(_0x44d565){const _0x3e7afe=getStringLiterals(_0x44d565);return _0x3e7afe['some'](_0x222a2a=>/(^|\s)[A-Z][A-Z0-9_]*=/['test'](_0x222a2a));}__name(isEnvironmentVariableAssignment,'isEnvironmentVariableAssignment');function isContainSideEffectExpr(_0x5281e7){if(isSideEffectExpression(_0x5281e7))return !![];else {if(_0x5281e7['type']===nodeTypes['logicalExpression']||_0x5281e7['type']===nodeTypes['binaryExpression'])return isContainSideEffectExpr(_0x5281e7['left'])||isContainSideEffectExpr(_0x5281e7['right']);else {if(_0x5281e7['type']===nodeTypes['unaryExpression'])return isContainSideEffectExpr(_0x5281e7['argument']);else {if(_0x5281e7['type']===nodeTypes['conditionalExpression'])return isContainSideEffectExpr(_0x5281e7['test'])||isContainSideEffectExpr(_0x5281e7['consequent'])||isContainSideEffectExpr(_0x5281e7['alternate']);else {if(_0x5281e7['type']===nodeTypes['memberExpression'])return isContainSideEffectExpr(_0x5281e7['object'])||_0x5281e7['computed']&&isContainSideEffectExpr(_0x5281e7['property']);else return ![];}}}}}__name(isContainSideEffectExpr,'isContainSideEffectExpr');function collectVariableNamesFromPattern(_0x41468d,_0x48b101){if(_0x41468d['type']===nodeTypes['identifier']){_0x48b101['add'](_0x41468d['name']);return;}if(_0x41468d['type']===nodeTypes['objectPattern'])for(const _0x4fea8d of _0x41468d['properties']){collectVariableNamesFromPattern(_0x4fea8d,_0x48b101);}else {if(_0x41468d['type']===nodeTypes['property'])collectVariableNamesFromPattern(_0x41468d['value'],_0x48b101);else {if(_0x41468d['type']===nodeTypes['arrayPattern'])for(const _0x4d770c of _0x41468d['elements']){_0x4d770c&&collectVariableNamesFromPattern(_0x4d770c,_0x48b101);}else {if(_0x41468d['type']===nodeTypes['assignmentPattern'])collectVariableNamesFromPattern(_0x41468d['left'],_0x48b101);else _0x41468d['type']===nodeTypes['restElement']&&collectVariableNamesFromPattern(_0x41468d['argument'],_0x48b101);}}}}__name(collectVariableNamesFromPattern,'collectVariableNamesFromPattern');function getFilenameFromIdentifier(_0x32b9b2,_0x3c77c7){const _0xd80010=_0x3c77c7['getScope'](_0x32b9b2),_0x3d8c4e=_0xd80010['set']['get'](_0x32b9b2['name']);let _0x2fb055;if(_0x3d8c4e)for(const _0x261eaf of _0x3d8c4e['defs']){_0x261eaf['type']===nodeTypes['variable']&&_0x261eaf['node']['init']&&_0x261eaf['node']['init']['type']===nodeTypes['literal']&&isStringType(_0x261eaf['node']['init']['value'])&&(_0x2fb055=_0x261eaf['node']['init']['value']);}return _0x2fb055;}__name(getFilenameFromIdentifier,'getFilenameFromIdentifier');function getFirstExpressionArgument(_0x356e99){const _0x47e895=first(_0x356e99);if(!_0x47e895||_0x47e895['type']===nodeTypes['spreadElement'])return void(-0x2380+0x1c29+-0x1*-0x757);return _0x47e895;}__name(getFirstExpressionArgument,'getFirstExpressionArgument');function unwrapExpression(_0x4a8e24){let _0x3fe64a=_0x4a8e24;while(_0x3fe64a['type']===nodeTypes['awaitExpression']||_0x3fe64a['type']===nodeTypes['chainExpression']||_0x3fe64a['type']===nodeTypes['TSAsExpression']||_0x3fe64a['type']===nodeTypes['TSSatisfiesExpression']){_0x3fe64a['type']===nodeTypes['awaitExpression']?_0x3fe64a=_0x3fe64a['argument']:_0x3fe64a=_0x3fe64a['expression'];}return _0x3fe64a;}__name(unwrapExpression,'unwrapExpression');function getComparableExpressionKey(_0x254bd8,_0x86a9f2){const _0x5b0cfa=unwrapExpression(_0x254bd8);let _0x46e91e;if(_0x5b0cfa['type']===nodeTypes['literal']){if(isNull(_0x5b0cfa['value']))_0x46e91e=jsBasicTypes['null'];else {if(typeof _0x5b0cfa['value']===jsBasicTypes['string'])_0x46e91e=jsBasicTypes['string']+':'+_0x5b0cfa['value'];else {if(typeof _0x5b0cfa['value']===jsBasicTypes['number'])_0x46e91e=jsBasicTypes['number']+':'+String(_0x5b0cfa['value']);else typeof _0x5b0cfa['value']===jsBasicTypes['boolean']&&(_0x46e91e=jsBasicTypes['boolean']+':'+String(_0x5b0cfa['value']));}}}else isMemberExpression(_0x5b0cfa)&&(_0x46e91e='expr:'+normalizeExpressionText(_0x86a9f2['getText'](_0x5b0cfa)));return _0x46e91e;}__name(getComparableExpressionKey,'getComparableExpressionKey');function areExpressionsEquivalent(_0x261d0e,_0x5a35c5,_0x1b5fd6){const _0x249777=getComparableExpressionKey(_0x261d0e,_0x1b5fd6),_0x42171c=getComparableExpressionKey(_0x5a35c5,_0x1b5fd6);let _0x1e0c9a=![];return _0x249777&&_0x42171c&&(_0x1e0c9a=_0x249777===_0x42171c),_0x1e0c9a;}__name(areExpressionsEquivalent,'areExpressionsEquivalent');function isNullishExpression(_0x2ae4af){const _0x1f5448=unwrapExpression(_0x2ae4af),_0x62b710=isNullOrUndefinedAnalysis(_0x1f5448);return _0x62b710;}__name(isNullishExpression,'isNullishExpression');function isPropertyAccess(_0x463d96,_0x5b2c9c){if(!isMemberExpression(_0x463d96)||_0x463d96['computed']&&isIdentifier(_0x463d96['property']))return ![];return isNameMatch(_0x463d96['property'],_0x5b2c9c);}__name(isPropertyAccess,'isPropertyAccess');function isNodeTypesAccess(_0x594e35,_0x17387b){return isMemberExpression(_0x594e35)&&isNameMatch(_0x594e35['object'],'nodeTypes')&&isNameMatch(_0x594e35['property'],_0x17387b);}__name(isNodeTypesAccess,'isNodeTypesAccess');function isIdentifierReference(_0x4b84d7){const _0x248633=_0x4b84d7['parent'];let _0x58fe13=![];if(_0x248633){const _0x22ed25=isMemberExpression(_0x248633)&&_0x248633['property']===_0x4b84d7&&!_0x248633['computed'],_0x54816d=isProperty(_0x248633)&&_0x248633['key']===_0x4b84d7&&!_0x248633['computed']&&_0x248633['value']!==_0x4b84d7;_0x58fe13=!_0x22ed25&&!_0x54816d;}return _0x58fe13;}__name(isIdentifierReference,'isIdentifierReference');function collectIdentifiersFromExpression(_0x56d2e2,_0x2caa47){const _0x574044=[];isIdentifier(_0x56d2e2)&&_0x574044['push'](_0x56d2e2);for(const _0x102610 of iterateDescendants(_0x56d2e2,_0x2caa47)){isIdentifier(_0x102610['value'])&&!hasFunctionAncestor(_0x102610['metadata'],_0x56d2e2)&&_0x574044['push'](_0x102610['value']);}return _0x574044;}__name(collectIdentifiersFromExpression,'collectIdentifiersFromExpression');function normalizeExpressionText(_0x168cb8){return _0x168cb8['replace'](/\s+/g,'');}__name(normalizeExpressionText,'normalizeExpressionText');

export { areExpressionsEquivalent, collectIdentifiersFromExpression, collectVariableNamesFromPattern, getComparableExpressionKey, getFilenameFromIdentifier, getFirstExpressionArgument, getVariableInScope, isContainSideEffectExpr, isEnvironmentVariableAssignment, isIdentifierReference, isNodeTypesAccess, isNullishExpression, isPropertyAccess, unwrapExpression };
