@teleporthq/teleport-plugin-common 0.45.3-alpha.0 → 0.45.13

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 (200) hide show
  1. package/__tests__/builders/html-builders.ts +9 -2
  2. package/__tests__/builders/style-builders.ts +135 -1
  3. package/__tests__/node-handlers/node-to-html/index.ts +2 -0
  4. package/__tests__/node-handlers/node-to-jsx/attribute-value-mapper.ts +77 -0
  5. package/__tests__/node-handlers/node-to-jsx/calendar-events-reviver.ts +176 -0
  6. package/__tests__/node-handlers/node-to-jsx/chart-data-guard.ts +101 -0
  7. package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-ecommerce-source.ts +79 -0
  8. package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-loading.ts +122 -0
  9. package/__tests__/node-handlers/node-to-jsx/index.ts +719 -3
  10. package/__tests__/node-handlers/node-to-jsx/url-search-params-expression.ts +59 -0
  11. package/__tests__/node-handlers/node-to-jsx/utils.ts +635 -3
  12. package/__tests__/utils/ast-utils.ts +188 -0
  13. package/__tests__/utils/content-property-sanitiser.ts +156 -0
  14. package/__tests__/utils/page-seeds-state-from-data-source.ts +70 -0
  15. package/__tests__/utils/parse-string-with-template-expressions.ts +82 -0
  16. package/__tests__/utils/resource-auth-scheme.ts +55 -0
  17. package/__tests__/utils/route-utils.ts +118 -0
  18. package/__tests__/utils/style-utils.ts +59 -0
  19. package/__tests__/utils/template-expression-balance.ts +83 -0
  20. package/__tests__/utils/url-query-writer.ts +239 -0
  21. package/__tests__/utils/url-search-param-sync.ts +138 -0
  22. package/__tests__/utils/url-search-params.ts +48 -0
  23. package/dist/cjs/builders/ast-builders.d.ts +2 -0
  24. package/dist/cjs/builders/ast-builders.d.ts.map +1 -1
  25. package/dist/cjs/builders/ast-builders.js +41 -3
  26. package/dist/cjs/builders/ast-builders.js.map +1 -1
  27. package/dist/cjs/builders/hast-builders.d.ts +1 -0
  28. package/dist/cjs/builders/hast-builders.d.ts.map +1 -1
  29. package/dist/cjs/builders/hast-builders.js +11 -1
  30. package/dist/cjs/builders/hast-builders.js.map +1 -1
  31. package/dist/cjs/builders/style-builders.d.ts +8 -2
  32. package/dist/cjs/builders/style-builders.d.ts.map +1 -1
  33. package/dist/cjs/builders/style-builders.js +80 -33
  34. package/dist/cjs/builders/style-builders.js.map +1 -1
  35. package/dist/cjs/index.d.ts +5 -1
  36. package/dist/cjs/index.d.ts.map +1 -1
  37. package/dist/cjs/index.js +10 -1
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/node-handlers/node-to-html/constants.d.ts.map +1 -1
  40. package/dist/cjs/node-handlers/node-to-html/constants.js +2 -0
  41. package/dist/cjs/node-handlers/node-to-html/constants.js.map +1 -1
  42. package/dist/cjs/node-handlers/node-to-html/index.d.ts.map +1 -1
  43. package/dist/cjs/node-handlers/node-to-html/index.js +69 -1
  44. package/dist/cjs/node-handlers/node-to-html/index.js.map +1 -1
  45. package/dist/cjs/node-handlers/node-to-html/types.d.ts +5 -1
  46. package/dist/cjs/node-handlers/node-to-html/types.d.ts.map +1 -1
  47. package/dist/cjs/node-handlers/node-to-html/utils.d.ts +2 -1
  48. package/dist/cjs/node-handlers/node-to-html/utils.d.ts.map +1 -1
  49. package/dist/cjs/node-handlers/node-to-html/utils.js +174 -13
  50. package/dist/cjs/node-handlers/node-to-html/utils.js.map +1 -1
  51. package/dist/cjs/node-handlers/node-to-jsx/index.d.ts.map +1 -1
  52. package/dist/cjs/node-handlers/node-to-jsx/index.js +1443 -45
  53. package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
  54. package/dist/cjs/node-handlers/node-to-jsx/types.d.ts +60 -6
  55. package/dist/cjs/node-handlers/node-to-jsx/types.d.ts.map +1 -1
  56. package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts +80 -7
  57. package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
  58. package/dist/cjs/node-handlers/node-to-jsx/utils.js +883 -72
  59. package/dist/cjs/node-handlers/node-to-jsx/utils.js.map +1 -1
  60. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  61. package/dist/cjs/utils/ast-utils.d.ts +163 -11
  62. package/dist/cjs/utils/ast-utils.d.ts.map +1 -1
  63. package/dist/cjs/utils/ast-utils.js +1013 -75
  64. package/dist/cjs/utils/ast-utils.js.map +1 -1
  65. package/dist/cjs/utils/hast-utils.d.ts +8 -6
  66. package/dist/cjs/utils/hast-utils.d.ts.map +1 -1
  67. package/dist/cjs/utils/hast-utils.js +28 -4
  68. package/dist/cjs/utils/hast-utils.js.map +1 -1
  69. package/dist/cjs/utils/nested-selector-commas.d.ts +2 -0
  70. package/dist/cjs/utils/nested-selector-commas.d.ts.map +1 -0
  71. package/dist/cjs/utils/nested-selector-commas.js +81 -0
  72. package/dist/cjs/utils/nested-selector-commas.js.map +1 -0
  73. package/dist/cjs/utils/route-utils.d.ts +117 -0
  74. package/dist/cjs/utils/route-utils.d.ts.map +1 -0
  75. package/dist/cjs/utils/route-utils.js +212 -0
  76. package/dist/cjs/utils/route-utils.js.map +1 -0
  77. package/dist/cjs/utils/style-utils.d.ts +1 -0
  78. package/dist/cjs/utils/style-utils.d.ts.map +1 -1
  79. package/dist/cjs/utils/style-utils.js +181 -2
  80. package/dist/cjs/utils/style-utils.js.map +1 -1
  81. package/dist/cjs/utils/template-expression-balance.d.ts +58 -0
  82. package/dist/cjs/utils/template-expression-balance.d.ts.map +1 -0
  83. package/dist/cjs/utils/template-expression-balance.js +181 -0
  84. package/dist/cjs/utils/template-expression-balance.js.map +1 -0
  85. package/dist/cjs/utils/types.d.ts +3 -0
  86. package/dist/cjs/utils/types.d.ts.map +1 -0
  87. package/dist/cjs/utils/types.js +3 -0
  88. package/dist/cjs/utils/types.js.map +1 -0
  89. package/dist/cjs/utils/url-query-writer.d.ts +123 -0
  90. package/dist/cjs/utils/url-query-writer.d.ts.map +1 -0
  91. package/dist/cjs/utils/url-query-writer.js +260 -0
  92. package/dist/cjs/utils/url-query-writer.js.map +1 -0
  93. package/dist/cjs/utils/url-search-param-sync.d.ts +4 -0
  94. package/dist/cjs/utils/url-search-param-sync.d.ts.map +1 -0
  95. package/dist/cjs/utils/url-search-param-sync.js +241 -0
  96. package/dist/cjs/utils/url-search-param-sync.js.map +1 -0
  97. package/dist/cjs/utils/url-search-params.d.ts +48 -0
  98. package/dist/cjs/utils/url-search-params.d.ts.map +1 -0
  99. package/dist/cjs/utils/url-search-params.js +109 -0
  100. package/dist/cjs/utils/url-search-params.js.map +1 -0
  101. package/dist/esm/builders/ast-builders.d.ts +2 -0
  102. package/dist/esm/builders/ast-builders.d.ts.map +1 -1
  103. package/dist/esm/builders/ast-builders.js +40 -4
  104. package/dist/esm/builders/ast-builders.js.map +1 -1
  105. package/dist/esm/builders/hast-builders.d.ts +1 -0
  106. package/dist/esm/builders/hast-builders.d.ts.map +1 -1
  107. package/dist/esm/builders/hast-builders.js +9 -0
  108. package/dist/esm/builders/hast-builders.js.map +1 -1
  109. package/dist/esm/builders/style-builders.d.ts +8 -2
  110. package/dist/esm/builders/style-builders.d.ts.map +1 -1
  111. package/dist/esm/builders/style-builders.js +78 -32
  112. package/dist/esm/builders/style-builders.js.map +1 -1
  113. package/dist/esm/index.d.ts +5 -1
  114. package/dist/esm/index.d.ts.map +1 -1
  115. package/dist/esm/index.js +5 -1
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/node-handlers/node-to-html/constants.d.ts.map +1 -1
  118. package/dist/esm/node-handlers/node-to-html/constants.js +2 -0
  119. package/dist/esm/node-handlers/node-to-html/constants.js.map +1 -1
  120. package/dist/esm/node-handlers/node-to-html/index.d.ts.map +1 -1
  121. package/dist/esm/node-handlers/node-to-html/index.js +71 -3
  122. package/dist/esm/node-handlers/node-to-html/index.js.map +1 -1
  123. package/dist/esm/node-handlers/node-to-html/types.d.ts +5 -1
  124. package/dist/esm/node-handlers/node-to-html/types.d.ts.map +1 -1
  125. package/dist/esm/node-handlers/node-to-html/utils.d.ts +2 -1
  126. package/dist/esm/node-handlers/node-to-html/utils.d.ts.map +1 -1
  127. package/dist/esm/node-handlers/node-to-html/utils.js +170 -13
  128. package/dist/esm/node-handlers/node-to-html/utils.js.map +1 -1
  129. package/dist/esm/node-handlers/node-to-jsx/index.d.ts.map +1 -1
  130. package/dist/esm/node-handlers/node-to-jsx/index.js +1442 -47
  131. package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
  132. package/dist/esm/node-handlers/node-to-jsx/types.d.ts +60 -6
  133. package/dist/esm/node-handlers/node-to-jsx/types.d.ts.map +1 -1
  134. package/dist/esm/node-handlers/node-to-jsx/utils.d.ts +80 -7
  135. package/dist/esm/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
  136. package/dist/esm/node-handlers/node-to-jsx/utils.js +875 -70
  137. package/dist/esm/node-handlers/node-to-jsx/utils.js.map +1 -1
  138. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  139. package/dist/esm/utils/ast-utils.d.ts +163 -11
  140. package/dist/esm/utils/ast-utils.d.ts.map +1 -1
  141. package/dist/esm/utils/ast-utils.js +989 -75
  142. package/dist/esm/utils/ast-utils.js.map +1 -1
  143. package/dist/esm/utils/hast-utils.d.ts +8 -6
  144. package/dist/esm/utils/hast-utils.d.ts.map +1 -1
  145. package/dist/esm/utils/hast-utils.js +26 -3
  146. package/dist/esm/utils/hast-utils.js.map +1 -1
  147. package/dist/esm/utils/nested-selector-commas.d.ts +2 -0
  148. package/dist/esm/utils/nested-selector-commas.d.ts.map +1 -0
  149. package/dist/esm/utils/nested-selector-commas.js +77 -0
  150. package/dist/esm/utils/nested-selector-commas.js.map +1 -0
  151. package/dist/esm/utils/route-utils.d.ts +117 -0
  152. package/dist/esm/utils/route-utils.d.ts.map +1 -0
  153. package/dist/esm/utils/route-utils.js +179 -0
  154. package/dist/esm/utils/route-utils.js.map +1 -0
  155. package/dist/esm/utils/style-utils.d.ts +1 -0
  156. package/dist/esm/utils/style-utils.d.ts.map +1 -1
  157. package/dist/esm/utils/style-utils.js +179 -1
  158. package/dist/esm/utils/style-utils.js.map +1 -1
  159. package/dist/esm/utils/template-expression-balance.d.ts +58 -0
  160. package/dist/esm/utils/template-expression-balance.d.ts.map +1 -0
  161. package/dist/esm/utils/template-expression-balance.js +174 -0
  162. package/dist/esm/utils/template-expression-balance.js.map +1 -0
  163. package/dist/esm/utils/types.d.ts +3 -0
  164. package/dist/esm/utils/types.d.ts.map +1 -0
  165. package/dist/esm/utils/types.js +2 -0
  166. package/dist/esm/utils/types.js.map +1 -0
  167. package/dist/esm/utils/url-query-writer.d.ts +123 -0
  168. package/dist/esm/utils/url-query-writer.d.ts.map +1 -0
  169. package/dist/esm/utils/url-query-writer.js +229 -0
  170. package/dist/esm/utils/url-query-writer.js.map +1 -0
  171. package/dist/esm/utils/url-search-param-sync.d.ts +4 -0
  172. package/dist/esm/utils/url-search-param-sync.d.ts.map +1 -0
  173. package/dist/esm/utils/url-search-param-sync.js +213 -0
  174. package/dist/esm/utils/url-search-param-sync.js.map +1 -0
  175. package/dist/esm/utils/url-search-params.d.ts +48 -0
  176. package/dist/esm/utils/url-search-params.d.ts.map +1 -0
  177. package/dist/esm/utils/url-search-params.js +81 -0
  178. package/dist/esm/utils/url-search-params.js.map +1 -0
  179. package/package.json +4 -4
  180. package/src/builders/ast-builders.ts +80 -3
  181. package/src/builders/hast-builders.ts +11 -0
  182. package/src/builders/style-builders.ts +121 -43
  183. package/src/index.ts +22 -1
  184. package/src/node-handlers/node-to-html/constants.ts +2 -0
  185. package/src/node-handlers/node-to-html/index.ts +126 -6
  186. package/src/node-handlers/node-to-html/types.ts +6 -0
  187. package/src/node-handlers/node-to-html/utils.ts +228 -14
  188. package/src/node-handlers/node-to-jsx/index.ts +2135 -62
  189. package/src/node-handlers/node-to-jsx/types.ts +75 -32
  190. package/src/node-handlers/node-to-jsx/utils.ts +1173 -84
  191. package/src/utils/ast-utils.ts +1316 -127
  192. package/src/utils/hast-utils.ts +37 -9
  193. package/src/utils/nested-selector-commas.ts +88 -0
  194. package/src/utils/route-utils.ts +214 -0
  195. package/src/utils/style-utils.ts +183 -1
  196. package/src/utils/template-expression-balance.ts +196 -0
  197. package/src/utils/types.ts +25 -0
  198. package/src/utils/url-query-writer.ts +318 -0
  199. package/src/utils/url-search-param-sync.ts +303 -0
  200. package/src/utils/url-search-params.ts +122 -0
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
14
  if (k2 === undefined) k2 = k;
