@getodk/xforms-engine 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/TextRange.d.ts +0 -9
- package/dist/index.js +265 -146
- package/dist/index.js.map +1 -1
- package/dist/instance/RankControl.d.ts +3 -2
- package/dist/instance/SelectControl.d.ts +3 -2
- package/dist/parse/body/control/ItemsetDefinition.d.ts +1 -1
- package/dist/parse/expression/BindComputationExpression.d.ts +1 -1
- package/dist/parse/expression/ItemsetNodesetExpression.d.ts +1 -2
- package/dist/parse/expression/TextChunkExpression.d.ts +9 -7
- package/dist/parse/expression/abstract/DependentExpression.d.ts +1 -15
- package/dist/parse/model/ModelDefinition.d.ts +6 -1
- package/dist/parse/model/generateItextChunks.d.ts +5 -0
- package/dist/parse/xpath/semantic-analysis.d.ts +1 -0
- package/dist/solid.js +249 -116
- package/dist/solid.js.map +1 -1
- package/package.json +16 -16
- package/src/client/TextRange.ts +0 -9
- package/src/instance/RankControl.ts +8 -2
- package/src/instance/SelectControl.ts +8 -2
- package/src/lib/reactivity/text/createTextRange.ts +30 -30
- package/src/parse/body/control/ItemsetDefinition.ts +2 -2
- package/src/parse/expression/BindComputationExpression.ts +2 -7
- package/src/parse/expression/ItemsetNodesetExpression.ts +2 -3
- package/src/parse/expression/ItemsetValueExpression.ts +1 -1
- package/src/parse/expression/RepeatCountControlExpression.ts +4 -4
- package/src/parse/expression/TextChunkExpression.ts +25 -35
- package/src/parse/expression/abstract/DependentExpression.ts +2 -38
- package/src/parse/model/ModelDefinition.ts +13 -0
- package/src/parse/model/generateItextChunks.ts +61 -0
- package/src/parse/text/ItemsetLabelDefinition.ts +4 -4
- package/src/parse/text/MessageDefinition.ts +4 -4
- package/src/parse/text/abstract/TextElementDefinition.ts +6 -7
- package/src/parse/xpath/semantic-analysis.ts +37 -8
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
collectTypedNodes,
|
|
21
21
|
findTypedPrincipalExpressionNode,
|
|
22
22
|
isCompleteSubExpression,
|
|
23
|
+
type TypedSyntaxNode,
|
|
23
24
|
} from './syntax-traversal.ts';
|
|
24
25
|
|
|
25
26
|
// prettier-ignore
|
|
@@ -106,6 +107,24 @@ const isTranslationFunctionCall = (syntaxNode: FunctionCallNode): boolean => {
|
|
|
106
107
|
|
|
107
108
|
export type TranslationExpression = LocalNamedFunctionCallLiteral<'itext'>;
|
|
108
109
|
|
|
110
|
+
const findFunctionPrincipalExpressionNode = (
|
|
111
|
+
expression: string
|
|
112
|
+
): TypedSyntaxNode<'function_call'> | null => {
|
|
113
|
+
let result;
|
|
114
|
+
try {
|
|
115
|
+
result = expressionParser.parse(expression);
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const functionCallNode = findTypedPrincipalExpressionNode(['function_call'], result.rootNode);
|
|
121
|
+
if (functionCallNode == null) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return functionCallNode;
|
|
126
|
+
};
|
|
127
|
+
|
|
109
128
|
/**
|
|
110
129
|
* Determines if an arbitrary XPath expression is (in whole) a translation
|
|
111
130
|
* expression (i.e. a call to `jr:itext`).
|
|
@@ -117,19 +136,29 @@ export type TranslationExpression = LocalNamedFunctionCallLiteral<'itext'>;
|
|
|
117
136
|
export const isTranslationExpression = (
|
|
118
137
|
expression: string
|
|
119
138
|
): expression is TranslationExpression => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
result = expressionParser.parse(expression);
|
|
123
|
-
} catch {
|
|
139
|
+
const functionCallNode = findFunctionPrincipalExpressionNode(expression);
|
|
140
|
+
if (!functionCallNode) {
|
|
124
141
|
return false;
|
|
125
142
|
}
|
|
143
|
+
return isTranslationFunctionCall(functionCallNode);
|
|
144
|
+
};
|
|
126
145
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
146
|
+
export const getTranslationExpression = (expression: string): string | null => {
|
|
147
|
+
const functionCallNode = findFunctionPrincipalExpressionNode(expression);
|
|
148
|
+
if (!functionCallNode) {
|
|
149
|
+
return null;
|
|
130
150
|
}
|
|
131
151
|
|
|
132
|
-
|
|
152
|
+
if (!isTranslationFunctionCall(functionCallNode)) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const arg = functionCallNode.children.find((child) => child.type === 'argument');
|
|
157
|
+
if (!arg) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return arg.text;
|
|
133
162
|
};
|
|
134
163
|
|
|
135
164
|
const isCurrentFunctionCall = (syntaxNode: FunctionCallNode): boolean => {
|