From 06b8d6adfbe8bef3262de78de9d265efda3bdd16 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Fri, 26 Sep 2025 18:15:11 +0530 Subject: [PATCH] Enhance processOverlappingPaths to collect all paths and remove redundant parent paths. Introduce removeRedundantPaths method for improved path filtering. --- src/stack.ts | 52 +++++++++++++++++++++++++++++++++++++++------- typings/stack.d.ts | 10 ++++++++- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/stack.ts b/src/stack.ts index 78e5b4c..4f063e9 100755 --- a/src/stack.ts +++ b/src/stack.ts @@ -1227,27 +1227,63 @@ export class Stack { /** * @private * @method processOverlappingPaths - * @description Processes overlapping paths by including all paths from each group + * @description Processes overlapping paths using a chained approach * @param {Object} pathAnalysis - Analysis result from analyzeReferencePaths * @returns {this} - Returns stack instance */ private processOverlappingPaths(pathAnalysis: any): Stack { - // Start with independent paths (if any) + // Collect ALL paths first + const allPaths: string[] = [] + + // Add independent paths if (pathAnalysis.independentPaths.length > 0) { - this.q.includeSpecificReferences = [...pathAnalysis.independentPaths] - } else { - this.q.includeSpecificReferences = [] + allPaths.push(...pathAnalysis.independentPaths) } - // Process each overlapping group by including ALL paths from each group + // Add all paths from overlapping groups pathAnalysis.overlappingGroups.forEach((group: string[]) => { - // Add all paths from the group to includeSpecificReferences - this.q.includeSpecificReferences.push(...group) + allPaths.push(...group) }) + // Remove exact duplicates + const uniquePaths = [...new Set(allPaths)] + + // Smart filtering: remove parent paths that are fully covered by child paths + const filteredPaths = this.removeRedundantPaths(uniquePaths) + + this.q.includeSpecificReferences = filteredPaths return this } + /** + * @private + * @method removeRedundantPaths + * @description Removes parent paths that are fully covered by more specific child paths + * Example: ["content", "content.content"] → ["content.content"] + * But keeps: ["form", "form.fields", "form.fields.rules"] → all three (not redundant) + */ + private removeRedundantPaths(paths: string[]): string[] { + // Sort by length (longest first) to prioritize more specific paths + const sortedPaths = paths.sort((a, b) => b.length - a.length) + const result: string[] = [] + + for (const currentPath of sortedPaths) { + // Check if this path is made redundant by a more specific path already in result + const isRedundant = result.some(existingPath => { + // Check if currentPath is a direct parent of existingPath + return existingPath.startsWith(currentPath + '.') && + existingPath.split('.').length === currentPath.split('.').length + 1 + }) + + if (!isRedundant) { + result.push(currentPath) + } + } + + return result + } + + /** * @private * @method preProcess diff --git a/typings/stack.d.ts b/typings/stack.d.ts index 3df4644..069397f 100644 --- a/typings/stack.d.ts +++ b/typings/stack.d.ts @@ -513,11 +513,19 @@ export declare class Stack { /** * @private * @method processOverlappingPaths - * @description Processes overlapping paths by including all paths from each group + * @description Processes overlapping paths using a chained approach * @param {Object} pathAnalysis - Analysis result from analyzeReferencePaths * @returns {this} - Returns stack instance */ private processOverlappingPaths; + /** + * @private + * @method removeRedundantPaths + * @description Removes parent paths that are fully covered by more specific child paths + * Example: ["content", "content.content"] → ["content.content"] + * But keeps: ["form", "form.fields", "form.fields.rules"] → all three (not redundant) + */ + private removeRedundantPaths; /** * @private * @method preProcess