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.
- package/machinery/autowrap.js +33 -11
- package/package.json +1 -1
package/machinery/autowrap.js
CHANGED
|
@@ -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
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
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;
|