juxscript 1.1.284 → 1.1.286

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.
@@ -144,16 +144,35 @@ export function autowrap(source, filename = '') {
144
144
  // Check if the body has multiple independent reactive groups
145
145
  const groups = groupBodyStatements(bodyStmts, source);
146
146
  if (groups.length > 1) {
147
- // Replace single watch with multiple watches
148
- // Record the original watch range for removal
149
- const watchStart = getLineNumber(source, stmt.start);
150
- const watchEnd = getLineNumber(source, stmt.end);
151
- needsWatch.push({
152
- line: watchStart,
153
- endLine: watchEnd,
154
- replace: true,
155
- groups: groups,
156
- });
147
+ // Verify no cross-group variable dependencies before splitting
148
+ const allDeclared = [];
149
+ let hasCrossDep = false;
150
+ for (const group of groups) {
151
+ const groupVars = [];
152
+ for (const s of group.stmts) {
153
+ groupVars.push(...getDeclaredVarNames(s));
154
+ }
155
+ // Check if this group uses vars declared in a previous group
156
+ for (const s of group.stmts) {
157
+ if (allDeclared.some(v => usesIdentifier(s, v))) {
158
+ hasCrossDep = true;
159
+ break;
160
+ }
161
+ }
162
+ if (hasCrossDep) break;
163
+ allDeclared.push(...groupVars);
164
+ }
165
+
166
+ if (!hasCrossDep) {
167
+ const watchStart = getLineNumber(source, stmt.start);
168
+ const watchEnd = getLineNumber(source, stmt.end);
169
+ needsWatch.push({
170
+ line: watchStart,
171
+ endLine: watchEnd,
172
+ replace: true,
173
+ groups: groups,
174
+ });
175
+ }
157
176
  }
158
177
  }
159
178
  i++;
@@ -268,8 +287,11 @@ function groupBodyStatements(bodyStmts, source) {
268
287
 
269
288
  while (j < bodyStmts.length) {
270
289
  const next = bodyStmts[j];
271
- if (varNames.some(v => usesIdentifier(next, v))) {
290
+ // Also collect any new variable names declared within grouped statements
291
+ if (varNames.some(v => usesIdentifier(next, v)) || !containsPageStateRef(next)) {
272
292
  groupStmts.push(next);
293
+ // Track any new variable declarations in the consumed statement
294
+ getDeclaredVarNames(next).forEach(v => varNames.push(v));
273
295
  j++;
274
296
  } else {
275
297
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.284",
3
+ "version": "1.1.286",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "./dist/lib/index.js",