Repository: exadel-inc/esl
Pull request #1134 (2022-08-03 00:08:06)

[🐛 in esl-traversing-query]: fix traversing search uniqness


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bca10bee5..0c007f338 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,17 +1,3 @@
-# [4.0.0-beta.13](https://github.com/exadel-inc/esl/compare/v4.0.0-beta.12...v4.0.0-beta.13) (2022-08-02)
-
-
-### Bug Fixes
-
-* **esl-utils:** fix missed body style for scroll lock strategy pseudo ([96c37db](https://github.com/exadel-inc/esl/commit/96c37dbd06a24d45809e6a7528143c09ced9f546))
-
-
-### Features
-
-* **esl-traversing-query:** add comma support to define multiple target ([#1120](https://github.com/exadel-inc/esl/issues/1120) / [#1129](https://github.com/exadel-inc/esl/issues/1129)) ([2890d7b](https://github.com/exadel-inc/esl/commit/2890d7b7667492b982b266048d23874c57b938ea)), closes [#1102](https://github.com/exadel-inc/esl/issues/1102)
-* **esl-trigger:** add `ignore-esc` attribute ([605b715](https://github.com/exadel-inc/esl/commit/605b715a29ef1a852e24ce5120ca30d394fc19c1))
-* **esl-utils:** extend SynteticEventTarget with ability to separate events ([#1118](https://github.com/exadel-inc/esl/issues/1118)) ([507726d](https://github.com/exadel-inc/esl/commit/507726d5b760e54fa3286560931ffbe3110e4151)), closes [#1079](https://github.com/exadel-inc/esl/issues/1079)
-
 # [4.0.0-beta.12](https://github.com/exadel-inc/esl/compare/v4.0.0-beta.11...v4.0.0-beta.12) (2022-07-18)
 
 
diff --git a/package-lock.json b/package-lock.json
index 48cc957d5..5f1a4bac2 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "@exadel/esl",
-  "version": "4.0.0-beta.13",
+  "version": "4.0.0-beta.12",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "@exadel/esl",
-      "version": "4.0.0-beta.13",
+      "version": "4.0.0-beta.12",
       "license": "MIT",
       "dependencies": {
         "@types/resize-observer-browser": "0.1.7",
diff --git a/package.json b/package.json
index 7c11a7a54..e308898d2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@exadel/esl",
-  "version": "4.0.0-beta.13",
+  "version": "4.0.0-beta.12",
   "private": false,
   "description": "Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components",
   "license": "MIT",
diff --git a/src/modules/esl-traversing-query/core/esl-traversing-query.ts b/src/modules/esl-traversing-query/core/esl-traversing-query.ts
index b34818567..5b1860ab0 100644
--- a/src/modules/esl-traversing-query/core/esl-traversing-query.ts
+++ b/src/modules/esl-traversing-query/core/esl-traversing-query.ts
@@ -95,6 +95,7 @@ export class TraversingQuery {
     }
     return uniq(result);
   }
+
   /** Split multiple queries separated by comma (respects query brackets) */
   // This can be solved by RegEx /(?<!\([^\)]*),(?![^\(]*\))/g)/, when the WebKit browser implements this feature
   public static splitQueries(str: string): string[] {
@@ -120,7 +121,7 @@ export class TraversingQuery {
       if (findFirst && els.length) return [els[0]];
       found.push(...els);
     }
-    return found;
+    return uniq(found);
   }
 
   protected static traverseQuery(query: string, findFirst: boolean, base?: Element | null, scope: Element | Document = document): Element[] {
diff --git a/src/modules/esl-utils/misc/array.ts b/src/modules/esl-utils/misc/array.ts
index b988324be..d1f49c17b 100644
--- a/src/modules/esl-utils/misc/array.ts
+++ b/src/modules/esl-utils/misc/array.ts
@@ -32,6 +32,7 @@ export function unwrap(value: any): any {
 
 /** Makes array values unique */
 export const uniq = <T> (arr: T[]): T[] => {
+  if (arr.length < 2) return arr.slice(0);
   const result: T[] = [];
   const set = new Set<T>();
   arr.forEach((item) => set.add(item));


Test patch:
diff --git a/src/modules/esl-traversing-query/test/esl-traversing-query.test.ts b/src/modules/esl-traversing-query/test/esl-traversing-query.test.ts
index 7681f65f4..5509838a1 100644
--- a/src/modules/esl-traversing-query/test/esl-traversing-query.test.ts
+++ b/src/modules/esl-traversing-query/test/esl-traversing-query.test.ts
@@ -169,12 +169,15 @@ describe('Traversing Query tests', () => {
         .toEqual(expectedCollection);
     });
   });
+
   describe('TraversingQuery should support multiple queries separated by comma', () => {
     test.each([
       ['::parent,::next', btn1, [row1, btn2]],
       ['::next,  ::parent', btn1, [btn2, row1]],
       ['::parent  ,::next', btn2, [row1, btn3]],
       ['::find(button, article)::filter(:first-child)', row1, [btn1]],
+      ['head::next, body', document.body, [document.body]],
+      ['body, head', document.body, [document.body, document.head]]
     ])('TraversingQuery.all/one, Sel: %s, Base: %p.', traversingQueryWrap);
   });
 
diff --git a/src/modules/esl-utils/misc/test/array.test.ts b/src/modules/esl-utils/misc/test/array.test.ts
index 292c5a8d0..4739782f6 100644
--- a/src/modules/esl-utils/misc/test/array.test.ts
+++ b/src/modules/esl-utils/misc/test/array.test.ts
@@ -36,6 +36,7 @@ describe('misc/array helper tests', () => {
     expect(uniq([1, 1, 1, 1])).toEqual([1]);
     expect(uniq([1, 2, 3, 4])).toEqual([1, 2, 3, 4]);
     expect(uniq([1, 2, 1, 3, 2])).toEqual([1, 2, 3]);
+    expect(uniq([4, 4, 2, 1, 2])).toEqual([4, 2, 1]);
     expect(uniq([NaN, NaN])).toEqual([NaN]);
     expect(uniq([[1], [2], [1]])).toEqual([[1], [2], [1]]);
   });