Repository: FontoXML/fontoxpath
Pull request #606 (2023-08-16 09:25:27)

Allow map operator to be evaluated statically
Without any context. This used to crash with a type error

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

  
  
  
  
  
<details open>
<summary>Files updated (2)</summary>

Status | Path | Size | Limits
:------------: | ------------ | :------------: | :------------:
:white_check_mark: | fontoxpath.js<br/> | 76.24KB (+46B +0.06%) | -
:white_check_mark: | fontoxpath.esm.js<br/> | 76.35KB (+42B +0.05%) | -
</details>

  
  


Total files change +88B +0.06%

Final result: :white_check_mark:

[View report in BundleMon website ➡️](https://app.bundlemon.dev/projects/6437c8f89a7cb205c434db8d/reports/64dc967b1784703179c66fc0)

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

coverage: 91.499% (+0.002%) from 91.497% when pulling **00a94ce31b3ce21bf8b0927a706b1e18ac8db64c on map-numbers-to-numbers** into **45de3dced906ca16586068fadcc3de426bf8dc6f on master**.

DrRataplan: Fixes #351 and maybe more

Patch:
diff --git a/.github/workflows/bundlesize.yml b/.github/workflows/bundlesize.yml
index d0f078db..2fa2792f 100644
--- a/.github/workflows/bundlesize.yml
+++ b/.github/workflows/bundlesize.yml
@@ -13,7 +13,7 @@ jobs:
             - uses: actions/checkout@v2
             - uses: actions/setup-node@v1
               with:
-                  node-version: '12'
+                  node-version: '20'
             - name: Install dependencies
               run: npm ci
             - name: override CI_COMMIT_SHA
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 0900c1ec..f13e8f57 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -12,9 +12,9 @@ jobs:
             fail-fast: false
             matrix:
                 node-version:
+                    - 20
                     - 18
                     - 16
-                    - 14
         steps:
             - uses: actions/checkout@v2
               with:
diff --git a/package-lock.json b/package-lock.json
index d2062562..bbe6886a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4773,9 +4773,9 @@
 			]
 		},
 		"node_modules/google-closure-compiler-osx": {
-			"version": "20221004.0.0",
-			"resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20221004.0.0.tgz",
-			"integrity": "sha512-z5V7BvaMauPga8DMTt9u6RGcjBdLAuv4gL2Ebw5NIQRTAHVkEVzCd3kiMX7CVCGhmWdS/1r3jZcCg4BswGia6w==",
+			"version": "20230206.0.0",
+			"resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20230206.0.0.tgz",
+			"integrity": "sha512-lJ/Y4HTk+KdL6PhLmmalP/3DdzGK0mS0+htuFP6y4t9+QXiUKnpHWx/VDQ3Fwm2fWEzqDxfhX3R+wC9lBvFiAg==",
 			"cpu": [
 				"x32",
 				"x64",
@@ -10645,7 +10645,7 @@
 				"fs-extra": "^10.0.1",
 				"google-closure-compiler-java": "^20221004.0.0",
 				"google-closure-compiler-linux": "^20221004.0.0",
-				"google-closure-compiler-osx": "^20221004.0.0",
+				"google-closure-compiler-osx": "^20230206.0.0",
 				"google-closure-compiler-windows": "^20221004.0.0",
 				"ora": "^5.4.1",
 				"resolve-from": "^5.0.0",
@@ -13330,9 +13330,9 @@
 			"optional": true
 		},
 		"google-closure-compiler-osx": {
-			"version": "20221004.0.0",
-			"resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20221004.0.0.tgz",
-			"integrity": "sha512-z5V7BvaMauPga8DMTt9u6RGcjBdLAuv4gL2Ebw5NIQRTAHVkEVzCd3kiMX7CVCGhmWdS/1r3jZcCg4BswGia6w==",
+			"version": "20230206.0.0",
+			"resolved": "https://registry.npmjs.org/google-closure-compiler-osx/-/google-closure-compiler-osx-20230206.0.0.tgz",
+			"integrity": "sha512-lJ/Y4HTk+KdL6PhLmmalP/3DdzGK0mS0+htuFP6y4t9+QXiUKnpHWx/VDQ3Fwm2fWEzqDxfhX3R+wC9lBvFiAg==",
 			"dev": true,
 			"optional": true
 		},
diff --git a/package.json b/package.json
index 72a6f153..c70c1afa 100644
--- a/package.json
+++ b/package.json
@@ -115,5 +115,8 @@
 	"dependencies": {
 		"prsc": "4.0.0",
 		"xspattern": "^3.1.0"
+	},
+	"overrides": {
+		"google-closure-compiler-osx": "^20230206.0.0"
 	}
 }
diff --git a/src/expressions/Expression.ts b/src/expressions/Expression.ts
index 47b8cefd..7c11ffef 100644
--- a/src/expressions/Expression.ts
+++ b/src/expressions/Expression.ts
@@ -4,6 +4,7 @@ import DynamicContext from './DynamicContext';
 import ExecutionParameters from './ExecutionParameters';
 import Specificity from './Specificity';
 import StaticContext from './StaticContext';
+import UnfocusableDynamicContext from './UnfocusableDynamicContext';
 import { Bucket } from './util/Bucket';
 import createDoublyIterableSequence from './util/createDoublyIterableSequence';
 import { errXUST0001 } from './xquery-update/XQueryUpdateFacilityErrors';
@@ -101,12 +102,17 @@ abstract class Expression {
 	}
 
 	protected evaluateWithoutFocus(
-		_contextlessDynamicContext: DynamicContext | null,
+		_contextlessDynamicContext: DynamicContext,
 		executionParameters: ExecutionParameters
 	): ISequence {
 		if (this._eagerlyEvaluatedValue === null) {
 			this._eagerlyEvaluatedValue = createDoublyIterableSequence(
-				this.evaluate(null, executionParameters).expandSequence()
+				this.evaluate(
+					new UnfocusableDynamicContext({
+						variableBindings: {},
+					}),
+					executionParameters
+				).expandSequence()
 			);
 		}
 		return this._eagerlyEvaluatedValue();


Test patch:
diff --git a/test/specs/parsing/operators/SimpleMapOperator.tests.ts b/test/specs/parsing/operators/SimpleMapOperator.tests.ts
index df7efa96..2c30210f 100644
--- a/test/specs/parsing/operators/SimpleMapOperator.tests.ts
+++ b/test/specs/parsing/operators/SimpleMapOperator.tests.ts
@@ -2,6 +2,7 @@ import * as chai from 'chai';
 import {
 	evaluateXPath,
 	evaluateXPathToNodes,
+	evaluateXPathToNumber,
 	evaluateXPathToString,
 	evaluateXPathToStrings,
 } from 'fontoxpath';
@@ -95,4 +96,6 @@ describe('Simple map operator', () => {
 		));
 	it('throws the correct error when mapping numbers to a ancestor path expresion', () =>
 		chai.assert.throws(() => evaluateXPathToNodes('0!ancestor::a', documentNode), 'XPTY0020'));
+	it('does not crash when mapping numbers to numbers', () =>
+		chai.assert.equal(evaluateXPathToNumber('0!1', documentNode), 1));
 });