juxscript 1.1.288 → 1.1.289
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 +19 -2
- package/package.json +1 -1
package/machinery/autowrap.js
CHANGED
|
@@ -110,6 +110,14 @@ function getLineNumber(source, pos) {
|
|
|
110
110
|
return line;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
function containsAwait(node) {
|
|
114
|
+
let found = false;
|
|
115
|
+
walkSimple(node, {
|
|
116
|
+
AwaitExpression() { found = true; }
|
|
117
|
+
});
|
|
118
|
+
return found;
|
|
119
|
+
}
|
|
120
|
+
|
|
113
121
|
/**
|
|
114
122
|
* @param {string} source - Raw .jux source code
|
|
115
123
|
* @param {string} [filename] - For logging
|
|
@@ -236,7 +244,8 @@ export function autowrap(source, filename = '') {
|
|
|
236
244
|
const indent = lines[startIdx].match(/^(\s*)/)[1];
|
|
237
245
|
const newLines = [];
|
|
238
246
|
for (const group of item.groups) {
|
|
239
|
-
|
|
247
|
+
const needsAsync = group.stmts && group.stmts.some(s => containsAwait(s));
|
|
248
|
+
newLines.push(`${indent}pageState.__watch(${needsAsync ? 'async ' : ''}() => {`);
|
|
240
249
|
for (const gLine of group.lines) {
|
|
241
250
|
newLines.push(`${indent} ${gLine.trim()}`);
|
|
242
251
|
}
|
|
@@ -248,8 +257,16 @@ export function autowrap(source, filename = '') {
|
|
|
248
257
|
const blockLines = lines.slice(startIdx, endIdx + 1);
|
|
249
258
|
const indent = blockLines[0].match(/^(\s*)/)[1];
|
|
250
259
|
|
|
260
|
+
// Check if any of the original AST statements in this range contain await
|
|
261
|
+
const stmtsInRange = ast.body.filter(s => {
|
|
262
|
+
const sLine = getLineNumber(source, s.start);
|
|
263
|
+
const eLine = getLineNumber(source, s.end);
|
|
264
|
+
return sLine >= item.line && eLine <= item.endLine;
|
|
265
|
+
});
|
|
266
|
+
const needsAsync = stmtsInRange.some(s => containsAwait(s));
|
|
267
|
+
|
|
251
268
|
const wrapped = [
|
|
252
|
-
`${indent}pageState.__watch(() => {`,
|
|
269
|
+
`${indent}pageState.__watch(${needsAsync ? 'async ' : ''}() => {`,
|
|
253
270
|
...blockLines.map(l => `${indent} ${l.trim()}`),
|
|
254
271
|
`${indent}});`,
|
|
255
272
|
];
|