4
15
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -32,19 +43,146 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
32
43
  return to.concat(ar || Array.prototype.slice.call(from));
33
44
  };
34
45
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.getRepeatSourceIdentifier = exports.createBinaryExpression = exports.createConditionalJSXExpression = exports.createConditionIdentifier = exports.createDynamicValueExpression = exports.addEventHandlerToTag = void 0;
46
+ exports.getRepeatSourceIdentifier = exports.createBinaryExpression = exports.createClassConditionExpression = exports.createConditionalJSXExpression = exports.createConditionIdentifier = exports.createDynamicValueExpression = exports.createGlobalStateExpression = exports.resolveAndRegisterGlobalStateSource = exports.resolveGlobalStateName = exports.createStateChangeStatement = exports.addEventHandlerToTag = exports.makeControlUncontrolledWhenNoChangeHandler = void 0;
36
47
  var types = __importStar(require("@babel/types"));
37
48
  var ast_utils_1 = require("../../utils/ast-utils");
38
49
  var teleport_shared_1 = require("@teleporthq/teleport-shared");
50
+ var uidl_utils_1 = require("@teleporthq/teleport-shared/dist/cjs/utils/uidl-utils");
39
51
  // Adds all the event handlers and all the instructions for each event handler
40
52
  // in case there is more than one specified in the UIDL
