Repository: FontoXML/fontoxpath
Pull request #535 (2022-09-09 12:12:57)

Improve bucket usage for `descendant::*` axis

bundlemon[bot]: <!-- bundlemon -->
## BundleMon

  
  
  
  
  
  
  
<details>
<summary>Unchanged files (2)</summary>

Status | Path | Size | Limits
:------------: | ------------ | :------------: | :------------:
:white_check_mark: | fontoxpath.esm.js<br/> | 82.26KB | -
:white_check_mark: | fontoxpath.js<br/> | 82.14KB | -
</details>



Total files change +7B 0%

Final result: :white_check_mark:

[View report in BundleMon website ➡️](https://app.bundlemon.dev/projects/609024effb87a20009a6b096/reports/631b2e281258d9f62e5820a7)

---
<p align="center"><a href="https://app.bundlemon.dev/projects/609024effb87a20009a6b096/reports?branch=bucket-descendantaxis&resolution=all" target="_blank" rel="noreferrer noopener">Current branch size history</a> | <a href="https://app.bundlemon.dev/projects/609024effb87a20009a6b096/reports?branch=master&resolution=days" target="_blank" rel="noreferrer noopener">Target branch size history</a></p>
coveralls: 
[![Coverage Status](https://coveralls.io/builds/52342026/badge)](https://coveralls.io/builds/52342026)

Coverage decreased (-0.1%) to 91.063% when pulling **7ce9b1178ea324d212d6024c6c7f8c6b217526c9 on bucket-descendantaxis** into **91018fe677c8e90e14325bdb0d48b9be76e0ed64 on master**.


Patch:
diff --git a/src/expressions/axes/DescendantAxis.ts b/src/expressions/axes/DescendantAxis.ts
index 422861ac..7c98af7a 100644
--- a/src/expressions/axes/DescendantAxis.ts
+++ b/src/expressions/axes/DescendantAxis.ts
@@ -76,9 +76,11 @@ class DescendantAxis extends Expression {
 		// instructions). Specifying this allows an external system to minimize the dependencies of
 		// an expression with the form 'descendant:ele' to only be invalidated by element
 		// insertions/deletions, not by textnode insertions/deletions.
+		// Similarly, `type-1-or-type-2` can only include elements: attributes are not reachable with the descendant axis
 		const testBucket = this._descendantExpression.getBucket();
 		const onlyElementDescendants =
-			testBucket && (testBucket.startsWith('name-') || testBucket === 'type-1');
+			(testBucket && (testBucket.startsWith('name-') || testBucket === 'type-1')) ||
+			testBucket === 'type-1-or-type-2';
 		this._descendantBucket = onlyElementDescendants ? 'type-1' : null;
 	}
 


Test patch:
diff --git a/src/expressions/tests/NameTest.ts b/src/expressions/tests/NameTest.ts
index 061ae692..a1ef2da9 100644
--- a/src/expressions/tests/NameTest.ts
+++ b/src/expressions/tests/NameTest.ts
@@ -10,10 +10,10 @@ import { Bucket } from '../util/Bucket';
 import TestAbstractExpression from './TestAbstractExpression';
 
 class NameTest extends TestAbstractExpression {
-	public _kind: number;
-	public _localName: string;
-	public _namespaceURI: string;
-	public _prefix: string;
+	private _kind: number;
+	private _localName: string;
+	private _namespaceURI: string;
+	private _prefix: string;
 
 	constructor(
 		name: { localName: string; namespaceURI: string | null; prefix: string },
diff --git a/test/specs/parsing/axes/DescendantAxis.tests.ts b/test/specs/parsing/axes/DescendantAxis.tests.ts
index ce2b585d..08bd6659 100644
--- a/test/specs/parsing/axes/DescendantAxis.tests.ts
+++ b/test/specs/parsing/axes/DescendantAxis.tests.ts
@@ -25,28 +25,29 @@ describe('descendant', () => {
 
 		const testDomFacade: IDomFacade = {
 			getFirstChild: (node: slimdom.Node, bucket: string | null) => {
-				console.log(node.nodeName);
-				chai.assert.equal(expectedBucket, bucket);
+				chai.assert.equal(bucket, expectedBucket);
 				return node.firstChild;
 			},
 			getChildNodes: (node: slimdom.Node, bucket: string | null) => {
-				console.log(node.nodeName);
-				chai.assert.equal(expectedBucket, bucket);
+				chai.assert.equal(bucket, expectedBucket);
 				return node.childNodes;
 			},
 			getNextSibling: (node: slimdom.Node, bucket: string | null) => {
-				console.log(node.nodeName);
-				chai.assert.equal(expectedBucket, bucket);
+				chai.assert.equal(bucket, expectedBucket);
 				return node.nextSibling;
 			},
 			getParentNode: (node: slimdom.Node, bucket: string | null) => {
-				console.log(node.nodeName);
-				chai.assert.equal(expectedBucket, bucket);
+				chai.assert.equal(bucket, expectedBucket);
 				return node.parentNode;
 			},
 		} as any;
 
 		evaluateXPathToNodes('descendant::childElement', documentNode.firstChild, testDomFacade);
+
+		// Same for `*`
+		evaluateXPathToNodes('descendant::*', documentNode.firstChild, testDomFacade);
+		// Same for `element()`
+		evaluateXPathToNodes('descendant::element()', documentNode.firstChild, testDomFacade);
 	});
 });