From 7573bdfa36e015a51d1b7d2b7787b1eb5d95a787 Mon Sep 17 00:00:00 2001 From: Martin Middel Date: Mon, 1 Sep 2025 11:13:22 +0200 Subject: [PATCH] Statically compile type test for instance of operator Without that, the namespace part is never picked up --- .../operators/types/InstanceOfOperator.ts | 2 +- .../types/InstanceOfOperator.tests.ts | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/expressions/operators/types/InstanceOfOperator.ts b/src/expressions/operators/types/InstanceOfOperator.ts index b9656ead1..a9444ed64 100644 --- a/src/expressions/operators/types/InstanceOfOperator.ts +++ b/src/expressions/operators/types/InstanceOfOperator.ts @@ -18,7 +18,7 @@ class InstanceOfOperator extends Expression { ) { super( expression.specificity, - [expression], + [expression, typeTest], { canBeStaticallyEvaluated: false }, false, type, diff --git a/test/specs/parsing/operators/types/InstanceOfOperator.tests.ts b/test/specs/parsing/operators/types/InstanceOfOperator.tests.ts index e00804003..557a318af 100644 --- a/test/specs/parsing/operators/types/InstanceOfOperator.tests.ts +++ b/test/specs/parsing/operators/types/InstanceOfOperator.tests.ts @@ -1,8 +1,7 @@ import * as chai from 'chai'; -import * as slimdom from 'slimdom'; +import { Document } from 'slimdom'; -import { evaluateXPathToBoolean } from 'fontoxpath'; -import evaluateXPathToAsyncSingleton from 'test-helpers/evaluateXPathToAsyncSingleton'; +import { Language, evaluateXPathToBoolean } from 'fontoxpath'; describe('instance of operator', () => { it('returns true for a valid instance of xs:boolean', () => @@ -38,4 +37,17 @@ describe('instance of operator', () => { it('returns false for an invalid instance of node()', () => chai.assert.isFalse(evaluateXPathToBoolean('1 instance of node()'))); + + it('keeps namespaces into account', () => { + chai.assert.isTrue( + evaluateXPathToBoolean( + `declare namespace x='x'; + instance of element(x:ele)`, + new Document(), + null, + null, + { language: Language.XQUERY_3_1_LANGUAGE }, + ), + ); + }); });