53
+ /** HTML form controls that React treats as "controlled" when given a value/checked prop. */
54
+ var CONTROLLED_FORM_CONTROL_TAGS = new Set(['input', 'textarea', 'select']);
55
+ /**
56
+ * `<input type=...>` values the browser accepts ONLY in a narrow string format,
57
+ * mapped to the number of leading ISO-8601 characters that format requires:
58
+ * datetime-local → `YYYY-MM-DDTHH:mm` (16) date → `YYYY-MM-DD` (10)
59
+ * month → `YYYY-MM` (7)
60
+ * A stored timestamp such as `2026-07-21T20:00:00.000Z` (with seconds/ms and a
61
+ * `Z`) does NOT conform, so the input renders EMPTY — and when it is `required`
62
+ * the whole form fails HTML5 validation and can never submit (edit pages could
63
+ * not be saved). `time` is handled separately because its digits are not a
64
+ * simple prefix. Slicing the ISO STRING (not `new Date(...)`) keeps the nominal
65
+ * wall-clock value and avoids server/browser timezone shifts.
66
+ */
67
+ var DATE_TIME_INPUT_PREFIX_LENGTH = {
68
+ 'datetime-local': 16,
69
+ date: 10,
70
+ month: 7,
71
+ };
72
+ /** Reads a static `type="..."` off a JSX opening tag, lowercased; null if absent/dynamic. */
73
+ var getStaticInputType = function (tag) {
74
+ var typeAttr = tag.openingElement.attributes.find(function (attr) {
75
+ return attr.type === 'JSXAttribute' &&
76
+ attr.name.type === 'JSXIdentifier' &&
77
+ attr.name.name === 'type';
78
+ });
79
+ if (!typeAttr || !typeAttr.value || typeAttr.value.type !== 'StringLiteral') {
80
+ return null;
81
+ }
82
+ return typeAttr.value.value.toLowerCase();
83
+ };
84
+ /**
85
+ * Wrap a bound `<input>` value expression so it renders in the format the input
86
+ * `type` requires. Returns the original expression untouched for non date/time
87
+ * types. `E` → `String(E || '').slice(0, N)` (date/datetime-local/month) or, for
88
+ * `time`, strip an optional leading `YYYY-MM-DD[T| ]` date then take `HH:mm`.
89
+ */
90
+ var buildDateTimeInputValueExpression = function (expression, inputType, t) {
91
+ if (t === void 0) { t = types; }
92
+ var stringified = t.callExpression(t.identifier('String'), [
93
+ t.logicalExpression('||', expression, t.stringLiteral('')),
94
+ ]);
95
+ if (inputType === 'time') {
96
+ var dateStripped = t.callExpression(t.memberExpression(stringified, t.identifier('replace')), [t.regExpLiteral('^\\d{4}-\\d{2}-\\d{2}[T ]', ''), t.stringLiteral('')]);
97
+ return t.callExpression(t.memberExpression(dateStripped, t.identifier('slice')), [
98
+ t.numericLiteral(0),
99
+ t.numericLiteral(5),
100
+ ]);
101
+ }
102
+ var prefixLength = DATE_TIME_INPUT_PREFIX_LENGTH[inputType];
103
+ return t.callExpression(t.memberExpression(stringified, t.identifier('slice')), [
104
+ t.numericLiteral(0),
105
+ t.numericLiteral(prefixLength),
106
+ ]);
107
+ };
108
+ /**
109
+ * React FREEZES a controlled form control (`value`/`checked` set) that has no
110
+ * `onChange` — the user cannot type and a console warning is logged. This is the
111
+ * classic edit-form failure: entity-bound fields rendered `value={props.item?.x}`
112
+ * with no state mirror (the worker intentionally does not mirror entity columns
113
+ * into state). When an `<input>`/`<textarea>`/`<select>` has a `value` (or a
114
+ * checkbox/radio `checked`) attribute but NO `onChange` handler was attached, and
115
+ * it is not `readOnly`/`disabled`, convert it to UNCONTROLLED — `value`→
116
+ * `defaultValue`, `checked`→`defaultChecked`. The control then pre-fills, stays
117
+ * editable, and its live DOM value is what form-submit workflows read via
118
+ * `document.getElementById(id).value`. Controls that ARE controlled (an onChange
119
+ * was already attached — via UIDL events, the form-store binding, or a workflow
120
+ * trigger) and read-only/disabled display fields are left untouched.
121
+ *
122
+ * Must run AFTER all attributes and event handlers have been added to the tag.
123
+ * Mutates the tag in place; idempotent.
124
+ */
125
+ var makeControlUncontrolledWhenNoChangeHandler = function (tag, elementName, t) {
126
+ if (t === void 0) { t = types; }
127
+ if (!CONTROLLED_FORM_CONTROL_TAGS.has(elementName.toLowerCase())) {
128
+ return;
129
+ }
130
+ var attributes = tag.openingElement.attributes;
131
+ var hasNamedAttribute = function (name) {
132
+ return attributes.some(function (attr) {
133
+ return attr.type === 'JSXAttribute' &&
134
+ attr.name.type === 'JSXIdentifier' &&
135
+ attr.name.name === name;
136
+ });
137
+ };
138
+ // An onChange means it is legitimately controlled; readOnly/disabled inputs are
139
+ // intentionally non-editable display fields (React does not warn on those).
140
+ if (hasNamedAttribute('onChange') ||
141
+ hasNamedAttribute('readOnly') ||
142
+ hasNamedAttribute('disabled')) {
143
+ return;
144
+ }
145
+ // A date/time `<input>` whose value is a dynamic binding (an entity-prefilled
146
+ // edit field) must have its ISO value reformatted to the input's required
147
+ // string shape, or the browser drops it and a `required` field blocks submit.
148
+ var inputType = elementName.toLowerCase() === 'input' ? getStaticInputType(tag) : null;
149
+ var needsDateTimeFormat = inputType !== null && (inputType === 'time' || inputType in DATE_TIME_INPUT_PREFIX_LENGTH);
150
+ var controlledToUncontrolled = [
151
+ ['value', 'defaultValue'],
152
+ ['checked', 'defaultChecked'],
153
+ ];
154
+ var _loop_1 = function (controlled, uncontrolled) {
155
+ var index = attributes.findIndex(function (attr) {
156
+ return attr.type === 'JSXAttribute' &&
157
+ attr.name.type === 'JSXIdentifier' &&
158
+ attr.name.name === controlled;
159
+ });
160
+ if (index !== -1) {
161
+ var attr = attributes[index];
162
+ var attrValue = attr.value;
163
+ if (controlled === 'value' &&
164
+ needsDateTimeFormat &&
165
+ attrValue &&
166
+ attrValue.type === 'JSXExpressionContainer' &&
167
+ attrValue.expression.type !== 'JSXEmptyExpression') {
168
+ attrValue = t.jsxExpressionContainer(buildDateTimeInputValueExpression(attrValue.expression, inputType, t));
169
+ }
170
+ attributes.splice(index, 1, t.jsxAttribute(t.jsxIdentifier(uncontrolled), attrValue));
171
+ }
172
+ };
173
+ for (var _i = 0, controlledToUncontrolled_1 = controlledToUncontrolled; _i < controlledToUncontrolled_1.length; _i++) {
174
+ var _a = controlledToUncontrolled_1[_i], controlled = _a[0], uncontrolled = _a[1];
175
+ _loop_1(controlled, uncontrolled);
176
+ }
177
+ };
178
+ exports.makeControlUncontrolledWhenNoChangeHandler = makeControlUncontrolledWhenNoChangeHandler;
41
179
  var addEventHandlerToTag = function (tag, eventKey, eventHandlerStatements, params, options, t) {
42
180
  if (t === void 0) { t = types; }
43
181
  var eventHandlerASTStatements = [];
44
182
  var propDefinitions = params.propDefinitions, stateDefinitions = params.stateDefinitions;
45
183
  eventHandlerStatements.forEach(function (eventHandlerAction) {
46
184
  if (eventHandlerAction.type === 'stateChange') {
47
- var handler = createStateChangeStatement(eventHandlerAction, stateDefinitions, options);
185
+ var handler = (0, exports.createStateChangeStatement)(eventHandlerAction, stateDefinitions, options);
48
186
  if (handler) {
49
187
  eventHandlerASTStatements.push(handler);
50
188
  }
@@ -57,15 +195,18 @@ var addEventHandlerToTag = function (tag, eventKey, eventHandlerStatements, para
57
195
  }
58
196
  });
59
197
  var expressionContent;
198
+ var functionParams = eventHandlerStatements.some(function (eventHandler) { return eventHandler.includeEventObject; })
199
+ ? [t.identifier('event')]
200
+ : [];
60
201
  if (eventHandlerASTStatements.length === 1) {
61
202
  var expression = eventHandlerASTStatements[0].expression;
62
203
  expressionContent =
63
204
  expression.type === 'CallExpression' && expression.arguments.length === 0
64
205
  ? expression.callee
65
- : t.arrowFunctionExpression([], expression);
206
+ : t.arrowFunctionExpression(functionParams, expression);
66
207
  }
67
208
  else {
68
- expressionContent = t.arrowFunctionExpression([], t.blockStatement(eventHandlerASTStatements));
209
+ expressionContent = t.arrowFunctionExpression(functionParams, t.blockStatement(eventHandlerASTStatements));
69
210
  }
70
211
  tag.openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier(eventKey), t.jsxExpressionContainer(expressionContent)));
71
212
  };
@@ -85,9 +226,35 @@ var createPropCallStatement = function (eventHandlerStatement, propDefinitions,
85
226
  var prefix = options.dynamicReferencePrefixMap.prop
86
227
  ? options.dynamicReferencePrefixMap.prop + '.'
87
228
  : '';
88
- return t.expressionStatement(t.callExpression(t.identifier(prefix + propFunctionKey), __spreadArray([], args.map(function (arg) { return (0, ast_utils_1.convertValueToLiteral)(arg); }), true)));
229
+ // Un-prefixed the prop name is called as a bare binding, so it must be
230
+ // identifier-safe; prefixed it is `props.<name>`, where the UIDL spelling is
231
+ // both legal and load-bearing.
232
+ var calleeName = prefix
233
+ ? prefix + propFunctionKey
234
+ : teleport_shared_1.JSIdentifiers.createSafeJSIdentifier(propFunctionKey);
235
+ return t.expressionStatement(t.callExpression(t.identifier(calleeName), __spreadArray([], args.map(function (arg) { return (0, ast_utils_1.convertValueToLiteral)(arg); }), true)));
89
236
  };
