@danielx/civet 0.11.8 → 0.11.10

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/main.js CHANGED
@@ -504,6 +504,7 @@ __export(lib_exports, {
504
504
  braceBlock: () => braceBlock,
505
505
  bracedBlock: () => bracedBlock,
506
506
  buildExportSplitClause: () => buildExportSplitClause,
507
+ canExpressionizeIfAsTernary: () => canExpressionizeIfAsTernary,
507
508
  convertArrowFunctionToMethod: () => convertArrowFunctionToMethod,
508
509
  convertFunctionToMethod: () => convertFunctionToMethod,
509
510
  convertNamedImportsToObject: () => convertNamedImportsToObject,
@@ -950,12 +951,13 @@ function prepend(prefix, node) {
950
951
  }
951
952
  if (Array.isArray(node)) {
952
953
  return [prefix, ...node];
953
- } else {
954
- assert(isParent(node), "prepend: can't glom into an AST leaf");
954
+ } else if (isParent(node)) {
955
955
  return {
956
956
  ...node,
957
957
  children: [prefix, ...node.children]
958
958
  };
959
+ } else {
960
+ return [prefix, node];
959
961
  }
960
962
  }
961
963
  function append(node, suffix) {
@@ -5680,6 +5682,9 @@ function prependStatementExpressionBlock(initializer, statement) {
5680
5682
  return;
5681
5683
  }
5682
5684
  const statementExp = exp.statement;
5685
+ if (statementExp.type === "IfStatement" && canExpressionizeIfAsTernary(statementExp)) {
5686
+ return;
5687
+ }
5683
5688
  const blockStatement = [ws || "", statementExp, ";"];
5684
5689
  const pre = [blockStatement];
5685
5690
  let ref;
@@ -7462,6 +7467,25 @@ function expressionizeBlock(blockOrExpression) {
7462
7467
  return blockOrExpression;
7463
7468
  }
7464
7469
  }
7470
+ function canExpressionizeIfAsTernary(statement) {
7471
+ const { then: b, else: e } = statement;
7472
+ return canExpressionizeBlock(b) && (e ? canExpressionizeBlock(e.block) : true);
7473
+ }
7474
+ function canExpressionizeBlock(blockOrExpression) {
7475
+ if (blockOrExpression && typeof blockOrExpression === "object" && "expressions" in blockOrExpression) {
7476
+ const { expressions } = blockOrExpression;
7477
+ let results1 = true;
7478
+ for (const [, s] of expressions) {
7479
+ if (!isExpression(s)) {
7480
+ results1 = false;
7481
+ break;
7482
+ }
7483
+ }
7484
+ return results1;
7485
+ }
7486
+ ;
7487
+ return;
7488
+ }
7465
7489
  function expressionizeIfStatement(statement) {
7466
7490
  const { condition, then: b, else: e } = statement;
7467
7491
  const [...condRest] = condition.children, [closeParen] = condRest.splice(-1);
@@ -8596,11 +8620,11 @@ function attachPostfixStatementAsExpression(exp, post) {
8596
8620
  }
8597
8621
  }
8598
8622
  function processTypes(node) {
8599
- const results1 = [];
8623
+ const results2 = [];
8600
8624
  for (let ref22 = gatherRecursiveAll(node, ($13) => $13.type === "TypeUnary"), i12 = 0, len11 = ref22.length; i12 < len11; i12++) {
8601
8625
  const unary = ref22[i12];
8602
8626
  let suffixIndex = unary.suffix.length - 1;
8603
- const results2 = [];
8627
+ const results3 = [];
8604
8628
  while (suffixIndex >= 0) {
8605
8629
  const suffix = unary.suffix[suffixIndex];
8606
8630
  if (typeof suffix === "object" && suffix != null && "token" in suffix && suffix.token === "?") {
@@ -8660,7 +8684,7 @@ function processTypes(node) {
8660
8684
  children: [prefix, replace, outer]
8661
8685
  });
8662
8686
  }
8663
- results2.push(replaceNode(unary, replace, parent));
8687
+ results3.push(replaceNode(unary, replace, parent));
8664
8688
  } else if (typeof suffix === "object" && suffix != null && "type" in suffix && suffix.type === "NonNullAssertion") {
8665
8689
  const {} = suffix;
8666
8690
  let m7;
@@ -8715,15 +8739,15 @@ function processTypes(node) {
8715
8739
  children: [prefix, replace, outer]
8716
8740
  });
8717
8741
  }
8718
- results2.push(replaceNode(unary, replace, parent));
8742
+ results3.push(replaceNode(unary, replace, parent));
8719
8743
  } else {
8720
- results2.push(suffixIndex--);
8744
+ results3.push(suffixIndex--);
8721
8745
  }
