@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.
Files changed (33) hide show
  1. package/dist/client/TextRange.d.ts +0 -9
  2. package/dist/index.js +265 -146
  3. package/dist/index.js.map +1 -1
  4. package/dist/instance/RankControl.d.ts +3 -2
  5. package/dist/instance/SelectControl.d.ts +3 -2
  6. package/dist/parse/body/control/ItemsetDefinition.d.ts +1 -1
  7. package/dist/parse/expression/BindComputationExpression.d.ts +1 -1
  8. package/dist/parse/expression/ItemsetNodesetExpression.d.ts +1 -2
  9. package/dist/parse/expression/TextChunkExpression.d.ts +9 -7
  10. package/dist/parse/expression/abstract/DependentExpression.d.ts +1 -15
  11. package/dist/parse/model/ModelDefinition.d.ts +6 -1
  12. package/dist/parse/model/generateItextChunks.d.ts +5 -0
  13. package/dist/parse/xpath/semantic-analysis.d.ts +1 -0
  14. package/dist/solid.js +249 -116
  15. package/dist/solid.js.map +1 -1
  16. package/package.json +16 -16
  17. package/src/client/TextRange.ts +0 -9
  18. package/src/instance/RankControl.ts +8 -2
  19. package/src/instance/SelectControl.ts +8 -2
  20. package/src/lib/reactivity/text/createTextRange.ts +30 -30
  21. package/src/parse/body/control/ItemsetDefinition.ts +2 -2
  22. package/src/parse/expression/BindComputationExpression.ts +2 -7
  23. package/src/parse/expression/ItemsetNodesetExpression.ts +2 -3
  24. package/src/parse/expression/ItemsetValueExpression.ts +1 -1
  25. package/src/parse/expression/RepeatCountControlExpression.ts +4 -4
  26. package/src/parse/expression/TextChunkExpression.ts +25 -35
  27. package/src/parse/expression/abstract/DependentExpression.ts +2 -38
  28. package/src/parse/model/ModelDefinition.ts +13 -0
  29. package/src/parse/model/generateItextChunks.ts +61 -0
  30. package/src/parse/text/ItemsetLabelDefinition.ts +4 -4
  31. package/src/parse/text/MessageDefinition.ts +4 -4
  32. package/src/parse/text/abstract/TextElementDefinition.ts +6 -7
  33. 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
- let result;
121
- try {
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
- const functionCallNode = findTypedPrincipalExpressionNode(['function_call'], result.rootNode);
128
- if (functionCallNode == null) {
129
- return false;
146
+ export const getTranslationExpression = (expression: string): string | null => {
147
+ const functionCallNode = findFunctionPrincipalExpressionNode(expression);
148
+ if (!functionCallNode) {
149
+ return null;
130
150
  }
131
151
 
132
- return isTranslationFunctionCall(functionCallNode);
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 => {