/*
 * Copyright (c) 2018, 2025, 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 RULENAME="oj-ts-comp-meth-deprecated";var NT;var depMethods;var delMethods;function Rule(){this._reset();this._scope=null};Rule.prototype.getName=function(){return RULENAME};Rule.prototype.getShortDescription=function(){return"JET component class deprecated methods should not be invoked"};Rule.prototype.getDescription=function(){return"JET component class deprecated methods should not be invoked"};Rule.prototype.register=function(regCtx){if(!depMethods){depMethods=regCtx.utils.metaLib.getDeprecatedMethodList(regCtx)}if(!delMethods){delMethods=regCtx.utils.metaLib.getDeletedMethodList(regCtx)}return{CallExpression:this._onCall,file:this._onNewFile,endfile:this._onEndFile}};Rule.prototype._reset=function(){if(this._helper){this._helper.reset()}};Rule.prototype._onCall=function(ruleCtx,node){var component,method,objName,status,comment,version,issue;var me,prop,method,del;var metaLib=ruleCtx.utils.metaLib;if(!NT){NT=ruleCtx.utils.AstUtils.getNodeTypes()}me=node.callee;objName=this._getVarFromMemberExpr(me);prop=me.property;if(prop&&prop.name){method=prop.name}if(!(method&&objName)){return}if(this._isCommonMethod(ruleCtx,objName,method)){return}if(!depMethods[method]){del=delMethods[method];if(!del){return}}component=this._scope.getVarType(me.object);if(!component||component==="TSAnyKeyword"){return}if(status=metaLib.isClassMethodDeprecated(component,method)){comment=ruleCtx.utils.utils.removeMarkup(status[0].description);issue=new ruleCtx.Issue(`Method ${method}() on var '${objName}' (${component}) ${comment.toLowerCase().includes("deprecated")?". ":" is "+(del?"deleted":"deprecated")+". "}${comment}`)}else if(metaLib.isClassDeprecated(component)){issue=new ruleCtx.Issue(`Method ${method}() on var '${objName}' called on deprecated class ${component}`)}if(!issue){if(del){version=metaLib.isClassMethodDeleted(component,method);if(version){issue=new ruleCtx.Issue(`Method ${method}() on var '${objName}' (${component}) was removed in version ${version}`)}else if(metaLib.isClassDeleted(component)){issue=new ruleCtx.Issue(`Method ${method}() on var '${objName}' called on deleted class (${component}).`)}if(issue){issue.setSeverity("critical");issue.setMsgKey(RULENAME+"_2")}}}if(issue){ruleCtx.reporter.addIssue(issue,ruleCtx)}};Rule.prototype._onNewFile=function(ruleCtx){if(ruleCtx.type==="file"&&ruleCtx.filetype!=="ts"&&ruleCtx.filetype!=="tsx"){return}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._onEndFile=function(){};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._isCommonMethod=function(ruleCtx,objName,method){return method.charAt(0)==="_"||method==="observable"||method==="applyBindings"||method==="addEventListener"||method==="removeEventListener"||ruleCtx.utils.AstUtils.isCommonDocApi(method)||objName==="this"||objName==="self"||objName==="_self"||objName==="window"||objName==="console"||this._helper.isCommonVar(objName)};module.exports=Rule;