8722
8746
  }
8723
- results1.push(results2);
8747
+ results2.push(results3);
8724
8748
  }
8725
8749
  ;
8726
- return results1;
8750
+ return results2;
8727
8751
  }
8728
8752
  function processStatementExpressions(statements) {
8729
8753
  for (let ref24 = gatherRecursiveAll(statements, ($14) => $14.type === "StatementExpression"), i13 = 0, len12 = ref24.length; i13 < len12; i13++) {
@@ -8908,12 +8932,12 @@ function processCoffeeClasses(statements) {
8908
8932
  index + 1,
8909
8933
  0,
8910
8934
  ...(() => {
8911
- const results3 = [];
8935
+ const results4 = [];
8912
8936
  for (let i16 = 0, len15 = autoBinds.length; i16 < len15; i16++) {
8913
8937
  const [, a] = autoBinds[i16];
8914
- results3.push([indent, ["this.", a.name, " = this.", a.name, ".bind(this)"], ";"]);
8938
+ results4.push([indent, ["this.", a.name, " = this.", a.name, ".bind(this)"], ";"]);
8915
8939
  }
8916
- return results3;
8940
+ return results4;
8917
8941
  })()
8918
8942
  );
8919
8943
  }
@@ -9512,6 +9536,7 @@ var grammar = {
9512
9536
  ImplicitAccessStart,
9513
9537
  PropertyAccessModifier,
9514
9538
  PropertyAccess,
9539
+ AccessLiteral,
9515
9540
  ExplicitPropertyGlob,
9516
9541
  PropertyGlob,
9517
9542
  PropertyBind,
@@ -15540,13 +15565,14 @@ function ClassElement$0($$ctx, $$state) {
15540
15565
  }
15541
15566
  if ($$ctx.tokenize) return $$r;
15542
15567
  const $$loc = $$r.loc, $$value = $$r.value;
15543
- const $$m = /* @__PURE__ */ (function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
15568
+ const $$m = (function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
15544
15569
  var decorators = $2;
15545
15570
  var declare = $3;
15546
15571
  var access = $4;
15547
15572
  var static_ = $5;
15548
15573
  var override = $6;
15549
15574
  var assignment = $7;
15575
+ if (assignment.assigned?.type === "SymbolLiteral") return $skip;
15550
15576
  return {
15551
15577
  type: static_ ? "CoffeeClassPublic" : "CoffeeClassPrivate",
15552
15578
  children: [decorators, declare, access, static_, override, assignment],
@@ -17385,7 +17411,7 @@ function PropertyAccessModifier($$ctx, $$state) {
17385
17411
  if ($$ctx.exit) $$ctx.exit("PropertyAccessModifier", $$state, $$final, $$eventData);
17386
17412
  return $$final;
17387
17413
  }
17388
- var PropertyAccess$0$parser = (0, import_lib2.$S)(AccessStart, (0, import_lib2.$C)(TemplateLiteral, StringLiteral, IntegerLiteral, SymbolLiteral));
17414
+ var PropertyAccess$0$parser = (0, import_lib2.$S)(AccessStart, (0, import_lib2.$C)(TemplateLiteral, AccessLiteral, SymbolLiteral));
17389
17415
  var PropertyAccess$1$parser = (0, import_lib2.$S)(AccessStart, (0, import_lib2.$EXPECT)($L22, 'PropertyAccess "-"'), IntegerLiteral);
17390
17416
  var PropertyAccess$2$parser = (0, import_lib2.$S)(AccessStart, (0, import_lib2.$Q)(InlineComment), (0, import_lib2.$C)(IdentifierName, PrivateIdentifier, LengthShorthand));
17391
17417
  var PropertyAccess$3$parser = (0, import_lib2.$S)(ExplicitAccessStart, (0, import_lib2.$Y)(EOS));
@@ -17400,12 +17426,14 @@ function PropertyAccess$0($$ctx, $$state) {
17400
17426
  const $$loc = $$r.loc, $$value = $$r.value;
17401
17427
  const $$m = (function($skip, $loc, $0, $1, $2) {
17402
17428
  var dot = $1;
17403
- var literal = $2;
17429
+ var expression = $2;
17404
17430
  return {
17405
17431
  type: "Index",
17432
+ expression,
17406
17433
  children: [
17407
17434
  adjustIndexAccess(dot),
17408
- literal,
17435
+ expression,
17436
+ "",
17409
17437
  "]"
17410
17438
  ]
17411
17439
  };
@@ -17463,12 +17491,21 @@ function PropertyAccess$2($$ctx, $$state) {
17463
17491
  var comments = $2;
17464
17492
  var id = $3;
17465
17493
  if (id.unicode) {
17494
+ const key = propertyKey(id);
17495
+ const expression = {
17496
+ type: "Literal",
17497
+ subtype: "StringLiteral",
17498
+ children: [key],
17499
+ raw: key.token
17500
+ };
17466
17501
  return {
17467
17502
  type: "Index",
17503
+ expression,
17468
17504
  children: [
17469
17505
  adjustIndexAccess(dot),
17470
17506
  ...comments,
17471
- propertyKey(id),
17507
+ expression,
17508
+ "",
17472
17509
  "]"
17473
17510
  ]
17474
17511
  };
@@ -17558,11 +17595,12 @@ function PropertyAccess$5($$ctx, $$state) {
17558
17595
  optional: modifier?.token === "?"
17559
17596
  };
17560
17597
  if (id) {
17598
+ const access = id.unicode ? ["prototype[", propertyKey(id), "]"] : ["prototype.", id];
17561
17599
  return {
17562
17600
  type: "PropertyAccess",
17563
17601
  name: id.name,
17564
17602
  dot: start,
17565
- children: [start, "prototype.", id]
17603
+ children: [start, ...access]
17566
17604
  };
17567
17605
  } else {
17568
17606
  return {
@@ -17601,6 +17639,40 @@ function PropertyAccess($$ctx, $$state) {
17601
17639
  if ($$ctx.exit) $$ctx.exit("PropertyAccess", $$state, $$final, $$eventData);
17602
17640
  return $$final;
17603
17641
  }
17642
+ var AccessLiteral$parser = (0, import_lib2.$C)(StringLiteral, IntegerLiteral);
17643
+ function AccessLiteral($$ctx, $$state) {
17644
+ const $$entered = $$ctx.enter && $$ctx.enter("AccessLiteral", $$state);
17645
+ if ($$entered && "cache" in $$entered) return $$entered.cache;
17646
+ const $$eventData = $$entered && $$entered.data;
17647
+ const $$r = AccessLiteral$parser($$ctx, $$state);
17648
+ if (!$$r) {
17649
+ if ($$ctx.exit) $$ctx.exit("AccessLiteral", $$state, void 0, $$eventData);
17650
+ return void 0;
17651
+ }
17652
+ if ($$ctx.tokenize) {
17653
+ const $$tok = $$r;
17654
+ $$tok.value = { type: "AccessLiteral", children: [$$r.value].flat(), token: $$state.input.substring($$state.pos, $$r.pos), loc: $$r.loc };
17655
+ if ($$ctx.exit) $$ctx.exit("AccessLiteral", $$state, $$tok, $$eventData);
17656
+ return $$tok;
17657
+ }
17658
+ const $$loc = $$r.loc, $$value = $$r.value;
17659
+ const $$m = (function($skip, $loc, $0, $1) {
17660
+ var literal = $0;
17661
+ return {
17662
+ type: "Literal",
17663
+ subtype: literal.type,
17664
+ children: [literal],
17665
+ raw: literal.token
17666
+ };
17667
+ })(import_lib2.SKIP, $$loc, $$value, $$value);
17668
+ let $$final = void 0;
17669
+ if ($$m !== import_lib2.SKIP) {
17670
+ $$r.value = $$m;
17671
+ $$final = $$r;
17672
+ }
17673
+ if ($$ctx.exit) $$ctx.exit("AccessLiteral", $$state, $$final, $$eventData);
17674
+ return $$final;
17675
+ }
17604
17676
  var ExplicitPropertyGlob$parser = (0, import_lib2.$S)((0, import_lib2.$Y)(ExplicitAccessStart), PropertyGlob);
17605
17677
  function ExplicitPropertyGlob($$ctx, $$state) {
17606
17678
  const $$entered = $$ctx.enter && $$ctx.enter("ExplicitPropertyGlob", $$state);
@@ -17686,10 +17758,11 @@ function PropertyBind($$ctx, $$state) {
17686
17758
  var dot = $3;
17687
17759
  var id = $4;
17688
17760
  var args = $5;
17761
+ const children = id.unicode ? [modifier, modifier?.token === "?" ? dot : null, "[", propertyKey(id), "]"] : [modifier, dot, id];
17689
17762
  return {
17690
17763
  type: "PropertyBind",
17691
17764
  name: id.name,
17692
- children: [modifier, dot, id],
17765
+ children,
17693
17766
  // omit `@` from children
17694
17767
  args: args?.children.slice(1, -1) ?? []
17695
17768
  // remove the parens from the arg list, or give an empty list
@@ -17725,10 +17798,11 @@ function PropertyBindExplicitArguments($$ctx, $$state) {
17725
17798
  var dot = $3;
17726
17799
  var id = $4;
17727
17800
  var args = $5;
17801
+ const children = id.unicode ? [modifier, modifier?.token === "?" ? dot : null, "[", propertyKey(id), "]"] : [modifier, dot, id];
17728
17802
  return {
17729
17803
  type: "PropertyBind",
17730
17804
  name: id.name,
17731
- children: [modifier, dot, id],
17805
+ children,
17732
17806
  // omit `@` from children
17733
17807
  args: args?.children.slice(1, -1) ?? []
17734
17808
  // remove the parens from the arg list, or give an empty list
@@ -21874,9 +21948,16 @@ function SymbolLiteral($$ctx, $$state) {
21874
21948
  const $$m = (function($skip, $loc, $0, $1, $2) {
21875
21949
  var colon = $1;
21876
21950
  var id = $2;
21877
- let name, token;
21951
+ let name, token, quoted;
21878
21952
  if (id.type === "Identifier") {
21879
- ({ name, children: [token] } = id);
21953
+ if (id.unicode) {
21954
+ name = id.unicode;
21955
+ token = { $loc: id.children?.[0]?.$loc, token: `"${id.unicode}"` };
21956
+ quoted = true;
21957
+ } else {
21958
+ ({ name, children: [token] } = id);
21959
+ quoted = false;
21960
+ }
21880
21961
  } else {
21881
21962
  name = literalValue({
21882
21963
  type: "Literal",
@@ -21885,17 +21966,18 @@ function SymbolLiteral($$ctx, $$state) {
21885
21966
  children: [id]
21886
21967
  });
21887
21968
  token = id;
21969
+ quoted = true;
21888
21970
  }
21889
21971
  if (config.symbols.includes(name)) {
21890
21972
  return {
21891
21973
  type: "SymbolLiteral",
21892
- children: id.type === "Identifier" ? [
21893
- { ...colon, token: "Symbol." },
21894
- token
21895
- ] : [
21974
+ children: quoted ? [
21896
21975
  { ...colon, token: "Symbol[" },
21897
21976
  token,
21898
21977
  "]"
21978
+ ] : [
21979
+ { ...colon, token: "Symbol." },
21980
+ token
21899
21981
  ],
21900
21982
  name
21901
21983
  };
@@ -21904,7 +21986,7 @@ function SymbolLiteral($$ctx, $$state) {
21904
21986
  type: "SymbolLiteral",
21905
21987
  children: [
21906
21988
  { ...colon, token: "Symbol.for(" },
21907
- id.type === "Identifier" ? ['"', token, '"'] : token,
21989
+ quoted ? token : ['"', token, '"'],
21908
21990
  ")"
21909
21991
  ],
21910
21992
  name
@@ -34185,7 +34267,7 @@ function IntegerLiteral($$ctx, $$state) {
34185
34267
  const $$loc = $$r.loc, $$value = $$r.value;
34186
34268
  const $$m = /* @__PURE__ */ (function($skip, $loc, $0, $1, $2) {
34187
34269
  var token = $2;
34188
- return { $loc, token };
34270
+ return { type: "NumericLiteral", $loc, token };
34189
34271
  })(import_lib2.SKIP, $$loc, $$value, $$value[0], $$value[1]);
34190
34272
  let $$final = void 0;
34191
34273
  if ($$m !== import_lib2.SKIP) {
@@ -35346,11 +35428,11 @@ function TemplateBlockCharacters($$ctx, $$state) {
35346
35428
  if ($$ctx.exit) $$ctx.exit("TemplateBlockCharacters", $$state, $$final, $$eventData);
35347
35429
  return $$final;
35348
35430
  }
35349
- var ReservedWord$0$parser = (0, import_lib2.$S)((0, import_lib2.$EXPECT)($R67, "ReservedWord /(?:off|yes|on|no)/"), NonIdContinue, CoffeeBooleansEnabled);
35350
- var ReservedWord$1$parser = (0, import_lib2.$S)((0, import_lib2.$EXPECT)($R68, "ReservedWord /isnt/"), NonIdContinue, CoffeeIsntEnabled);
35351
- var ReservedWord$2$parser = (0, import_lib2.$S)((0, import_lib2.$EXPECT)($R69, "ReservedWord /by/"), NonIdContinue, CoffeeForLoopsEnabled);
35352
- var ReservedWord$3$parser = (0, import_lib2.$S)((0, import_lib2.$EXPECT)($R70, "ReservedWord /of/"), NonIdContinue, CoffeeOfEnabled);
35353
- var ReservedWord$4$parser = (0, import_lib2.$S)((0, import_lib2.$EXPECT)($R71, "ReservedWord /(?:instanceof|interface|protected|continue|debugger|function|default|extends|finally|private|delete|export|import|public|return|static|switch|typeof|unless|await|break|catch|class|const|false|super|throw|until|while|yield|case|else|enum|loop|null|this|true|void|with|and|for|let|new|not|try|var|do|if|in|is|or)/"), NonIdContinue);
35431
+ var ReservedWord$0$parser = (0, import_lib2.$S)((0, import_lib2.$TEXT)((0, import_lib2.$EXPECT)($R67, "ReservedWord /(?:off|yes|on|no)/")), NonIdContinue, CoffeeBooleansEnabled);
35432
+ var ReservedWord$1$parser = (0, import_lib2.$S)((0, import_lib2.$TEXT)((0, import_lib2.$EXPECT)($R68, "ReservedWord /isnt/")), NonIdContinue, CoffeeIsntEnabled);
35433
+ var ReservedWord$2$parser = (0, import_lib2.$S)((0, import_lib2.$TEXT)((0, import_lib2.$EXPECT)($R69, "ReservedWord /by/")), NonIdContinue, CoffeeForLoopsEnabled);
35434
+ var ReservedWord$3$parser = (0, import_lib2.$S)((0, import_lib2.$TEXT)((0, import_lib2.$EXPECT)($R70, "ReservedWord /of/")), NonIdContinue, CoffeeOfEnabled);
35435
+ var ReservedWord$4$parser = (0, import_lib2.$S)((0, import_lib2.$TEXT)((0, import_lib2.$EXPECT)($R71, "ReservedWord /(?:instanceof|interface|protected|continue|debugger|function|default|extends|finally|private|delete|export|import|public|return|static|switch|typeof|unless|await|break|catch|class|const|false|super|throw|until|while|yield|case|else|enum|loop|null|this|true|void|with|and|for|let|new|not|try|var|do|if|in|is|or)/")), NonIdContinue);
35354
35436
  function ReservedWord$0($$ctx, $$state) {
35355
35437
  const $$r = ReservedWord$0$parser($$ctx, $$state);
35356
35438
  if (!$$r) {