@danielx/civet 0.7.36 → 0.8.1

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/civet CHANGED
@@ -419,26 +419,35 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
419
419
  prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
420
420
  { ...options, filename, ast: true }
421
421
  );
422
- import_main.lib.gatherRecursive(ast, ($) => $.type === "BlockStatement").forEach((topBlock) => {
423
- return import_main.lib.gatherRecursiveWithinFunction(topBlock, ($1) => $1.type === "Declaration").forEach((decl) => {
424
- const type = decl.children.shift();
422
+ let ref1;
423
+ if (coffee) {
424
+ ref1 = import_main.lib.gatherRecursive(ast.children, ($) => $.type === "BlockStatement")[0];
425
+ } else {
426
+ ref1 = import_main.lib.gatherRecursive(ast.children, ($1) => $1.type === "DoStatement")[0].block;
427
+ }
428
+ ;
429
+ const topBlock = ref1;
430
+ for (let ref2 = topBlock.expressions, i3 = 0, len2 = ref2.length; i3 < len2; i3++) {
431
+ const [, statement] = ref2[i3];
432
+ if (typeof statement === "object" && statement != null && "type" in statement && statement.type === "Declaration") {
433
+ statement.children.shift();
425
434
  if (!Array.isArray(ast)) {
426
435
  ast = [ast];
427
436
  }
428
- return ast.unshift(`var ${decl.names.join(",")};`);
429
- });
430
- });
437
+ ast.unshift(`var ${statement.names.join(",")};`);
438
+ }
439
+ }
431
440
  }
432
441
  let errors = [];
433
442
  try {
434
- output = (0, import_main.generate)(ast, { errors });
443
+ output = (0, import_main.generate)(ast, { ...options, errors, sourceMap: void 0 });
435
444
  } catch (error) {
436
445
  console.error(error);
437
446
  return callback(null, void 0);
438
447
  }
439
448
  if (errors.length) {
440
449
  errors = [];
441
- (0, import_main.generate)(ast, { errors, sourceMap: (0, import_main.SourceMap)(input) });
450
+ (0, import_main.generate)(ast, { ...options, errors, sourceMap: (0, import_main.SourceMap)(input) });
442
451
  showError2(errors[0]);
443
452
  return callback(null, void 0);
444
453
  }
@@ -546,7 +555,8 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
546
555
  const unpluginOptions = {
547
556
  ...options,
548
557
  ts: options.js ? "civet" : "preserve",
549
- outputExtension: ".tsx"
558
+ outputExtension: ".tsx",
559
+ declarationExtension: options.outputExt?.replace(/\.[jt]sx?$/i, ".d.ts")
550
560
  };
551
561
  (unpluginOptions.parseOptions ??= {}).rewriteCivetImports = ".civet.jsx";
552
562
  unplugin = (0, import_unplugin.rawPlugin)(unpluginOptions, { framework: "civet-cli" });
@@ -559,8 +569,16 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
559
569
  if (options.repl) {
560
570
  return repl(args, options);
561
571
  }
572
+ process.stdout.on("error", (e) => {
573
+ if (["EPIPE", "EOF"].includes(e.code)) {
574
+ return process.exit(0);
575
+ } else {
576
+ console.error(e);
577
+ return process.exit(1);
578
+ }
579
+ });
562
580
  let errors = 0;
563
- for await (const { filename, error, content, stdin } of readFiles(filenames, options.eval)) {
581
+ for await (let { filename, error, content, stdin } of readFiles(filenames, options.eval)) {
564
582
  if (error) {
565
583
  console.error(`${filename} failed to load:`);
566
584
  console.error(error);
@@ -583,14 +601,6 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
583
601
  errors++;
584
602
  continue;
585
603
  }
586
- process.stdout.on("error", (e) => {
587
- if (["EPIPE", "EOF"].includes(e.code)) {
588
- return process.exit(0);
589
- } else {
590
- console.error(e);
591
- return process.exit(1);
592
- }
593
- });
594
604
  if (options.ast) {
595
605
  process.stdout.write(JSON.stringify(output, null, 2));
596
606
  } else if (options.compile) {
@@ -626,14 +636,24 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
626
636
  }
627
637
  }
628
638
  } else if (options.run) {
629
- const esm = /^\s*(import|export)\b/m.test(output);
639
+ let ref3;
640
+ {
641
+ if (typeof output === "string" && /\b(await|import|export)\b/.test(output)) {
642
+ const ast = await (0, import_main.compile)(content, { ...options, ast: true, filename });
643
+ ref3 = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast) || import_main.lib.hasExportDeclaration(ast);
644
+ } else {
645
+ ref3 = void 0;
646
+ }
647
+ }
648
+ ;
649
+ const esm = ref3;
630
650
  if (esm) {
631
651
  if (stdin) {
632
- const filename2 = `.stdin-${process.pid}.civet`;
652
+ filename = `.stdin-${process.pid}.civet`;
633
653
  try {
634
- await import_promises.default.writeFile(filename2, content, { encoding });
654
+ await import_promises.default.writeFile(filename, content, { encoding });
635
655
  } catch (e) {
636
- console.error(`Could not write ${filename2} for Civet ESM mode:`);
656
+ console.error(`Could not write ${filename} for Civet ESM mode:`);
637
657
  console.error(e);
638
658
  process.exit(1);
639
659
  }
@@ -706,9 +726,9 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
706
726
  }
707
727
  }, !filenames.length);
708
728
  } catch (error) {
709
- let ref1;
710
- if (ref1 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
711
- const match = ref1;
729
+ let ref4;
730
+ if (ref4 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
731
+ const match = ref4;
712
732
  return process.exitCode = Math.min(255, errors + +match[1]);
713
733
  } else {
714
734
  process.exitCode = 1;