Skip to content

Commit 840bdce

Browse files
committed
improve map constructor problem reporting - using 'awaitingMapKey' property
1 parent 749a16d commit 840bdce

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

sample/fntest.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
version="3.0">
1010

1111
<xsl:variable name="fn" as="map(*)" select="
12-
map {'abc': 'def': 2: 'new'}"/>
12+
map {'abc':'new'}"/>
1313
</xsl:stylesheet>

src/xsltTokenDiagnostics.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ interface XPathData {
6565
function?: BaseToken;
6666
functionArity?: number;
6767
isRangeVar?: boolean;
68+
awaitingMapKey?: boolean;
6869
curlyBraceType?: CurlyBraceType;
6970
}
7071

@@ -1126,6 +1127,18 @@ export class XsltTokenDiagnostics {
11261127
let tv = token.value;
11271128

11281129
// start checks
1130+
const stackItem: XPathData | undefined = xpathStack.length > 0 ? xpathStack[xpathStack.length - 1] : undefined;
1131+
if (stackItem && stackItem.curlyBraceType === CurlyBraceType.Map) {
1132+
if (tv === ',') {
1133+
if (stackItem.awaitingMapKey) {
1134+
isXPathError = true;
1135+
} else {
1136+
stackItem.awaitingMapKey = true;
1137+
}
1138+
} else if (tv === '}' && stackItem.awaitingMapKey) {
1139+
isXPathError = true;
1140+
}
1141+
}
11291142
if (prevToken?.tokenType === TokenLevelState.uriLiteral) {
11301143
token['error'] = ErrorType.XPathUnexpected;
11311144
problemTokens.push(token);
@@ -1134,8 +1147,12 @@ export class XsltTokenDiagnostics {
11341147
let currCharType = <CharLevelState>token.charType;
11351148
let nextToken = index + 1 < allTokens.length ? allTokens[index + 1] : undefined;
11361149
if (tv === ':') {
1137-
if (xpathStack.length > 0 && xpathStack[xpathStack.length - 1].curlyBraceType === CurlyBraceType.Map) {
1138-
// not an error in a map
1150+
if (stackItem && stackItem.curlyBraceType === CurlyBraceType.Map) {
1151+
if (stackItem.awaitingMapKey) {
1152+
stackItem.awaitingMapKey = false;
1153+
} else {
1154+
isXPathError = true;
1155+
}
11391156
} else if (prevToken.tokenType === TokenLevelState.nodeNameTest || prevToken.tokenType === TokenLevelState.attributeNameTest) {
11401157
isXPathError = !(prevToken.startCharacter + prevToken.length === token.startCharacter && nextToken?.value === '*');
11411158
} else {
@@ -1251,8 +1268,11 @@ export class XsltTokenDiagnostics {
12511268
curlyBraceType = CurlyBraceType.Array;
12521269
}
12531270
}
1254-
1255-
xpathStack.push({ token: token, variables: inScopeXPathVariablesList, preXPathVariable: preXPathVariable, xpathVariableCurrentlyBeingDefined: xpathVariableCurrentlyBeingDefined, curlyBraceType });
1271+
const stackItem: XPathData = { token: token, variables: inScopeXPathVariablesList, preXPathVariable: preXPathVariable, xpathVariableCurrentlyBeingDefined: xpathVariableCurrentlyBeingDefined, curlyBraceType };
1272+
if (curlyBraceType === CurlyBraceType.Map) {
1273+
stackItem.awaitingMapKey = true;
1274+
}
1275+
xpathStack.push(stackItem);
12561276
if (anonymousFunctionParams) {
12571277
// handle case: function($a) {$a + 8} pass params to inside '{...}'
12581278
inScopeXPathVariablesList = anonymousFunctionParamList;

0 commit comments

Comments
 (0)