/*
 * 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 path=require("path");const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-supproperty-propagation"};ruleDef.prototype.getShortDescription=function(){return"Check for cases where a component directly passes a property with sub-properties through to a child component"};ruleDef.prototype.getDescription=function(){return"Detects cases where a component property is passed directly to a child in a way that does not ensure that the child will automatically be informed of some change to that property during the lifespan of the component instance. In this scenario, the component should be using a proxy observable or computed rather than a direct passthrough binding to $properties to ensure that any change to the property at the top level is also notified to the child correctly"};ruleDef.prototype.register=function(context){return{attrexpr:this._doAudit}};ruleDef.prototype._doAudit=function(context,attribute,attributeValue){let issue;const candidateRE=/^[\{|\[]{2}(?:\$properties|\$props|properties)\.(\w*)[\}|\]]{2}$/;const checkProperty=attributeValue.match(candidateRE);if(checkProperty&&checkProperty.length===2){if(context.elemStack&&context.elemStack.length>0){const usageTag=context.elemStack.slice(-1)[0].name;if(usageTag&&!usageTag.startsWith("oj-bind-")){const componentName=Utils.matchComponentPath(context,path.dirname(context.filepath));if(componentName){const meta=Utils.componentInfo(context,componentName);if(meta.properties[checkProperty[1]]){if(meta.properties[checkProperty[1]].properties){if(!Utils.shouldIgnoreCheck(context,"jetwc-supproperty-propagation",componentName,"properties",checkProperty[1])){issue=new context.Issue(`Complex Properties such as ${checkProperty[1]} in the component ${componentName} should be bound via a proxy to a child component rather than directly if change propagation is going to work correctly. Currently the binding is via ${attributeValue}`);context.reporter.addIssue(issue,context)}}}}}}}};module.exports=ruleDef;