/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const helperClass=require("./helpers/vartrack");const RULE_NAME="oj-ts-comp-attr-deprecated";var NT;var depMembers;var delMembers;function Rule(){this._reset();this._scope=null};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return"JET component class deprecated members should not be invoked"};Rule.prototype.getDescription=function(){return"JET component class deprecated members should not be invoked"};Rule.prototype.register=function(regCtx){if(!depMembers){depMembers=regCtx.utils.metaLib.getDeprecatedMemberList(regCtx)}if(!delMembers){delMembers=regCtx.utils.metaLib.getDeletedMemberList(regCtx)}return{MemberExpression:this._onMemExpr,file:this._onNewFile}};Rule.prototype._reset=function(){if(this._helper){this._helper.reset()}};Rule.prototype._onMemExpr=function(ruleCtx,node){var component,member,objName,status,comment,issue,version,deleted;var metaLib=ruleCtx.utils.metaLib;if(node.parent&&node.parent.type==="CallExpression"){return}objName=this._getVarFromMemberExpr(node);if(this._isCommonObject(ruleCtx,objName)){return}if(node.property){member=node.property.name}if(!(member&&objName&&!member.startsWith("_"))){return}if(!depMembers[member]){deleted=delMembers[member];if(!deleted){return}}component=this._scope.getVarType(node.object);if(!component||component==="TSAnyKeyword"){return}if(status=metaLib.isClassMemberDeprecated(component,member)){let stat,targ;stat=status[0];if(targ=stat.target){if(targ==="propertyType"||targ==="propertyValue"){return}}comment=ruleCtx.utils.utils.removeMarkup(status[0].description);issue=new ruleCtx.Issue(`Member '${member}' on var '${objName}' (${component}) ${comment.toLowerCase().includes("deprecated")?". ":" is deprecated. "} ${comment}`)}else{if(metaLib.isClassDeprecated(component)){issue=new ruleCtx.Issue(`Method '${member}' on var '${objName}' called on deprecated component ${component}.`)}}if(!issue){if(version=metaLib.isClassMemberDeleted(component,member)){issue=new ruleCtx.Issue(`Member '${member}' on var '${objName}' (${component}) was removed in version ${version}`)}else if(metaLib.isClassDeleted(component)){issue=new ruleCtx.Issue(`Member '${member}' on var '${objName}' called on deleted class ${component}.`);issue.setSeverity("critical")}if(issue){issue.setSeverity("critical");issue.setMsgKey(RULE_NAME+"_2")}}if(issue){ruleCtx.reporter.addIssue(issue,ruleCtx)}};Rule.prototype._onNewFile=function(ruleCtx){if(!this._helper){this._helper=new helperClass}this._reset();if(!NT&&ruleCtx.utils.AstUtils){NT=ruleCtx.utils.AstUtils.getNodeTypes()}this._scope=ruleCtx.utils.AstUtils.getScopes()};Rule.prototype._getVarFromMemberExpr=function(me,varSoFar,level){var obj;level=typeof level==="number"?level+1:0;if(me.object){obj=me.object;if(obj.type===NT.IDENTIFIER){varSoFar=varSoFar?varSoFar+"."+obj.name:obj.name}else if(obj.type===NT.MEMBER_EXPR){varSoFar=this._getVarFromMemberExpr(obj,varSoFar,level)}if(me.property&&level){if(me.property.type===NT.IDENTIFIER){varSoFar=varSoFar?varSoFar+"."+me.property.name:me.property.name}else if(me.property.type===NT.MEMBER_EXPR){varSoFar=this._getVarFromMemberExpr(me.property,varSoFar,level)}}}return varSoFar};Rule.prototype._isCommonObject=function(ruleCtx,objName){return objName==="this"||objName==="self"||objName==="_self"||objName==="window"||objName==="console"||this._helper.isCommonVar(objName)};module.exports=Rule;