@danielx/civet 0.6.15 → 0.6.17

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
@@ -744,12 +744,15 @@ var require_lib = __commonJS({
744
744
  }
745
745
  }
746
746
  function findAncestor(node, predicate, stopPredicate) {
747
- node = node.parent;
748
- while (node && !stopPredicate?.(node)) {
749
- if (predicate(node))
750
- return node;
751
- node = node.parent;
747
+ let { parent } = node;
748
+ while (parent && !stopPredicate?.(parent, node)) {
749
+ if (predicate(parent, node)) {
750
+ return { ancestor: parent, child: node };
751
+ }
752
+ node = parent;
753
+ parent = node.parent;
752
754
  }
755
+ return { ancestor: void 0, child: node };
753
756
  }
754
757
  function gatherNodes(node, predicate) {
755
758
  if (node == null)
@@ -822,14 +825,11 @@ var require_lib = __commonJS({
822
825
  }
823
826
  function hoistRefDecs(statements) {
824
827
  gatherRecursiveAll(statements, (s) => s.hoistDec).forEach((node) => {
825
- let { hoistDec, parent } = node;
828
+ let { hoistDec } = node;
826
829
  node.hoistDec = null;
827
- while (parent?.type !== "BlockStatement" || parent.bare && !parent.root) {
828
- node = parent;
829
- parent = node.parent;
830
- }
831
- if (parent) {
832
- insertHoistDec(parent, node, hoistDec);
830
+ const { ancestor, child } = findAncestor(node, (ancestor2) => ancestor2.type === "BlockStatement" && (!ancestor2.bare || ancestor2.root));
831
+ if (ancestor) {
832
+ insertHoistDec(ancestor, child, hoistDec);
833
833
  } else {
834
834
  throw new Error("Couldn't find block to hoist declaration into.");
835
835
  }
@@ -945,6 +945,9 @@ var require_lib = __commonJS({
945
945
  function isVoidType(t) {
946
946
  return t?.type === "LiteralType" && t.t.type === "VoidType";
947
947
  }
948
+ function isPromiseVoidType(t) {
949
+ return t?.type === "IdentifierType" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
950
+ }
948
951
  function isWhitespaceOrEmpty(node) {
949
952
  if (!node)
950
953
  return true;
@@ -1369,6 +1372,8 @@ var require_lib = __commonJS({
1369
1372
  if (f.abstract || f.block || f.signature?.optional)
1370
1373
  return;
1371
1374
  const { name, parent } = f;
1375
+ if (parent?.type === "ExportDeclaration")
1376
+ return;
1372
1377
  const expressions = parent?.expressions ?? parent?.elements;
1373
1378
  const currentIndex = expressions?.findIndex(([, def]) => def === f);
1374
1379
  const following = currentIndex >= 0 && expressions[currentIndex + 1]?.[1];
@@ -1388,8 +1393,8 @@ var require_lib = __commonJS({
1388
1393
  implicitFunctionBlock(f);
1389
1394
  processParams(f);
1390
1395
  if (!processReturnValue(f) && config.implicitReturns) {
1391
- const { block, returnType } = f;
1392
- const isVoid = isVoidType(returnType?.t);
1396
+ const { async, block, returnType } = f;
1397
+ const isVoid = isVoidType(returnType?.t) || async && isPromiseVoidType(returnType?.t);
1393
1398
  const isBlock = block?.type === "BlockStatement";
1394
1399
  if (!isVoid && isBlock) {
1395
1400
  insertReturn(block);
@@ -2111,7 +2116,7 @@ var require_lib = __commonJS({
2111
2116
  if (!hasDec(x))
2112
2117
  return a.indexOf(x) === i;
2113
2118
  }).forEach(pushVar);
2114
- const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
2119
+ const fnNodes = gatherNodes(statements, isFunction);
2115
2120
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
2116
2121
  const blockNodes = new Set(gatherNodes(statements, (s) => s.type === "BlockStatement"));
2117
2122
  fnNodes.forEach(({ block }) => blockNodes.delete(block));
@@ -2163,7 +2168,7 @@ var require_lib = __commonJS({
2163
2168
  }
2164
2169
  let currentScope = /* @__PURE__ */ new Set();
2165
2170
  scopes.push(currentScope);
2166
- const fnNodes = gatherNodes(statements, (s) => s.type === "FunctionExpression");
2171
+ const fnNodes = gatherNodes(statements, isFunction);
2167
2172
  const forNodes = gatherNodes(statements, (s) => s.type === "ForStatement");
2168
2173
  let targetStatements = [];
2169
2174
  for (const statement of statements) {
@@ -2226,7 +2231,7 @@ var require_lib = __commonJS({
2226
2231
  let declared;
2227
2232
  values.forEach((value) => {
2228
2233
  value.children = [ref];
2229
- const ancestor = findAncestor(
2234
+ const { ancestor } = findAncestor(
2230
2235
  value,
2231
2236
  ({ type }) => type === "Declaration",
2232
2237
  isFunction
@@ -2996,6 +3001,7 @@ ${input.slice(result.pos)}
2996
3001
  NonPipelineArgumentPart,
2997
3002
  BinaryOpExpression,
2998
3003
  BinaryOpRHS,
3004
+ WRHS,
2999
3005
  SingleLineBinaryOpRHS,
3000
3006
  RHS,
3001
3007
  ParenthesizedAssignment,
@@ -3105,6 +3111,8 @@ ${input.slice(result.pos)}
3105
3111
  ExplicitBlock,
3106
3112
  ImplicitNestedBlock,
3107
3113
  Block,
3114
+ BareNestedBlock,
3115
+ BareBlock,
3108
3116
  ThenClause,
3109
3117
  BracedOrEmptyBlock,
3110
3118
  NoPostfixBracedOrEmptyBlock,
@@ -3229,7 +3237,9 @@ ${input.slice(result.pos)}
3229
3237
  PatternExpressionList,
3230
3238
  ConditionFragment,
3231
3239
  CaseExpressionList,
3240
+ CaseExpression,
3232
3241
  ImpliedColon,
3242
+ IgnoreColon,
3233
3243
  TryStatement,
3234
3244
  TryExpression,
3235
3245
  CatchClause,
@@ -3572,6 +3582,7 @@ ${input.slice(result.pos)}
3572
3582
  EOS,
3573
3583
  EOL,
3574
3584
  DebugHere,
3585
+ InsertColon,
3575
3586
  InsertSemicolon,
3576
3587
  InsertOpenParen,
3577
3588
  InsertCloseParen,
@@ -4803,9 +4814,10 @@ ${input.slice(result.pos)}
4803
4814
  var rhs = $2;
4804
4815
  return [[], op, [], rhs];
4805
4816
  });
4806
- var BinaryOpRHS$1 = $TS($S(NewlineBinaryOpAllowed, $S(NotDedentedBinaryOp, $C(_, $S(EOS, __)), RHS)), function($skip, $loc, $0, $1, $2) {
4807
- var rhs = $2;
4808
- return [...rhs[0], ...rhs.slice(1)];
4817
+ var BinaryOpRHS$1 = $TS($S(NewlineBinaryOpAllowed, NotDedentedBinaryOp, WRHS), function($skip, $loc, $0, $1, $2, $3) {
4818
+ var op = $2;
4819
+ var rhs = $3;
4820
+ return [...op, ...rhs];
4809
4821
  });
4810
4822
  var BinaryOpRHS$2 = $T($S($N(NewlineBinaryOpAllowed), SingleLineBinaryOpRHS), function(value) {
4811
4823
  return value[1];
@@ -4832,6 +4844,35 @@ ${input.slice(result.pos)}
4832
4844
  return result;
4833
4845
  }
4834
4846
  }
4847
+ var WRHS$0 = $TS($S(PushIndent, $E($S(Nested, RHS)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
4848
+ var wrhs = $2;
4849
+ if (!wrhs)
4850
+ return $skip;
4851
+ return wrhs;
4852
+ });
4853
+ var WRHS$1 = $S($C(_, $S(EOS, __)), RHS);
4854
+ function WRHS(state) {
4855
+ let eventData;
4856
+ if (state.events) {
4857
+ const result = state.events.enter?.("WRHS", state);
4858
+ if (result) {
4859
+ if (result.cache)
4860
+ return result.cache;
4861
+ eventData = result.data;
4862
+ }
4863
+ }
4864
+ if (state.tokenize) {
4865
+ const result = $TOKEN("WRHS", state, WRHS$0(state) || WRHS$1(state));
4866
+ if (state.events)
4867
+ state.events.exit?.("WRHS", state, result, eventData);
4868
+ return result;
4869
+ } else {
4870
+ const result = WRHS$0(state) || WRHS$1(state);
4871
+ if (state.events)
4872
+ state.events.exit?.("WRHS", state, result, eventData);
4873
+ return result;
4874
+ }
4875
+ }
4835
4876
  var SingleLineBinaryOpRHS$0 = $TS($S($E(_), BinaryOp, $C(_, $S(EOS, __)), RHS), function($skip, $loc, $0, $1, $2, $3, $4) {
4836
4877
  var ws1 = $1;
4837
4878
  var op = $2;
@@ -5538,8 +5579,8 @@ ${input.slice(result.pos)}
5538
5579
  var PrimaryExpression$2 = TemplateLiteral;
5539
5580
  var PrimaryExpression$3 = Literal;
5540
5581
  var PrimaryExpression$4 = ArrayLiteral;
5541
- var PrimaryExpression$5 = IdentifierReference;
5542
- var PrimaryExpression$6 = FunctionExpression;
5582
+ var PrimaryExpression$5 = FunctionExpression;
5583
+ var PrimaryExpression$6 = IdentifierReference;
5543
5584
  var PrimaryExpression$7 = ClassExpression;
5544
5585
  var PrimaryExpression$8 = RegularExpressionLiteral;
5545
5586
  var PrimaryExpression$9 = ParenthesizedExpression;
@@ -8465,6 +8506,70 @@ ${input.slice(result.pos)}
8465
8506
  return result;
8466
8507
  }
8467
8508
  }
8509
+ var BareNestedBlock$0 = $TS($S($Y(EOS), AllowAll, $E(NestedBlockStatements), RestoreAll), function($skip, $loc, $0, $1, $2, $3, $4) {
8510
+ if (!$3)
8511
+ return $skip;
8512
+ return $3;
8513
+ });
8514
+ function BareNestedBlock(state) {
8515
+ let eventData;
8516
+ if (state.events) {
8517
+ const result = state.events.enter?.("BareNestedBlock", state);
8518
+ if (result) {
8519
+ if (result.cache)
8520
+ return result.cache;
8521
+ eventData = result.data;
8522
+ }
8523
+ }
8524
+ if (state.tokenize) {
8525
+ const result = $TOKEN("BareNestedBlock", state, BareNestedBlock$0(state));
8526
+ if (state.events)
8527
+ state.events.exit?.("BareNestedBlock", state, result, eventData);
8528
+ return result;
8529
+ } else {
8530
+ const result = BareNestedBlock$0(state);
8531
+ if (state.events)
8532
+ state.events.exit?.("BareNestedBlock", state, result, eventData);
8533
+ return result;
8534
+ }
8535
+ }
8536
+ var BareBlock$0 = BareNestedBlock;
8537
+ var BareBlock$1 = ExplicitBlock;
8538
+ var BareBlock$2 = ThenClause;
8539
+ var BareBlock$3 = $TS($S($E(_), $N(EOS), Statement), function($skip, $loc, $0, $1, $2, $3) {
8540
+ var ws = $1;
8541
+ var s = $3;
8542
+ const expressions = [[ws, s]];
8543
+ return {
8544
+ type: "BlockStatement",
8545
+ expressions,
8546
+ children: [expressions],
8547
+ bare: true
8548
+ };
8549
+ });
8550
+ var BareBlock$4 = EmptyBareBlock;
8551
+ function BareBlock(state) {
8552
+ let eventData;
8553
+ if (state.events) {
8554
+ const result = state.events.enter?.("BareBlock", state);
8555
+ if (result) {
8556
+ if (result.cache)
8557
+ return result.cache;
8558
+ eventData = result.data;
8559
+ }
8560
+ }
8561
+ if (state.tokenize) {
8562
+ const result = $TOKEN("BareBlock", state, BareBlock$0(state) || BareBlock$1(state) || BareBlock$2(state) || BareBlock$3(state) || BareBlock$4(state));
8563
+ if (state.events)
8564
+ state.events.exit?.("BareBlock", state, result, eventData);
8565
+ return result;
8566
+ } else {
8567
+ const result = BareBlock$0(state) || BareBlock$1(state) || BareBlock$2(state) || BareBlock$3(state) || BareBlock$4(state);
8568
+ if (state.events)
8569
+ state.events.exit?.("BareBlock", state, result, eventData);
8570
+ return result;
8571
+ }
8572
+ }
8468
8573
  var ThenClause$0 = $T($S(Then, SingleLineStatements), function(value) {
8469
8574
  return value[1];
8470
8575
  });
@@ -10215,13 +10320,17 @@ ${input.slice(result.pos)}
10215
10320
  return {
10216
10321
  type: "ComputedPropertyName",
10217
10322
  children: $0,
10218
- expression
10323
+ expression,
10324
+ implicit: true
10219
10325
  };
10220
10326
  });
10221
10327
  var ComputedPropertyName$2 = $TS($S(InsertOpenBracket, $EXPECT($L20, fail, 'ComputedPropertyName "-"'), NumericLiteral, InsertCloseBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
10328
+ const expression = [$2, $3];
10222
10329
  return {
10223
10330
  type: "ComputedPropertyName",
10224
- children: $0
10331
+ expression,
10332
+ children: [$1, expression, $4],
10333
+ implicit: true
10225
10334
  };
10226
10335
  });
10227
10336
  function ComputedPropertyName(state) {
@@ -12849,7 +12958,7 @@ ${input.slice(result.pos)}
12849
12958
  return result;
12850
12959
  }
12851
12960
  }
12852
- var CaseClause$0 = $TS($S(PatternExpressionList, $C(ThenClause, NestedBlockStatements, EmptyBareBlock)), function($skip, $loc, $0, $1, $2) {
12961
+ var CaseClause$0 = $TS($S(PatternExpressionList, $C(ThenClause, BareBlock)), function($skip, $loc, $0, $1, $2) {
12853
12962
  var patterns = $1;
12854
12963
  var block = $2;
12855
12964
  return {
@@ -12859,13 +12968,13 @@ ${input.slice(result.pos)}
12859
12968
  patterns
12860
12969
  };
12861
12970
  });
12862
- var CaseClause$1 = $T($S(Case, CaseExpressionList, $C(NestedBlockStatements, EmptyBareBlock)), function(value) {
12971
+ var CaseClause$1 = $T($S(Case, CaseExpressionList, IgnoreColon, $C(ThenClause, BareBlock)), function(value) {
12863
12972
  return { "type": "CaseClause", "children": value };
12864
12973
  });
12865
- var CaseClause$2 = $TS($S(When, CaseExpressionList, InsertOpenBrace, $C(ThenClause, NestedBlockStatements, EmptyBareBlock), InsertBreak, InsertNewline, InsertIndent, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
12974
+ var CaseClause$2 = $TS($S(When, CaseExpressionList, IgnoreColon, InsertOpenBrace, $C(ThenClause, BareBlock), InsertBreak, InsertNewline, InsertIndent, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12866
12975
  var cases = $2;
12867
- var block = $4;
12868
- var b = $5;
12976
+ var block = $5;
12977
+ var b = $6;
12869
12978
  return {
12870
12979
  type: "WhenClause",
12871
12980
  cases,
@@ -12874,7 +12983,7 @@ ${input.slice(result.pos)}
12874
12983
  children: $0
12875
12984
  };
12876
12985
  });
12877
- var CaseClause$3 = $TS($S(Default, ImpliedColon, $C(NestedBlockStatements, EmptyBareBlock)), function($skip, $loc, $0, $1, $2, $3) {
12986
+ var CaseClause$3 = $TS($S(Default, ImpliedColon, $C(ThenClause, BareBlock)), function($skip, $loc, $0, $1, $2, $3) {
12878
12987
  var block = $3;
12879
12988
  return {
12880
12989
  type: "DefaultClause",
@@ -12970,7 +13079,7 @@ ${input.slice(result.pos)}
12970
13079
  return result;
12971
13080
  }
12972
13081
  }
12973
- var CaseExpressionList$0 = $TS($S(ForbidMultiLineImplicitObjectLiteral, $E($S($Q(_), ExpressionWithObjectApplicationForbidden, ImpliedColon)), $Q($S(__, Comma, ExpressionWithObjectApplicationForbidden, ImpliedColon)), RestoreMultiLineImplicitObjectLiteral), function($skip, $loc, $0, $1, $2, $3, $4) {
13082
+ var CaseExpressionList$0 = $TS($S(ForbidMultiLineImplicitObjectLiteral, $E($S($E(_), CaseExpression, InsertColon)), $Q($S(__, Comma, CaseExpression, InsertColon)), RestoreMultiLineImplicitObjectLiteral), function($skip, $loc, $0, $1, $2, $3, $4) {
12974
13083
  var first = $2;
12975
13084
  var rest = $3;
12976
13085
  if (!first)
@@ -13006,10 +13115,40 @@ ${input.slice(result.pos)}
13006
13115
  return result;
13007
13116
  }
13008
13117
  }
13009
- var ImpliedColon$0 = $S($E(_), Colon);
13010
- var ImpliedColon$1 = $TV($EXPECT($L0, fail, 'ImpliedColon ""'), function($skip, $loc, $0, $1) {
13011
- return { $loc, token: ":" };
13118
+ var CaseExpression$0 = $TS($S(PropertyName, $Y($S($E(_), Colon))), function($skip, $loc, $0, $1, $2) {
13119
+ var value = $1;
13120
+ if (value.type === "ComputedPropertyName") {
13121
+ if (value.implicit)
13122
+ return value.expression;
13123
+ return { ...value, type: "ArrayExpression" };
13124
+ }
13125
+ return value;
13012
13126
  });
13127
+ var CaseExpression$1 = ExpressionWithObjectApplicationForbidden;
13128
+ function CaseExpression(state) {
13129
+ let eventData;
13130
+ if (state.events) {
13131
+ const result = state.events.enter?.("CaseExpression", state);
13132
+ if (result) {
13133
+ if (result.cache)
13134
+ return result.cache;
13135
+ eventData = result.data;
13136
+ }
13137
+ }
13138
+ if (state.tokenize) {
13139
+ const result = $TOKEN("CaseExpression", state, CaseExpression$0(state) || CaseExpression$1(state));
13140
+ if (state.events)
13141
+ state.events.exit?.("CaseExpression", state, result, eventData);
13142
+ return result;
13143
+ } else {
13144
+ const result = CaseExpression$0(state) || CaseExpression$1(state);
13145
+ if (state.events)
13146
+ state.events.exit?.("CaseExpression", state, result, eventData);
13147
+ return result;
13148
+ }
13149
+ }
13150
+ var ImpliedColon$0 = $S($E(_), Colon);
13151
+ var ImpliedColon$1 = InsertColon;
13013
13152
  function ImpliedColon(state) {
13014
13153
  let eventData;
13015
13154
  if (state.events) {
@@ -13032,6 +13171,32 @@ ${input.slice(result.pos)}
13032
13171
  return result;
13033
13172
  }
13034
13173
  }
13174
+ var IgnoreColon$0 = $TV($E($S($E(_), Colon)), function($skip, $loc, $0, $1) {
13175
+ if ($1)
13176
+ return $1[0];
13177
+ });
13178
+ function IgnoreColon(state) {
13179
+ let eventData;
13180
+ if (state.events) {
13181
+ const result = state.events.enter?.("IgnoreColon", state);
13182
+ if (result) {
13183
+ if (result.cache)
13184
+ return result.cache;
13185
+ eventData = result.data;
13186
+ }
13187
+ }
13188
+ if (state.tokenize) {
13189
+ const result = $TOKEN("IgnoreColon", state, IgnoreColon$0(state));
13190
+ if (state.events)
13191
+ state.events.exit?.("IgnoreColon", state, result, eventData);
13192
+ return result;
13193
+ } else {
13194
+ const result = IgnoreColon$0(state);
13195
+ if (state.events)
13196
+ state.events.exit?.("IgnoreColon", state, result, eventData);
13197
+ return result;
13198
+ }
13199
+ }
13035
13200
  var TryStatement$0 = $TS($S(Try, $N($EXPECT($L12, fail, 'TryStatement ":"')), NoPostfixBracedOrEmptyBlock, $E(CatchClause), $E(FinallyClause)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
13036
13201
  var t = $1;
13037
13202
  var b = $3;
@@ -14731,14 +14896,15 @@ ${input.slice(result.pos)}
14731
14896
  }
14732
14897
  }
14733
14898
  var ExportDeclaration$0 = $TS($S($E(Decorators), Export, __, Default, __, $C(HoistableDeclaration, ClassDeclaration, ExtendedExpression)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
14734
- return { type: "ExportDeclaration", children: $0 };
14899
+ var declaration = $6;
14900
+ return { type: "ExportDeclaration", declaration, children: $0 };
14735
14901
  });
14736
14902
  var ExportDeclaration$1 = $TS($S(Export, __, ExportFromClause, __, FromClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
14737
14903
  return { type: "ExportDeclaration", ts: $3.ts, children: $0 };
14738
14904
  });
14739
14905
  var ExportDeclaration$2 = $TS($S($E(Decorators), Export, __, $C(Declaration, VariableStatement, TypeAndNamedExports, ExportVarDec)), function($skip, $loc, $0, $1, $2, $3, $4) {
14740
- var decl = $4;
14741
- return { type: "ExportDeclaration", ts: decl.ts, children: $0 };
14906
+ var declaration = $4;
14907
+ return { type: "ExportDeclaration", declaration, ts: declaration.ts, children: $0 };
14742
14908
  });
14743
14909
  function ExportDeclaration(state) {
14744
14910
  let eventData;
@@ -22108,7 +22274,8 @@ ${input.slice(result.pos)}
22108
22274
  }
22109
22275
  }
22110
22276
  var TypeArguments$0 = $TS($S($EXPECT($L155, fail, 'TypeArguments "<"'), $P(TypeArgument), __, $EXPECT($L34, fail, 'TypeArguments ">"')), function($skip, $loc, $0, $1, $2, $3, $4) {
22111
- return { ts: true, children: $0 };
22277
+ var args = $2;
22278
+ return { ts: true, types: args.map(([, t]) => t), children: $0 };
22112
22279
  });
22113
22280
  function TypeArguments(state) {
22114
22281
  let eventData;
@@ -22569,6 +22736,31 @@ ${input.slice(result.pos)}
22569
22736
  return result;
22570
22737
  }
22571
22738
  }
22739
+ var InsertColon$0 = $TV($EXPECT($L0, fail, 'InsertColon ""'), function($skip, $loc, $0, $1) {
22740
+ return { $loc, token: ":" };
22741
+ });
22742
+ function InsertColon(state) {
22743
+ let eventData;
22744
+ if (state.events) {
22745
+ const result = state.events.enter?.("InsertColon", state);
22746
+ if (result) {
22747
+ if (result.cache)
22748
+ return result.cache;
22749
+ eventData = result.data;
22750
+ }
22751
+ }
22752
+ if (state.tokenize) {
22753
+ const result = $TOKEN("InsertColon", state, InsertColon$0(state));
22754
+ if (state.events)
22755
+ state.events.exit?.("InsertColon", state, result, eventData);
22756
+ return result;
22757
+ } else {
22758
+ const result = InsertColon$0(state);
22759
+ if (state.events)
22760
+ state.events.exit?.("InsertColon", state, result, eventData);
22761
+ return result;
22762
+ }
22763
+ }
22572
22764
  var InsertSemicolon$0 = $TV($EXPECT($L0, fail, 'InsertSemicolon ""'), function($skip, $loc, $0, $1) {
22573
22765
  return { $loc, token: ";" };
22574
22766
  });