juxscript 1.1.277 → 1.1.279
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 +12 -9
- package/package.json +1 -1
package/machinery/autowrap.js
CHANGED
|
@@ -81,8 +81,8 @@ function isSetupStatement(stmt) {
|
|
|
81
81
|
expr.argument?.callee?.object?.name === 'jux' &&
|
|
82
82
|
!containsPageStateRef(stmt)) return true;
|
|
83
83
|
}
|
|
84
|
-
if (stmt.type === 'VariableDeclaration' && !containsPageStateRef(stmt)) return true;
|
|
85
|
-
if (stmt.type === 'VariableDeclaration' && containsJuxCall(stmt)) return true;
|
|
84
|
+
if (stmt.type === 'VariableDeclaration' && !containsPageStateRef(stmt) && !containsJuxCall(stmt)) return true;
|
|
85
|
+
if (stmt.type === 'VariableDeclaration' && containsJuxCall(stmt) && !containsPageStateRef(stmt)) return true;
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -121,26 +121,29 @@ export function autowrap(source, filename = '') {
|
|
|
121
121
|
if (isSetupStatement(stmt)) { i++; continue; }
|
|
122
122
|
if (isAlreadyWrapped(stmt)) { i++; continue; }
|
|
123
123
|
|
|
124
|
-
// VariableDeclaration reading pageState — group with
|
|
124
|
+
// VariableDeclaration reading pageState — group with subsequent stmts that use declared vars
|
|
125
125
|
if (stmt.type === 'VariableDeclaration' && containsPageStateRef(stmt)) {
|
|
126
126
|
const varNames = getDeclaredVarNames(stmt);
|
|
127
127
|
const groupStmts = [stmt];
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
let j = i + 1;
|
|
129
|
+
|
|
130
|
+
// Greedily consume following statements that use any of the declared variable names
|
|
131
|
+
while (j < ast.body.length) {
|
|
132
|
+
const next = ast.body[j];
|
|
133
|
+
if (isAlreadyWrapped(next) || isSetupStatement(next)) break;
|
|
130
134
|
if (varNames.some(v => usesIdentifier(next, v))) {
|
|
131
135
|
groupStmts.push(next);
|
|
132
|
-
|
|
136
|
+
j++;
|
|
133
137
|
} else {
|
|
134
|
-
|
|
138
|
+
break;
|
|
135
139
|
}
|
|
136
|
-
} else {
|
|
137
|
-
i++;
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
needsWatch.push({
|
|
141
143
|
line: getLineNumber(source, groupStmts[0].start),
|
|
142
144
|
endLine: getLineNumber(source, groupStmts[groupStmts.length - 1].end),
|
|
143
145
|
});
|
|
146
|
+
i = j;
|
|
144
147
|
continue;
|
|
145
148
|
}
|
|
146
149
|
|