@danielx/civet 0.6.88 → 0.6.90
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/dist/browser.js +149 -87
- package/dist/civet +18 -7
- package/dist/main.js +149 -87
- package/dist/main.mjs +149 -87
- package/dist/types.d.ts +6 -1
- package/package.json +1 -1
package/dist/civet
CHANGED
|
@@ -344,11 +344,7 @@ async function repl(options) {
|
|
|
344
344
|
return callback(null, output);
|
|
345
345
|
}
|
|
346
346
|
let ast = (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
347
|
-
const topLevelAwait = import_main.lib.
|
|
348
|
-
ast,
|
|
349
|
-
($) => $.type === "Await",
|
|
350
|
-
import_main.lib.isFunction
|
|
351
|
-
).length > 0;
|
|
347
|
+
const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
|
|
352
348
|
if (topLevelAwait) {
|
|
353
349
|
const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
|
|
354
350
|
const prefix = input.slice(0, -rest.length);
|
|
@@ -357,6 +353,15 @@ async function repl(options) {
|
|
|
357
353
|
prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
|
|
358
354
|
{ ...options, filename, ast: true }
|
|
359
355
|
);
|
|
356
|
+
import_main.lib.gatherRecursive(ast, ($) => $.type === "BlockStatement").forEach((topBlock) => {
|
|
357
|
+
return import_main.lib.gatherRecursiveWithinFunction(topBlock, ($1) => $1.type === "Declaration").forEach((decl) => {
|
|
358
|
+
const type = decl.children.shift();
|
|
359
|
+
if (!Array.isArray(ast)) {
|
|
360
|
+
ast = [ast];
|
|
361
|
+
}
|
|
362
|
+
return ast.unshift(`var ${decl.names.join(",")};`);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
360
365
|
}
|
|
361
366
|
const errors = [];
|
|
362
367
|
try {
|
|
@@ -366,7 +371,7 @@ async function repl(options) {
|
|
|
366
371
|
return callback(null, void 0);
|
|
367
372
|
}
|
|
368
373
|
if (errors.length) {
|
|
369
|
-
console.error(`Parse errors: ${errors.map(($
|
|
374
|
+
console.error(`Parse errors: ${errors.map(($2) => $2.message).join("\n")}`);
|
|
370
375
|
return callback(null, void 0);
|
|
371
376
|
}
|
|
372
377
|
let result;
|
|
@@ -379,12 +384,18 @@ async function repl(options) {
|
|
|
379
384
|
return callback(error, void 0);
|
|
380
385
|
}
|
|
381
386
|
if (topLevelAwait) {
|
|
387
|
+
let threw = false;
|
|
382
388
|
try {
|
|
383
389
|
result = await result;
|
|
384
390
|
} catch (error) {
|
|
391
|
+
threw = true;
|
|
385
392
|
callback(error, void 0);
|
|
386
393
|
}
|
|
387
|
-
|
|
394
|
+
if (!threw) {
|
|
395
|
+
return callback(null, result);
|
|
396
|
+
}
|
|
397
|
+
;
|
|
398
|
+
return;
|
|
388
399
|
} else {
|
|
389
400
|
return callback(null, result);
|
|
390
401
|
}
|