Skip to content

Commit e6f3ac2

Browse files
committed
ensure ? at end of xs:integer? within 'as' attribute within a function
does not cause a 'missing context-item' error
1 parent b7f41dd commit e6f3ac2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/xsltTokenDiagnostics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,8 @@ export class XsltTokenDiagnostics {
11821182
const nextToken = allTokens[index + 1];
11831183
isPartialFunctionArg = (nextToken.charType === CharLevelState.rB || nextToken.value === ',');
11841184
}
1185-
if (!isNoArgFunctionCall && !isPartialFunctionArg && !XsltTokenDiagnostics.contextItemExists(elementStack, xpathStack, insideGlobalFunction)) {
1185+
const withinTypeDeclarationAttr = tagAttributeNames.length > 0 && tagAttributeNames[tagAttributeNames.length - 1] === 'as';
1186+
if (!withinTypeDeclarationAttr && !isNoArgFunctionCall && !isPartialFunctionArg && !XsltTokenDiagnostics.contextItemExists(elementStack, xpathStack, insideGlobalFunction)) {
11861187
token.error = ErrorType.MissingContextItemGeneral;
11871188
problemTokens.push(token);
11881189
}

test/issue-144.xsl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:fn="namespace-uri"
45
version="3.0">
56

6-
<!-- the following type declarations should have no errors -->
7+
<?START type declarations with NO ERRORS?>
78
<xsl:variable name="test1" as="xs:integer" select="count(22)"/>
89
<xsl:variable name="test2" as="map(xs:integer, map(xs:string, array(*)))" select="/*"/>
910
<xsl:variable name="test3" as="xs:integer" select="1"/>
@@ -12,16 +13,28 @@
1213
select="function($a as element()) as xs:string {local-name($a)}"/>
1314
<xsl:variable name="test6" as="xs:boolean" select="2 instance of array(function())"/>
1415

15-
<!-- all tokens in the following type declarations should be marked as errors -->
16+
<xsl:function name="fn:main" as="item()*">
17+
<xsl:param name="test7" as="xs:integer?"/>
18+
<xsl:sequence select="$test7"/>
19+
</xsl:function>
20+
<?END type declarations with NO ERRORS?>
21+
22+
23+
<?START type declarations WITH ERRORS?>
1624
<xsl:variable name="test1-error" as="xs:intege" select="count(22)"/>
1725
<xsl:variable name="test2-error" as="xs:map(xs:integeer, mapp(xs:sstring, aarray(*)))" select="/*"/>
1826
<xsl:variable name="test3-error" as="string" select="1"/>
1927
<xsl:variable name="test4-error" as="elejment('book')" select="/*"/>
28+
<xsl:variable name="test5-error" as="" select="'the `as` attribute is empty'"/>
29+
<?END type declarations WITH ERRORS?>
2030

31+
<?START auto-complete test?>
32+
2133
<!--
2234
1. the 'as' attribute below should be marked with an error
2335
2. type within the 'as' attribute, the auto-complete list should be triggered and populated properly
2436
-->
2537
<xsl:variable name="test1-autocomplate" as="" select="'a string'"/>
38+
<?END auto-complete test?>
2639

2740
</xsl:stylesheet>

0 commit comments

Comments
 (0)