/*
 * 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 Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-reserved-property"};ruleDef.prototype.getShortDescription=function(){return"Check component does not a reserved word as a property name"};ruleDef.prototype.getDescription=function(){return"This rule checks that a component does not define a property that is on the list of reserved values e.g. slot, key, ref, children etc."};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){const meta=context.suppData.obj;const fullName=Utils.getComponentFullName(meta);const componentType=Utils.getComponentType(meta);if(componentType==="composite"){this._checkForReservedPropertyNames(context,fullName,meta)}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo&&componentInfo.properties){this._checkForReservedPropertyNames(context,componentInfo.fullName,componentInfo)}};ruleDef.prototype._checkForReservedPropertyNames=function(context,fullName,componentMeta){if(componentMeta&&componentMeta.properties){const reservedProperties=context.rulePack.getRuleCustomOption("reserved");reservedProperties.forEach(reserved=>{if(componentMeta.properties.hasOwnProperty(reserved)){const issue=new context.Issue(`Component ${fullName} defines a property which uses a reserved name: '${reserved}'. You must select a different name for this property`);context.reporter.addIssue(issue,context)}})}};module.exports=ruleDef;