237
+ /**
238
+ * Plan v14 — Type-aware state setter emitter.
239
+ *
240
+ * The old emitter unconditionally produced `setX(!x)` for `$toggle` and
241
+ * `setX(<literal>)` for primitives, regardless of the declared state
242
+ * type. That broke every multi-step form: `$toggle` on a numeric step
243
+ * state turned `1` into `false`, hiding every `state === N` panel; a
244
+ * primitive written to an object state replaced the whole object.
245
+ *
246
+ * The codegen here is now the safety net for what server-side Layers 1-3
247
+ * could not catch (legacy projects, AI bypass). When a combination is
248
+ * incoherent (e.g. `$toggle` on a number, or a bare string targeting an
249
+ * object), we skip the statement and warn — the workflow runtime handler
250
+ * remains the source of truth. Coherent combinations emit the same code
251
+ * as before, plus four new modifier shapes (`$increment` / `$decrement` /
252
+ * `$patch` / `$append`) that produce React functional setters.
253
+ *
254
+ * Returns `null` when the emitter declines (caller already handles null).
255
+ */
90
256
  var createStateChangeStatement = function (eventHandlerStatement, stateDefinitions, options, t) {
257
+ var _a;
91
258
  if (t === void 0) { t = types; }
92
259
  if (!eventHandlerStatement.modifies) {
93
260
  console.warn("No state identifier referenced under the \"modifies\" field");
@@ -95,69 +262,530 @@ var createStateChangeStatement = function (eventHandlerStatement, stateDefinitio
95
262
  }
96
263
  var stateKey = eventHandlerStatement.modifies;
97
264
  var stateDefinition = stateDefinitions[stateKey];
265
+ if (!stateDefinition) {
266
+ console.warn("State change references an undeclared state \"".concat(stateKey, "\" \u2014 skipping setter emission."));
267
+ return null;
268
+ }
98
269
  var statePrefix = options.dynamicReferencePrefixMap.state
99
270
  ? options.dynamicReferencePrefixMap.state + '.'
100
271
  : '';
101
- var newStateValue = eventHandlerStatement.newState === '$toggle'
102
- ? t.unaryExpression('!', t.identifier(statePrefix + stateKey))
103
- : (0, ast_utils_1.convertValueToLiteral)(eventHandlerStatement.newState, stateDefinition.type);
272
+ // Reading/writing the state through a prefix (`this.class`) is a member
273
+ // access and keeps the UIDL spelling; without one the name IS the binding
274
+ // and has to match what `createStateHookAST` declared.
275
+ var stateReadName = statePrefix
276
+ ? statePrefix + stateKey
277
+ : teleport_shared_1.JSIdentifiers.createSafeJSIdentifier(stateKey);
278
+ var declaredType = stateDefinition.type;
279
+ var newState = eventHandlerStatement.newState;
280
+ var newStateValue;
281
+ var useFunctionalSetter = false;
282
+ var functionalSetterBuilder;
283
+ if (newState === '$toggle') {
284
+ // Boolean-only. Reject for number / object / array — emitting `!x`
285
+ // on those types is the v13/v14 regression we are fixing.
286
+ if (declaredType !== 'boolean') {
287
+ console.warn("[createStateChangeStatement] '$toggle' is only valid for boolean state; state \"".concat(stateKey, "\" is declared as ").concat(declaredType, ". Skipping setter to avoid corrupting state."));
288
+ return null;
289
+ }
290
+ newStateValue = t.unaryExpression('!', t.identifier(stateReadName));
291
+ }
292
+ else if (typeof newState === 'object' && newState !== null) {
293
+ var obj = newState;
294
+ var objType = obj.type;
295
+ if (objType === 'expr') {
296
+ newStateValue = (0, ast_utils_1.getExpressionFromUIDLExpressionNode)(newState);
297
+ }
298
+ else if (objType === 'dynamic') {
299
+ newStateValue = (0, exports.createDynamicValueExpression)(newState, options);
300
+ }
301
+ else if (objType === '$increment' || objType === '$decrement') {
302
+ if (declaredType !== 'number') {
303
+ console.warn("[createStateChangeStatement] '".concat(objType, "' requires a numeric state; \"").concat(stateKey, "\" is declared as ").concat(declaredType, ". Skipping setter."));
304
+ return null;
305
+ }
306
+ // Honor the sign of `delta`: an $increment with delta -2 is a
307
+ // deliberate decrement by 2 (the type doc documents this). The
308
+ // builder emits `prev + delta` for $increment and `prev - delta`
309
+ // for $decrement, then the absolute value of |delta| is the
310
+ // numeric literal we feed in. Math.abs prevents the rare double-
311
+ // negative case where someone writes `{ type: '$decrement', delta: -1 }`
312
+ // (intended +1) from emitting `prev - -1` (which would be `+1`
313
+ // via JS coercion but is unreadable).
314
+ var rawDelta = (_a = obj.delta) !== null && _a !== void 0 ? _a : 1;
315
+ var operator_1 = objType === '$increment' ? (rawDelta < 0 ? '-' : '+') : rawDelta < 0 ? '+' : '-';
316
+ var magnitude_1 = Math.abs(rawDelta);
317
+ useFunctionalSetter = true;
318
+ functionalSetterBuilder = function (prevId) {
319
+ return t.binaryExpression(operator_1, prevId, t.numericLiteral(magnitude_1));
320
+ };
321
+ }
322
+ else if (objType === '$patch') {
323
+ if (declaredType !== 'object') {
324
+ console.warn("[createStateChangeStatement] '$patch' requires an object state; \"".concat(stateKey, "\" is declared as ").concat(declaredType, ". Skipping setter."));
325
+ return null;
326
+ }
327
+ var patch_1 = obj;
328
+ if (!patch_1.path || typeof patch_1.path !== 'string') {
329
+ console.warn("[createStateChangeStatement] '$patch' requires a string \"path\"; received \"".concat(String(patch_1.path), "\" for state \"").concat(stateKey, "\". Skipping setter."));
330
+ return null;
331
+ }
332
+ var patchValueAst_1 = (0, ast_utils_1.convertValueToLiteral)(patch_1.value, 'string');
333
+ useFunctionalSetter = true;
334
+ functionalSetterBuilder = function (prevId) {
335
+ return t.objectExpression([
336
+ t.spreadElement(prevId),
337
+ t.objectProperty(t.identifier(patch_1.path), patchValueAst_1, false, false),
338
+ ]);
339
+ };
340
+ }
341
+ else if (objType === '$append') {
342
+ if (declaredType !== 'array') {
343
+ console.warn("[createStateChangeStatement] '$append' requires an array state; \"".concat(stateKey, "\" is declared as ").concat(declaredType, ". Skipping setter."));
344
+ return null;
345
+ }
346
+ var appended = obj;
347
+ var appendedValueAst_1 = (0, ast_utils_1.convertValueToLiteral)(appended.value, 'string');
348
+ useFunctionalSetter = true;
349
+ functionalSetterBuilder = function (prevId) {
350
+ return t.arrayExpression([t.spreadElement(prevId), appendedValueAst_1]);
351
+ };
352
+ }
353
+ else {
354
+ // Unknown object shape — fall back to literal conversion only when
355
+ // the declared type accepts a primitive write.
356
+ if (declaredType === 'object' || declaredType === 'array') {
357
+ console.warn("[createStateChangeStatement] Unrecognised modifier shape on a ".concat(declaredType, " state \"").concat(stateKey, "\"; skipping setter to avoid corrupting state."));
358
+ return null;
359
+ }
360
+ newStateValue = (0, ast_utils_1.convertValueToLiteral)(newState, declaredType);
361
+ }
362
+ }
363
+ else {
364
+ // Bare primitive (`'oily'`, `2`, `true`). Coerce against the declared type.
365
+ // For object/array state, writing a primitive REPLACES the structure.
366
+ // That is the bug — fail safe.
367
+ if (declaredType === 'object' || declaredType === 'array') {
368
+ console.warn("[createStateChangeStatement] Refusing to overwrite ".concat(declaredType, " state \"").concat(stateKey, "\" with a primitive value (").concat(JSON.stringify(newState), "). Use '$patch' / '$append' modifiers instead. Skipping setter."));
369
+ return null;
370
+ }
371
+ newStateValue = (0, ast_utils_1.convertValueToLiteral)(newState, declaredType);
372
+ }
104
373
  switch (options.stateHandling) {
105
- case 'hooks':
106
- return t.expressionStatement(t.callExpression(t.identifier(teleport_shared_1.StringUtils.createStateStoringFunction(stateKey)), [
107
- newStateValue,
108
- ]));
109
- case 'function':
374
+ case 'hooks': {
375
+ var setterId = t.identifier(teleport_shared_1.StringUtils.createStateStoringFunction(stateKey));
376
+ if (useFunctionalSetter && functionalSetterBuilder) {
377
+ var prevId = t.identifier('prev');
378
+ var arrow = t.arrowFunctionExpression([prevId], functionalSetterBuilder(prevId));
379
+ return t.expressionStatement(t.callExpression(setterId, [arrow]));
380
+ }
381
+ if (!newStateValue) {
382
+ return null;
383
+ }
384
+ return t.expressionStatement(t.callExpression(setterId, [newStateValue]));
385
+ }
386
+ case 'function': {
387
+ // Class-component setState path is legacy; functional setters aren't
388
+ // supported via `this.setState(prev => …)` here, so for the new
389
+ // modifiers we fall back to skipping. The hooks path is the path the
390
+ // multi-step form actually exercises.
391
+ if (useFunctionalSetter) {
392
+ console.warn("[createStateChangeStatement] Functional-setter modifiers are only supported under stateHandling=\"hooks\". Skipping setter for \"".concat(stateKey, "\"."));
393
+ return null;
394
+ }
395
+ if (!newStateValue) {
396
+ return null;
397
+ }
110
398
  return t.expressionStatement(t.callExpression(t.identifier('this.setState'), [
111
399
  t.objectExpression([t.objectProperty(t.identifier(stateKey), newStateValue)]),
112
400
  ]));
401
+ }
113
402
  case 'mutation':
114
- default:
115
- return t.expressionStatement(t.assignmentExpression('=', t.identifier(statePrefix + stateKey), newStateValue));
403
+ default: {
404
+ if (useFunctionalSetter) {
405
+ console.warn("[createStateChangeStatement] Functional-setter modifiers are only supported under stateHandling=\"hooks\". Skipping setter for \"".concat(stateKey, "\"."));
406
+ return null;
407
+ }
408
+ if (!newStateValue) {
409
+ return null;
410
+ }
411
+ return t.expressionStatement(t.assignmentExpression('=', t.identifier(stateReadName), newStateValue));
412
+ }
413
+ }
414
+ };
415
+ exports.createStateChangeStatement = createStateChangeStatement;
416
+ var resolveGlobalStateName = function (id, definitions) {
417
+ if (!definitions) {
418
+ return id;
419
+ }
420
+ for (var _i = 0, _a = Object.values(definitions); _i < _a.length; _i++) {
421
+ var def = _a[_i];
422
+ if (def.id === id) {
423
+ return def.name;
424
+ }
425
+ }
426
+ return id;
427
+ };
428
+ exports.resolveGlobalStateName = resolveGlobalStateName;
429
+ // Matches the leading JS identifier of an expression, e.g. `foo` from
430
+ // `foo?.['bar'] || []`. Used to recognise when a string-encoded UIDL source
431
+ // (cms-list-repeater `source`) is rooted at a global-state name so the
432
+ // generator can register the reference for `useGlobalState()` destructuring.
433
+ var LEADING_IDENTIFIER_RE = /^([A-Za-z_$][A-Za-z0-9_$]*)/;
434
+ // Older versions of the UIDL emitter encoded a global-state reference as the
435
+ // magic literal `globalState_<defId>` instead of the declared variable name.
436
+ // Detect that prefix so we can rewrite it to the proper identifier and fix
437
+ // already-published UIDL documents without forcing them to be regenerated.
438
+ var LEGACY_GLOBAL_STATE_RE = /^globalState_([A-Za-z0-9_-]+)/;
439
+ /**
440
+ * Given a string-encoded UIDL `source` expression, resolve any global-state
441
+ * reference into the proper JS identifier for the generator and ensure the
442
+ * reference is registered for `useGlobalState()` destructuring.
443
+ *
444
+ * Two upstream encodings are accepted:
445
+ * 1. Modern shape — leading identifier is the declared state name
446
+ * (e.g. `countriesWithDescriptions || []`). We just register it.
447
+ * 2. Legacy shape — leading identifier is the magic placeholder
448
+ * `globalState_<defId>` (e.g. `globalState_TQ_96vaRH5pdf['key']`). We
449
+ * rewrite the placeholder to the declared name AND register it.
450
+ *
451
+ * Returns the (possibly rewritten) source string. The caller should embed
452
+ * the returned string instead of the input.
453
+ */
454
+ var resolveAndRegisterGlobalStateSource = function (source, params) {
455
+ var original = source !== null && source !== void 0 ? source : '';
456
+ if (!original) {
457
+ return original;
116
458
  }
459
+ var definitions = params.globalStateDefinitions;
460
+ if (!definitions || Object.keys(definitions).length === 0) {
461
+ return original;
462
+ }
463
+ var legacyMatch = original.match(LEGACY_GLOBAL_STATE_RE);
464
+ if (legacyMatch) {
465
+ var id = legacyMatch[1];
466
+ for (var _i = 0, _a = Object.values(definitions); _i < _a.length; _i++) {
467
+ var def = _a[_i];
468
+ if (def.id === id) {
469
+ params.globalStateReferences.push({ id: def.id, name: def.name });
470
+ // The rewritten source is embedded as code, so the placeholder becomes
471
+ // the LOCAL binding — the sanitised name the destructuring declares.
472
+ return original.replace(LEGACY_GLOBAL_STATE_RE, teleport_shared_1.JSIdentifiers.createSafeJSIdentifier(def.name));
473
+ }
474
+ }
475
+ // Legacy prefix found but no matching definition (orphaned reference).
476
+ // Leave the source untouched; the downstream identifier creation will
477
+ // still emit something, and a separate sanity pass can flag it.
478
+ return original;
479
+ }
480
+ var leadingMatch = original.match(LEADING_IDENTIFIER_RE);
481
+ if (leadingMatch) {
482
+ var leadingName = leadingMatch[1];
483
+ for (var _b = 0, _c = Object.values(definitions); _b < _c.length; _b++) {
484
+ var def = _c[_b];
485
+ if (def.name === leadingName) {
486
+ params.globalStateReferences.push({ id: def.id, name: def.name });
487
+ return original;
488
+ }
489
+ }
490
+ }
491
+ return original;
492
+ };
493
+ exports.resolveAndRegisterGlobalStateSource = resolveAndRegisterGlobalStateSource;
494
+ var createGlobalStateExpression = function (ref, definitions, t) {
495
+ if (t === void 0) { t = types; }
496
+ // The global-state name is destructured out of `useGlobalState()` as a local
497
+ // binding, so it goes through the same sanitiser the destructuring site uses.
498
+ var name = teleport_shared_1.JSIdentifiers.createSafeJSIdentifier((0, exports.resolveGlobalStateName)(ref.content.id, definitions));
499
+ var refPath = ref.content.refPath || [];
500
+ if (refPath.length === 0) {
501
+ return t.identifier(name);
502
+ }
503
+ var expr = t.identifier(name);
504
+ for (var _i = 0, refPath_1 = refPath; _i < refPath_1.length; _i++) {
505
+ var segment = refPath_1[_i];
506
+ expr = t.optionalMemberExpression(expr, t.identifier(segment), false, true);
507
+ }
508
+ return expr;
117
509
  };
510
+ exports.createGlobalStateExpression = createGlobalStateExpression;
118
511
  var createDynamicValueExpression = function (identifier, options, t) {
512
+ var _a;
513
+ if (t === void 0) { t = types; }
514
+ var inner = createDynamicValueExpressionRaw(identifier, options, t);
515
+ // When the UIDL content carries a `valueMapper`, wrap the resolved
516
+ // expression in a sandboxed IIFE that runs the user's `mapValue(value)`
517
+ // and falls back to the raw value on error. This mirrors the state
518
+ // definition `wrapWithMappingFunction` pattern and lets any framework
519
+ // that re-uses `createDynamicValueExpression` inherit the behaviour.
520
+ var valueMapper = ((_a = identifier.content.valueMapper) === null || _a === void 0 ? void 0 : _a.trim()) || '';
521
+ if (!valueMapper) {
522
+ return inner;
523
+ }
524
+ return wrapExpressionWithValueMapperAst(inner, valueMapper, t);
525
+ };
526
+ exports.createDynamicValueExpression = createDynamicValueExpression;
527
+ var wrapExpressionWithValueMapperAst = function (innerExpression, valueMapper, t) {
528
+ if (t === void 0) { t = types; }
529
+ // Build: ((v) => { try { return (new Function('value', '"use strict"; <mapper>; return mapValue(value);')).call(null, v) } catch (_e) { return v } })(<inner>)
530
+ //
531
+ // We deliberately use `new Function(...)` at runtime rather than parsing
532
+ // the mapper body into AST statements here. That keeps this plugin free
533
+ // of a parser dependency, matches the sandboxing used by state-definition
534
+ // `wrapWithMappingFunction`, and ensures the generated code is framework
535
+ // agnostic — only stringify semantics + `toString()` on primitives are
536
+ // required for the output to render correctly.
537
+ var tryBlock = t.tryStatement(t.blockStatement([
538
+ t.returnStatement(t.callExpression(t.memberExpression(t.newExpression(t.identifier('Function'), [
539
+ t.stringLiteral('value'),
540
+ t.stringLiteral("\"use strict\"; ".concat(valueMapper, "; return mapValue(value);")),
541
+ ]), t.identifier('call')), [t.nullLiteral(), t.identifier('v')])),
542
+ ]), t.catchClause(t.identifier('_e'), t.blockStatement([t.returnStatement(t.identifier('v'))])));
543
+ var arrow = t.arrowFunctionExpression([t.identifier('v')], t.blockStatement([tryBlock]));
544
+ return t.callExpression(arrow, [innerExpression]);
545
+ };
546
+ var createDynamicValueExpressionRaw = function (identifier, options, t) {
547
+ var _a;
119
548
  if (t === void 0) { t = types; }
120
549
  var identifierContent = identifier.content;
550
+ var refPath = identifier.content.refPath || [];
121
551
  var referenceType = identifierContent.referenceType, id = identifierContent.id;
122
552
  if (referenceType === 'attr' || referenceType === 'children' || referenceType === 'token') {
123
553
  throw new Error("Dynamic reference type \"".concat(referenceType, "\" is not supported yet"));
124
554
  }
555
+ // 'ctx' references resolve to the data source context render prop identifier
556
+ // using only the refPath to build property access
557
+ if (referenceType === 'ctx') {
558
+ var ctxPrefix = options.dynamicReferencePrefixMap.ctx || '';
559
+ if (ctxPrefix && refPath.length > 0) {
560
+ var expr = t.identifier(ctxPrefix);
561
+ for (var _i = 0, refPath_2 = refPath; _i < refPath_2.length; _i++) {
562
+ var path = refPath_2[_i];
563
+ expr = t.optionalMemberExpression(expr, t.identifier(path), false, true);
564
+ }
565
+ return expr;
566
+ }
567
+ // Details-page fallback: an unresolvable `ctx` reference on a details page
568
+ // (its ctxId points at no known render-prop context — e.g. a synthetic
569
+ // `details-page-generic-*` id produced for a widget's `target`) is still a
570
+ // column on the fetched row exposed as a prop. Resolve it exactly like the
571
+ // `local` branch below → `props.<exposeAs>.<refPath>` (e.g.
572
+ // `props.webinar?.scheduled_at`), so the widget binds the real value.
573
+ if (options.detailsPageExposeAsName && refPath.length > 0) {
574
+ var propPrefix = options.dynamicReferencePrefixMap.prop || 'props';
575
+ var expr = t.memberExpression(t.identifier(propPrefix), t.identifier(options.detailsPageExposeAsName));
576
+ for (var _b = 0, refPath_3 = refPath; _b < refPath_3.length; _b++) {
577
+ var path = refPath_3[_b];
578
+ expr = t.optionalMemberExpression(expr, t.identifier(path), false, true);
579
+ }
580
+ return expr;
581
+ }
582
+ // Last resort: NEVER emit a bare identifier for an unresolved ctx reference —
583
+ // `generateIdWithRefPath(id, …)` yields an UNDECLARED variable (e.g.
584
+ // `tQQGFGA6h4I`), which throws `ReferenceError` during SSR and crashes the
585
+ // Vercel `next build` export (run 1b6eb5ba: `/webinar-detail/[id]`). Emit the
586
+ // reference's declared `fallbackValue` literal, or `undefined`.
587
+ var ctxFallbackValue = identifierContent.fallbackValue;
588
+ if (typeof ctxFallbackValue === 'string' ||
589
+ typeof ctxFallbackValue === 'number' ||
590
+ typeof ctxFallbackValue === 'boolean') {
591
+ return (0, ast_utils_1.convertValueToLiteral)(ctxFallbackValue);
592
+ }
593
+ return t.identifier('undefined');
594
+ }
595
+ // `urlSearchParams` references read a declared key from the URL query string.
596
+ // Next.js generators typically set `dynamicReferencePrefixMap.urlSearchParams`
597
+ // to `'router.query'` so we emit `router.query.<key>`. Static / HTML
598
+ // generators set it to `'__urlSearchParams'` and inject a `const
599
+ // __urlSearchParams = new URLSearchParams(location.search)` prelude.
600
+ //
601
+ // `options.urlSearchParamsRegistry` (set by the plugin based on the page
602
+ // UIDL's `searchParams` definition) supplies per-key defaults so we emit
603
+ // `(router.query.category ?? 'food')` with the declared fallback.
604
+ if (referenceType === 'urlSearchParams') {
605
+ var paramKey = refPath[0] || id;
606
+ var urlParamsPrefix = options.dynamicReferencePrefixMap.urlSearchParams ||
607
+ 'router.query';
608
+ var _c = urlParamsPrefix.split('.'), rootPrefix = _c[0], restPath = _c.slice(1);
609
+ var expr = t.identifier(rootPrefix);
610
+ for (var _d = 0, restPath_1 = restPath; _d < restPath_1.length; _d++) {
611
+ var segment = restPath_1[_d];
612
+ expr = t.memberExpression(expr, t.identifier(segment));
613
+ }
614
+ expr = t.optionalMemberExpression(expr, t.identifier(paramKey), false, true);
615
+ var registry = options.urlSearchParamsRegistry;
616
+ var declaredDefault = (_a = registry === null || registry === void 0 ? void 0 : registry[paramKey]) === null || _a === void 0 ? void 0 : _a.defaultValue;
617
+ if (declaredDefault !== undefined && declaredDefault !== '') {
618
+ expr = t.logicalExpression('??', expr, t.stringLiteral(declaredDefault));
619
+ }
620
+ return expr;
621
+ }
622
+ // 'local' references resolve to the iteration variable of the enclosing repeater.
623
+ // The reference id in UIDL is a node id (e.g. "TQ_xxxxxx") and carries no meaning
624
+ // at runtime — the only load-bearing pieces are the refPath and the current
625
+ // localIdentifier (set when walking into a repeater/data-provider's children).
626
+ if (referenceType === 'local') {
627
+ var localPrefix = options.localIdentifier ||
628
+ options.dynamicReferencePrefixMap.local ||
629
+ '';
630
+ if (localPrefix) {
631
+ if (refPath.length === 0) {
632
+ return t.identifier(localPrefix);
633
+ }
634
+ var expr = t.identifier(localPrefix);
635
+ for (var _e = 0, refPath_4 = refPath; _e < refPath_4.length; _e++) {
636
+ var path = refPath_4[_e];
637
+ expr = t.optionalMemberExpression(expr, t.identifier(path), false, true);
638
+ }
639
+ return expr;
640
+ }
641
+ // Details-page fallback: a page-root `local` reference (no enclosing
642
+ // repeater) means "a column on the fetched row" exposed as a prop under
643
+ // `initialPropsData.exposeAs.name`. Resolve to `props.<name>.<refPath>`.
644
+ if (options.detailsPageExposeAsName && refPath.length > 0) {
645
+ var propPrefix = options.dynamicReferencePrefixMap.prop || 'props';
646
+ var expr = t.memberExpression(t.identifier(propPrefix), t.identifier(options.detailsPageExposeAsName));
647
+ for (var _f = 0, refPath_5 = refPath; _f < refPath_5.length; _f++) {
648
+ var path = refPath_5[_f];
649
+ expr = t.optionalMemberExpression(expr, t.identifier(path), false, true);
650
+ }
651
+ return expr;
652
+ }
653
+ }
654
+ var idWithPath = (0, uidl_utils_1.generateIdWithRefPath)(id, refPath);
125
655
  var prefix = options.dynamicReferencePrefixMap[referenceType] || '';
656
+ // With no prefix the id IS the binding (React hooks: `class`), so it has to
657
+ // be sanitised exactly the way the declaration was. With a prefix it is a
658
+ // MEMBER (`props.class`, `this.class`), where a reserved word is perfectly
659
+ // legal and renaming it would point at a property that does not exist.
126
660
  return prefix === ''
127
- ? t.identifier(id)
128
- : t.memberExpression(t.identifier(prefix), t.identifier(id));
661
+ ? t.identifier(teleport_shared_1.JSIdentifiers.createSafeJSIdentifierPath(idWithPath))
662
+ : t.memberExpression(t.identifier(prefix), t.identifier(idWithPath));
129
663
  };
130
- exports.createDynamicValueExpression = createDynamicValueExpression;
131
664
  // Prepares an identifier (from props or state or an expr) to be used as a conditional rendering identifier
132
665
  // Assumes the type from the corresponding props/state definitions if not expr. Expressions are expected to have a boolean return here
133
666
  var createConditionIdentifier = function (dynamicReference, params, options) {
134
- var _a = dynamicReference.content, id = _a.id, referenceType = _a.referenceType;
667
+ var _a, _b, _c, _d;
668
+ if (dynamicReference.type === 'expr') {
669
+ return {
670
+ key: dynamicReference.content,
671
+ type: 'boolean',
672
+ isExpression: true,
673
+ };
674
+ }
675
+ var _e = dynamicReference.content, id = _e.id, referenceType = _e.referenceType, refPath = _e.refPath;
676
+ // Handle local references (from repeaters/loops) - they don't have an id
677
+ if (referenceType === 'local') {
678
+ // For local references, the identifier comes from the refPath
679
+ var refPathKey = refPath && refPath.length > 0 ? refPath.join('.') : '';
680
+ var prefix = options.localIdentifier || '';
681
+ // Details-page fallback: at the page root there is no enclosing repeater,
682
+ // so a `local` reference means "a column on the fetched row" exposed as a
683
+ // prop under `initialPropsData.exposeAs.name`.
684
+ if (!prefix && options.detailsPageExposeAsName && refPathKey) {
685
+ var propPrefix = ((_a = options.dynamicReferencePrefixMap) === null || _a === void 0 ? void 0 : _a.prop) || 'props';
686
+ return {
687
+ key: "".concat(options.detailsPageExposeAsName, ".").concat(refPathKey),
688
+ type: 'string',
689
+ prefix: propPrefix,
690
+ };
691
+ }
692
+ return {
693
+ key: refPathKey,
694
+ type: 'string',
695
+ prefix: prefix,
696
+ };
697
+ }
698
+ if (referenceType === 'global') {
699
+ return {
700
+ key: teleport_shared_1.UIDLUtils.generateIdWithRefPath(id, refPath),
701
+ type: 'string',
702
+ prefix: '',
703
+ referenceType: 'global',
704
+ };
705
+ }
706
+ if (referenceType === 'globalState') {
707
+ var resolvedName = (0, exports.resolveGlobalStateName)(id, params.globalStateDefinitions);
708
+ var refPathSegments = refPath || [];
709
+ var key = refPathSegments.length > 0
710
+ ? refPathSegments.reduce(function (acc, seg) { return "".concat(acc, "?.").concat(seg); }, resolvedName)
711
+ : resolvedName;
712
+ return {
713
+ key: key,
714
+ type: 'string',
715
+ prefix: '',
716
+ referenceType: 'globalState',
717
+ };
718
+ }
719
+ // A value of the page address's query string, read the way the value path
720
+ // above reads it (`router.query.<key>` in Next, the prelude's object in a
721
+ // static generator) — e.g. a categories overview that steps aside while a
722
+ // search narrows the list.
723
+ if (referenceType === 'urlSearchParams') {
724
+ return {
725
+ key: (refPath === null || refPath === void 0 ? void 0 : refPath[0]) || id,
726
+ type: 'string',
727
+ prefix: options.dynamicReferencePrefixMap.urlSearchParams ||
728
+ 'router.query',
729
+ };
730
+ }
135
731
  // in case the id is a member expression: eg: fields.name
136
732
  var referenceRoot = id.split('.')[0];
733
+ var currentType = referenceType === 'prop'
734
+ ? (_b = params.propDefinitions[referenceRoot]) === null || _b === void 0 ? void 0 : _b.type
735
+ : (_c = params.stateDefinitions[referenceRoot]) === null || _c === void 0 ? void 0 : _c.type;
736
+ var type = currentType;
737
+ if (refPath === null || refPath === void 0 ? void 0 : refPath.length) {
738
+ if (referenceType === 'prop' && ((_d = params.propDefinitions[referenceRoot]) === null || _d === void 0 ? void 0 : _d.defaultValue)) {
739
+ var currentValue = params.propDefinitions[referenceRoot].defaultValue;
740
+ for (var _i = 0, refPath_6 = refPath; _i < refPath_6.length; _i++) {
741
+ var path = refPath_6[_i];
742
+ currentValue = currentValue === null || currentValue === void 0 ? void 0 : currentValue[path];
743
+ type = currentValue ? typeof currentValue : currentType;
744
+ }
745
+ }
746
+ else if (referenceType === 'state' && currentType === 'object') {
747
+ var stateDef = params.stateDefinitions[referenceRoot];
748
+ if (stateDef &&
749
+ typeof stateDef.defaultValue === 'object' &&
750
+ stateDef.defaultValue !== null &&
751
+ !Array.isArray(stateDef.defaultValue)) {
752
+ var objectDefault = stateDef.defaultValue;
753
+ var entry = objectDefault[refPath[0]];
754
+ if ((entry === null || entry === void 0 ? void 0 : entry.type) === 'static' && entry.content !== undefined) {
755
+ type = typeof entry.content;
756
+ }
757
+ else {
758
+ type = 'string';
759
+ }
760
+ }
761
+ }
762
+ }
137
763
  switch (referenceType) {
138
764
  case 'prop':
139
765
  return {
140
- key: id,
141
- type: params.propDefinitions[referenceRoot].type,
766
+ key: teleport_shared_1.UIDLUtils.generateIdWithRefPath(id, refPath),
767
+ type: type,
142
768
  prefix: options.dynamicReferencePrefixMap.prop,
143
769
  };
144
770
  case 'state':
145
771
  return {
146
- key: id,
147
- type: params.stateDefinitions[referenceRoot].type,
772
+ key: teleport_shared_1.UIDLUtils.generateIdWithRefPath(id, refPath),
773
+ type: type,
148
774
  prefix: options.dynamicReferencePrefixMap.state,
149
775
  };
150
776
  case 'expr':
151
777
  return {
152
778
  key: id,
153
779
  type: 'boolean',
780
+ isExpression: true,
154
781
  };
155
782
  default:
156
783
  throw new Error("createConditionIdentifier encountered an invalid reference type: ".concat(JSON.stringify(dynamicReference, null, 2)));
157
784
  }
158
785
  };
159
786
  exports.createConditionIdentifier = createConditionIdentifier;
160
- var createConditionalJSXExpression = function (content, conditionalExpression, conditionalIdentifier, t) {
787
+ var createConditionalJSXExpression = function (content, conditionalExpression, conditionalIdentifier, options, t) {
788
+ if (options === void 0) { options = {}; }
161
789
  if (t === void 0) { t = types; }
162
790
  var contentNode;
163
791
  if (typeof content === 'string') {
@@ -169,35 +797,219 @@ var createConditionalJSXExpression = function (content, conditionalExpression, c
169
797
  else {
170
798
  contentNode = content;
171
799
  }
172
- var binaryExpression;
173
- // When the stateValue is an object we will compute a logical/binary expression on the left side
174
- var conditions = conditionalExpression.conditions, matchingCriteria = conditionalExpression.matchingCriteria;
175
- var binaryExpressions = conditions.map(function (condition) {
176
- return (0, exports.createBinaryExpression)(condition, conditionalIdentifier);
800
+ var binaryExpression = createConditionChainExpression(conditionalExpression, conditionalIdentifier, options, t);
801
+ return t.logicalExpression('&&', binaryExpression, contentNode);
802
+ };
803
+ exports.createConditionalJSXExpression = createConditionalJSXExpression;
804
+ // Folds a (possibly nested) conditions chain into one expression. Group
805
+ // entries recurse with their own matchingCriteria — the AST nesting is what
806
+ // the printer emits as parentheses.
807
+ var createConditionChainExpression = function (chain, conditionalIdentifier, options, t) {
808
+ if (t === void 0) { t = types; }
809
+ var conditions = chain.conditions, matchingCriteria = chain.matchingCriteria;
810
+ var entryExpressions = conditions.map(function (entry) {
811
+ var _a, _b;
812
+ return teleport_shared_1.UIDLUtils.isUIDLConditionGroup(entry)
813
+ ? createConditionChainExpression(entry, conditionalIdentifier, options, t)
814
+ : (0, exports.createBinaryExpression)(entry, (_b = (_a = options.resolveEntryIdentifier) === null || _a === void 0 ? void 0 : _a.call(options, entry)) !== null && _b !== void 0 ? _b : conditionalIdentifier, options);
177
815
  });
178
- if (binaryExpressions.length === 1) {
179
- binaryExpression = binaryExpressions[0];
816
+ if (entryExpressions.length === 0) {
817
+ // An empty group cannot gate anything; degrade to a pass-through.
818
+ return t.booleanLiteral(true);
180
819
  }
181
- else {
182
- // the first two binary expressions are put together as a logical expression
183
- var firstExp = binaryExpressions[0], secondExp = binaryExpressions[1];
184
- var operation = matchingCriteria === 'all' ? '&&' : '||';
185
- var expression = t.logicalExpression(operation, firstExp, secondExp);
186
- // accumulate the rest of the expressions to the logical expression
187
- for (var index = 2; index < binaryExpressions.length; index++) {
188
- expression = t.logicalExpression(operation, expression, binaryExpressions[index]);
820
+ if (entryExpressions.length === 1) {
821
+ return entryExpressions[0];
822
+ }
823
+ // the first two expressions are put together as a logical expression
824
+ var operation = matchingCriteria === 'all' ? '&&' : '||';
825
+ var expression = t.logicalExpression(operation, entryExpressions[0], entryExpressions[1]);
826
+ // accumulate the rest of the expressions to the logical expression
827
+ for (var index = 2; index < entryExpressions.length; index++) {
828
+ expression = t.logicalExpression(operation, expression, entryExpressions[index]);
829
+ }
830
+ return expression;
831
+ };
832
+ /**
833
+ * The test a conditionally-bound class applies under: every rule of its chain,
834
+ * joined by the chain's matchingCriteria, or the single `value` it equals. A
835
+ * condition with neither can never hold, so there is no test and the caller
836
+ * leaves the class off.
837
+ */
838
+ var createClassConditionExpression = function (condition, conditionalIdentifier) {
839
+ var _a, _b;
840
+ if ((_b = (_a = condition.expression) === null || _a === void 0 ? void 0 : _a.conditions) === null || _b === void 0 ? void 0 : _b.length) {
841
+ return createConditionChainExpression(condition.expression, conditionalIdentifier, {});
842
+ }
843
+ if (condition.value !== undefined) {
844
+ return (0, exports.createBinaryExpression)({ operation: '===', operand: condition.value }, conditionalIdentifier);
845
+ }
846
+ return null;
847
+ };
848
+ exports.createClassConditionExpression = createClassConditionExpression;
849
+ /**
850
+ * Resolves an operand value to an AST expression, handling dynamic refs, expressions, and static values.
851
+ */
852
+ var resolveOperandExpression = function (operand, conditionalIdentifier, options) {
853
+ if (typeof operand === 'object' && 'type' in operand && operand.type === 'expr') {
854
+ return (0, ast_utils_1.getExpressionFromUIDLExpressionNode)(operand);
855
+ }
856
+ if (typeof operand === 'object' && 'type' in operand && operand.type === 'dynamic') {
857
+ return (0, exports.createDynamicValueExpression)(operand, {
858
+ dynamicReferencePrefixMap: {
859
+ prop: 'props',
860
+ state: '',
861
+ local: '',
862
+ },
863
+ localIdentifier: options.localIdentifier,
864
+ detailsPageExposeAsName: options.detailsPageExposeAsName,
865
+ });
866
+ }
867
+ return (0, ast_utils_1.convertValueToLiteral)(operand, conditionalIdentifier.type);
868
+ };
869
+ /**
870
+ * `resolveOperandExpression` for an operand that is ONE ELEMENT of the bound
871
+ * collection (`contains` / `notContains`), not a value of the collection's own
872
+ * type.
873
+ *
874
+ * The typed resolver parses a static operand as the identifier's type, which
875
+ * for an array-typed state means `JSON.parse`: the string `"5"` came out as the
876
+ * number `5`, `"true"` as `true`. The rows an array state actually holds are
877
+ * whatever a workflow pushed — strings, read off `data-*` attributes — so
878
+ * `selectedRatings.includes(5)` never matched `["5"]` and a ticked rating
879
+ * checkbox stayed empty. The literal keeps the type it was authored with, which
880
+ * is also how the editor's canvas evaluates the same condition.
881
+ */
882
+ var resolveElementOperandExpression = function (operand, conditionalIdentifier, options) {
883
+ return resolveOperandExpression(operand, __assign(__assign({}, conditionalIdentifier), { type: '' }), options);
884
+ };
885
+ /**
886
+ * Coerce a conditional identifier to an empty collection when it is null or
887
+ * undefined, so the collection operators below can dereference it safely.
888
+ *
889
+ * The bound value is absent far more often than it looks: an optional CMS
890
+ * column, a category without an image, a state that has not hydrated yet. A
891
+ * bare `x.length` / `x.includes(...)` then throws `Cannot read properties of
892
+ * null` during render and takes the whole page down with an unhandled runtime
893
+ * error — a condition whose entire job is to HIDE a node must never be able to
894
+ * do that. `x || []` keeps string semantics intact (a non-empty string is
895
+ * truthy and carries both `.length` and `.includes`) while turning nullish
896
+ * values into a harmless empty collection; objects get `{}` for `Object.keys`
897
+ * / `hasOwnProperty`, which reject `null` outright.
898
+ */
899
+ var createNullSafeCollection = function (identifier, conditionalIdentifier, t) {
900
+ if (t === void 0) { t = types; }
901
+ return t.logicalExpression('||', identifier, conditionalIdentifier.type === 'object' ? t.objectExpression([]) : t.arrayExpression([]));
902
+ };
903
+ /** `x.length` — via `Object.keys(x).length` for objects — on a nullish-safe target. */
904
+ var createLengthExpression = function (identifier, conditionalIdentifier, t) {
905
+ if (t === void 0) { t = types; }
906
+ var target = createNullSafeCollection(identifier, conditionalIdentifier, t);
907
+ return conditionalIdentifier.type === 'object'
908
+ ? t.memberExpression(t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('keys')), [
909
+ target,
910
+ ]), t.identifier('length'))
911
+ : t.memberExpression(target, t.identifier('length'));
912
+ };
913
+ /**
914
+ * A UIDL `expr` reference whose whole body is a JavaScript LITERAL.
915
+ *
916
+ * `expr` content is source, not a name, so it must never reach the reserved
917
+ * word sanitiser: the domain-to-UIDL mapper emits the literal `false` as its
918
+ * "this condition could not be resolved" fallback (an orphaned state/prop
919
+ * reference), and `t.identifier(createSafeJSIdentifierPath('false'))` prints
920
+ * `false_` — an undefined binding that throws
921
+ * `ReferenceError: false_ is not defined` while the page is rendering, taking
922
+ * the whole page down instead of quietly rendering nothing.
923
+ *
924
+ * Only complete literals are matched. Anything else (`chatMessage?.sender`,
925
+ * `props.product?.slug`) keeps the historical verbatim-identifier printing,
926
+ * including the sanitiser pass that a state genuinely named `class` relies on.
927
+ */
928
+ var NUMERIC_LITERAL_RE = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/;
929
+ var createJSLiteralExpression = function (source, t) {
930
+ if (t === void 0) { t = types; }
931
+ switch (source) {
932
+ case 'true':
933
+ return t.booleanLiteral(true);
934
+ case 'false':
935
+ return t.booleanLiteral(false);
936
+ case 'null':
937
+ return t.nullLiteral();
938
+ case 'undefined':
939
+ return t.identifier('undefined');
940
+ default:
941
+ return NUMERIC_LITERAL_RE.test(source) ? t.numericLiteral(Number(source)) : null;
942
+ }
943
+ };
944
+ /** The left-hand side of one condition, as an AST node. */
945
+ var createConditionalIdentifierExpression = function (conditionalIdentifier, t) {
946
+ if (t === void 0) { t = types; }
947
+ // Same rule as `createDynamicValueExpression`: an un-prefixed key is the
948
+ // binding itself and must be identifier-safe; a prefixed one is a member
949
+ // access that has to keep the UIDL's original spelling.
950
+ if (conditionalIdentifier.prefix) {
951
+ return t.memberExpression(t.identifier(conditionalIdentifier.prefix), t.identifier(conditionalIdentifier.key));
952
+ }
953
+ if (conditionalIdentifier.isExpression) {
954
+ var literal = createJSLiteralExpression(conditionalIdentifier.key, t);
955
+ if (literal) {
956
+ return literal;
189
957
  }
190
- binaryExpression = expression;
191
958
  }
192
- return t.logicalExpression('&&', binaryExpression, contentNode);
959
+ return t.identifier(teleport_shared_1.JSIdentifiers.createSafeJSIdentifierPath(conditionalIdentifier.key));
193
960
  };
194
- exports.createConditionalJSXExpression = createConditionalJSXExpression;
195
- var createBinaryExpression = function (condition, conditionalIdentifier, t) {
961
+ var createBinaryExpression = function (condition, conditionalIdentifier, options, t) {
962
+ if (options === void 0) { options = {}; }
196
963
  if (t === void 0) { t = types; }
197
- var operand = condition.operand, operation = condition.operation;
198
- var identifier = conditionalIdentifier.prefix
199
- ? t.memberExpression(t.identifier(conditionalIdentifier.prefix), t.identifier(conditionalIdentifier.key))
200
- : t.identifier(conditionalIdentifier.key);
964
+ var operand = condition.operand, operation = condition.operation, containsField = condition.containsField;
965
+ var identifier = createConditionalIdentifierExpression(conditionalIdentifier, t);
966
+ // Array/Object operators
967
+ if (operation === 'isEmpty') {
968
+ return t.binaryExpression('===', createLengthExpression(identifier, conditionalIdentifier, t), t.numericLiteral(0));
969
+ }
970
+ if (operation === 'isNotEmpty') {
971
+ return t.binaryExpression('>', createLengthExpression(identifier, conditionalIdentifier, t), t.numericLiteral(0));
972
+ }
973
+ if (operation === 'lengthEquals' && operand !== undefined) {
974
+ return t.binaryExpression('===', createLengthExpression(identifier, conditionalIdentifier, t), resolveOperandExpression(operand, conditionalIdentifier, options));
975
+ }
976
+ if (operation === 'lengthGreaterThan' && operand !== undefined) {
977
+ return t.binaryExpression('>', createLengthExpression(identifier, conditionalIdentifier, t), resolveOperandExpression(operand, conditionalIdentifier, options));
978
+ }
979
+ if (operation === 'lengthLessThan' && operand !== undefined) {
980
+ return t.binaryExpression('<', createLengthExpression(identifier, conditionalIdentifier, t), resolveOperandExpression(operand, conditionalIdentifier, options));
981
+ }
982
+ if (operation === 'contains' && operand !== undefined) {
983
+ var operandExpr = resolveElementOperandExpression(operand, conditionalIdentifier, options);
984
+ var target = createNullSafeCollection(identifier, conditionalIdentifier, t);
985
+ if (containsField) {
986
+ var itemParam = t.identifier('__item');
987
+ return t.callExpression(t.memberExpression(target, t.identifier('some')), [
988
+ t.arrowFunctionExpression([itemParam], t.binaryExpression('===', t.memberExpression(itemParam, t.identifier(containsField)), operandExpr)),
989
+ ]);
990
+ }
991
+ return t.callExpression(t.memberExpression(target, t.identifier('includes')), [operandExpr]);
992
+ }
993
+ if (operation === 'notContains' && operand !== undefined) {
994
+ var operandExpr = resolveElementOperandExpression(operand, conditionalIdentifier, options);
995
+ var target = createNullSafeCollection(identifier, conditionalIdentifier, t);
996
+ if (containsField) {
997
+ var itemParam = t.identifier('__item');
998
+ return t.unaryExpression('!', t.callExpression(t.memberExpression(target, t.identifier('some')), [
999
+ t.arrowFunctionExpression([itemParam], t.binaryExpression('===', t.memberExpression(itemParam, t.identifier(containsField)), operandExpr)),
1000
+ ]));
1001
+ }
1002
+ return t.unaryExpression('!', t.callExpression(t.memberExpression(target, t.identifier('includes')), [operandExpr]));
1003
+ }
1004
+ if (operation === 'hasKey' && operand !== undefined) {
1005
+ var operandExpr = resolveOperandExpression(operand, conditionalIdentifier, options);
1006
+ return t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier('Object'), t.identifier('prototype')), t.identifier('hasOwnProperty')), t.identifier('call')), [createNullSafeCollection(identifier, conditionalIdentifier, t), operandExpr]);
1007
+ }
1008
+ if (operation === 'notHasKey' && operand !== undefined) {
1009
+ var operandExpr = resolveOperandExpression(operand, conditionalIdentifier, options);
1010
+ return t.unaryExpression('!', t.callExpression(t.memberExpression(t.memberExpression(t.memberExpression(t.identifier('Object'), t.identifier('prototype')), t.identifier('hasOwnProperty')), t.identifier('call')), [createNullSafeCollection(identifier, conditionalIdentifier, t), operandExpr]));
1011
+ }
1012
+ // Standard binary operators
201
1013
  if (operation === '===') {
202
1014
  if (operand === true) {
203
1015
  return identifier;
@@ -207,36 +1019,35 @@ var createBinaryExpression = function (condition, conditionalIdentifier, t) {
207
1019
  }
208
1020
  }
209
1021
  if (operand !== undefined) {
210
- var stateValueIdentifier = (0, ast_utils_1.convertValueToLiteral)(operand, conditionalIdentifier.type);
211
- return t.binaryExpression(convertToBinaryOperator(operation), identifier, stateValueIdentifier);
1022
+ if (typeof operand === 'object' && 'type' in operand && operand.type === 'expr') {
1023
+ var exprIdentifier = (0, ast_utils_1.getExpressionFromUIDLExpressionNode)(operand);
1024
+ return t.binaryExpression((0, ast_utils_1.convertToBinaryOperator)(operation), identifier, exprIdentifier);
1025
+ }
1026
+ if (typeof operand === 'object' && 'type' in operand && operand.type === 'dynamic') {
1027
+ var dynamicValueIdentifier = (0, exports.createDynamicValueExpression)(operand, {
1028
+ dynamicReferencePrefixMap: {
1029
+ prop: 'props',
1030
+ state: '',
1031
+ local: '',
1032
+ },
1033
+ localIdentifier: options.localIdentifier,
1034
+ });
1035
+ return t.binaryExpression((0, ast_utils_1.convertToBinaryOperator)(operation), identifier, dynamicValueIdentifier);
1036
+ }
1037
+ // An expression's type is a placeholder, not the type of its value.
1038
+ var stateValueIdentifier = (0, ast_utils_1.convertValueToLiteral)((0, ast_utils_1.coerceToDeclaredType)(operand, conditionalIdentifier.isExpression ? undefined : conditionalIdentifier.type), conditionalIdentifier.type);
1039
+ var lhs = (conditionalIdentifier.referenceType === 'global' ||
1040
+ conditionalIdentifier.referenceType === 'globalState') &&
1041
+ typeof operand === 'string'
1042
+ ? t.optionalCallExpression(t.optionalMemberExpression(identifier, t.identifier('toString'), false, true), [], false)
1043
+ : identifier;
1044
+ return t.binaryExpression((0, ast_utils_1.convertToBinaryOperator)(operation), lhs, stateValueIdentifier);
212
1045
  }
213
1046
  else {
214
- return operation ? t.unaryExpression(convertToUnaryOperator(operation), identifier) : identifier;
1047
+ return operation ? t.unaryExpression((0, ast_utils_1.convertToUnaryOperator)(operation), identifier) : identifier;
215
1048
  }
216
1049
  };
217
1050
  exports.createBinaryExpression = createBinaryExpression;
218
- /**
219
- * Because of the restrictions of the AST Types we need to have a clear subset of binary operators we can use
220
- * @param operation - the operation defined in the UIDL for the current state branch
221
- */
222
- var convertToBinaryOperator = function (operation) {
223
- var allowedOperations = ['===', '!==', '>=', '<=', '>', '<'];
224
- if (allowedOperations.includes(operation)) {
225
- return operation;
226
- }
227
- else {
228
- return '===';
229
- }
230
- };
231
- var convertToUnaryOperator = function (operation) {
232
- var allowedOperations = ['!'];
233
- if (allowedOperations.includes(operation)) {
234
- return operation;
235
- }
236
- else {
237
- return '!';
238
- }
239
- };
240
1051
  var getRepeatSourceIdentifier = function (dataSource, options) {
241
1052
  switch (dataSource.type) {
242
1053
  case 'static':