@danielx/civet 0.8.6 → 0.8.7

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/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ This changelog is generated automatically by [`build/changelog.civet`](build/cha
4
4
  For each version of Civet, it lists and links to all incorporated PRs,
5
5
  as well as a full diff and commit list.
6
6
 
7
+ ## 0.8.7 (2024-10-22, [diff](https://github.com/DanielXMoore/Civet/compare/v0.8.6...v0.8.7), [commits](https://github.com/DanielXMoore/Civet/commits/v0.8.7))
8
+ * Fix one-line arrow functions with `@` arguments [[#1490](https://github.com/DanielXMoore/Civet/pull/1490)]
9
+ * Fix `Promise<void>` detection with implicit type arguments [[#1491](https://github.com/DanielXMoore/Civet/pull/1491)]
10
+ * Fix await with array member expression [[#1492](https://github.com/DanielXMoore/Civet/pull/1492)]
11
+
7
12
  ## 0.8.6 (2024-10-21, [diff](https://github.com/DanielXMoore/Civet/compare/v0.8.5...v0.8.6), [commits](https://github.com/DanielXMoore/Civet/commits/v0.8.6))
8
13
  * Fix CLI with complex `NODE_OPTIONS`, LSP cleanup [[#1482](https://github.com/DanielXMoore/Civet/pull/1482)]
9
14
  * `if` conditions continued by binary op on next line [[#1483](https://github.com/DanielXMoore/Civet/pull/1483)]
package/dist/browser.js CHANGED
@@ -547,6 +547,7 @@ ${body}`;
547
547
  hasImportDeclaration: () => hasImportDeclaration,
548
548
  hasYield: () => hasYield,
549
549
  insertTrimmingSpace: () => insertTrimmingSpace,
550
+ isComma: () => isComma,
550
551
  isEmptyBareBlock: () => isEmptyBareBlock,
551
552
  isFunction: () => isFunction,
552
553
  isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
@@ -2344,11 +2345,21 @@ ${js}`
2344
2345
  }
2345
2346
 
2346
2347
  // source/parser/function.civet
2348
+ function getTypeArguments(args) {
2349
+ while (typeof args === "object" && args != null && "args" in args) {
2350
+ args = args.args;
2351
+ }
2352
+ if (!Array.isArray(args)) {
2353
+ throw new Error("getTypeArguments could not find relevant array");
2354
+ }
2355
+ return args.filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "TypeArgument");
2356
+ }
2347
2357
  function isVoidType(t) {
2348
- return t?.type === "TypeLiteral" && t.t.type === "VoidType";
2358
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeLiteral" && "t" in t && typeof t.t === "object" && t.t != null && "type" in t.t && t.t.type === "VoidType";
2349
2359
  }
2350
2360
  function isPromiseVoidType(t) {
2351
- return t?.type === "TypeIdentifier" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
2361
+ let args;
2362
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeIdentifier" && "raw" in t && t.raw === "Promise" && (args = getTypeArguments(t.args?.args)).length === 1 && isVoidType(args[0].t);
2352
2363
  }
2353
2364
  function implicitFunctionBlock(f) {
2354
2365
  if (f.abstract || f.block || f.signature?.optional)
@@ -2934,7 +2945,7 @@ ${js}`
2934
2945
  if (isConstructor) {
2935
2946
  const { ancestor } = findAncestor(f, ($5) => $5.type === "ClassExpression");
2936
2947
  if (ancestor != null) {
2937
- const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "Identifier").map(($8) => $8.name));
2948
+ const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "Identifier").map(($8) => $8.name));
2938
2949
  const classExpressions = ancestor.body.expressions;
2939
2950
  let index = findChildIndex(classExpressions, f);
2940
2951
  assert.notEqual(index, -1, "Could not find constructor in class");
@@ -2986,10 +2997,10 @@ ${js}`
2986
2997
  if (isConstructor) {
2987
2998
  const superCalls = gatherNodes(
2988
2999
  expressions,
2989
- (a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "CallExpression" && "children" in a1 && Array.isArray(a1.children) && a1.children.length >= 1 && typeof a1.children[0] === "object" && a1.children[0] != null && "token" in a1.children[0] && a1.children[0].token === "super"
3000
+ (a2) => typeof a2 === "object" && a2 != null && "type" in a2 && a2.type === "CallExpression" && "children" in a2 && Array.isArray(a2.children) && a2.children.length >= 1 && typeof a2.children[0] === "object" && a2.children[0] != null && "token" in a2.children[0] && a2.children[0].token === "super"
2990
3001
  );
2991
3002
  if (superCalls.length) {
2992
- const { child } = findAncestor(superCalls[0], (a2) => a2 === block);
3003
+ const { child } = findAncestor(superCalls[0], (a3) => a3 === block);
2993
3004
  const index = findChildIndex(expressions, child);
2994
3005
  if (index < 0) {
2995
3006
  throw new Error("Could not find super call within top-level expressions");
@@ -2999,6 +3010,7 @@ ${js}`
2999
3010
  }
3000
3011
  }
3001
3012
  expressions.unshift(...prefix);
3013
+ braceBlock(block);
3002
3014
  }
3003
3015
  function processSignature(f) {
3004
3016
  const { block, signature } = f;
@@ -3121,11 +3133,11 @@ ${js}`
3121
3133
  parameter = {
3122
3134
  ...parameter,
3123
3135
  initializer: void 0,
3124
- children: parameter.children.filter((a3) => a3 !== initializer)
3136
+ children: parameter.children.filter((a4) => a4 !== initializer)
3125
3137
  };
3126
3138
  } else {
3127
3139
  args.push(parameter.children.filter(
3128
- (a4) => a4 !== parameter.typeSuffix
3140
+ (a5) => a5 !== parameter.typeSuffix
3129
3141
  ));
3130
3142
  }
3131
3143
  }
@@ -3198,7 +3210,7 @@ ${js}`
3198
3210
  }
3199
3211
  if (gatherRecursiveWithinFunction(
3200
3212
  block,
3201
- (a5) => a5 === ref
3213
+ (a6) => a6 === ref
3202
3214
  ).length > 1) {
3203
3215
  fn.ampersandBlock = false;
3204
3216
  }
@@ -8095,6 +8107,7 @@ ${js}`
8095
8107
  NestedTypeArgumentList,
8096
8108
  NestedTypeArgument,
8097
8109
  SingleLineTypeArgumentList,
8110
+ WTypeArgument,
8098
8111
  TypeArgumentDelimited,
8099
8112
  TypeArgument,
8100
8113
  TypeArgumentDelimiter,
@@ -8956,10 +8969,10 @@ ${js}`
8956
8969
  function RHS(ctx, state2) {
8957
8970
  return (0, import_lib4.$EVENT_C)(ctx, state2, "RHS", RHS$$);
8958
8971
  }
8959
- var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4) {
8972
+ var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$N)(CallExpressionRest), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8960
8973
  var pre = $2;
8961
8974
  var args = $3;
8962
- var post = $4;
8975
+ var post = $5;
8963
8976
  return processUnaryNestedExpression(pre, args, post) ?? $skip;
8964
8977
  });
8965
8978
  var UnaryExpression$1 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$Q)(UnaryOp), UnaryBody, (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3) {
@@ -18362,11 +18375,12 @@ ${js}`
18362
18375
  }
18363
18376
  var TypeArguments$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(OpenAngleBracket, (0, import_lib4.$P)((0, import_lib4.$S)(__, TypeArgumentDelimited)), __, CloseAngleBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
18364
18377
  var args = $2;
18365
- args = args.map(([ws, arg]) => [ws, ...arg]);
18378
+ args = args.flatMap(([ws, [arg, delim]]) => [prepend(ws, arg), delim]);
18379
+ args.pop();
18366
18380
  return {
18367
18381
  type: "TypeArguments",
18368
18382
  ts: true,
18369
- types: args.map(([, t]) => t),
18383
+ args,
18370
18384
  children: $0
18371
18385
  };
18372
18386
  });
@@ -18378,10 +18392,15 @@ ${js}`
18378
18392
  var ws = $3;
18379
18393
  var args = $4;
18380
18394
  var close = $5;
18381
- let last = args[args.length - 1];
18382
- if (last?.token === ",")
18395
+ const last = args[args.length - 1];
18396
+ if (isComma(last))
18383
18397
  args = args.slice(0, -1);
18384
- return [open, ws, args, close];
18398
+ return {
18399
+ type: "TypeArguments",
18400
+ ts: true,
18401
+ args,
18402
+ children: [open, ws, args, close]
18403
+ };
18385
18404
  });
18386
18405
  function ImplicitTypeArguments(ctx, state2) {
18387
18406
  return (0, import_lib4.$EVENT)(ctx, state2, "ImplicitTypeArguments", ImplicitTypeArguments$0);
@@ -18399,10 +18418,10 @@ ${js}`
18399
18418
  function ForbiddenImplicitTypeCalls(ctx, state2) {
18400
18419
  return (0, import_lib4.$EVENT_C)(ctx, state2, "ForbiddenImplicitTypeCalls", ForbiddenImplicitTypeCalls$$);
18401
18420
  }
18402
- var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), (0, import_lib4.$E)(_), TypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18421
+ var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), WTypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18403
18422
  return [
18404
18423
  $2,
18405
- ...$3.flatMap(([comma, eos, ws, arg]) => [comma, prepend(ws, arg)]),
18424
+ ...$3.flatMap(([comma, eos, arg]) => [comma, arg]),
18406
18425
  ...$4.flatMap(
18407
18426
  ([comma, args]) => Array.isArray(args) ? [comma, ...args] : [comma, args]
18408
18427
  )
@@ -18417,10 +18436,10 @@ ${js}`
18417
18436
  ];
18418
18437
  });
18419
18438
  var TypeArgumentList$2 = NestedTypeArgumentList;
18420
- var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$E)(_), TypeArgument))), function($skip, $loc, $0, $1, $2) {
18439
+ var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18421
18440
  return [
18422
18441
  $1,
18423
- ...$2.flatMap(([comma, ws, arg]) => [comma, prepend(ws, arg)])
18442
+ ...$2.flatMap(([comma, arg]) => [comma, arg])
18424
18443
  ];
18425
18444
  });
18426
18445
  var TypeArgumentList$$ = [TypeArgumentList$0, TypeArgumentList$1, TypeArgumentList$2, TypeArgumentList$3];
@@ -18447,17 +18466,25 @@ ${js}`
18447
18466
  function NestedTypeArgument(ctx, state2) {
18448
18467
  return (0, import_lib4.$EVENT)(ctx, state2, "NestedTypeArgument", NestedTypeArgument$0);
18449
18468
  }
18450
- var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), (0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument)))), function($skip, $loc, $0, $1, $2) {
18451
- return [$1, ...$2.flat()];
18469
+ var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(WTypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18470
+ return [$1, ...$2];
18452
18471
  });
18453
18472
  function SingleLineTypeArgumentList(ctx, state2) {
18454
18473
  return (0, import_lib4.$EVENT)(ctx, state2, "SingleLineTypeArgumentList", SingleLineTypeArgumentList$0);
18455
18474
  }
18475
+ var WTypeArgument$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), function($skip, $loc, $0, $1, $2) {
18476
+ return prepend($1, $2);
18477
+ });
18478
+ function WTypeArgument(ctx, state2) {
18479
+ return (0, import_lib4.$EVENT)(ctx, state2, "WTypeArgument", WTypeArgument$0);
18480
+ }
18456
18481
  var TypeArgumentDelimited$0 = (0, import_lib4.$S)(TypeArgument, TypeArgumentDelimiter);
18457
18482
  function TypeArgumentDelimited(ctx, state2) {
18458
18483
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgumentDelimited", TypeArgumentDelimited$0);
18459
18484
  }
18460
- var TypeArgument$0 = Type;
18485
+ var TypeArgument$0 = (0, import_lib4.$T)(Type, function(value) {
18486
+ return { "type": "TypeArgument", "ts": true, "t": value, "children": [value] };
18487
+ });
18461
18488
  function TypeArgument(ctx, state2) {
18462
18489
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgument", TypeArgument$0);
18463
18490
  }
package/dist/main.js CHANGED
@@ -538,6 +538,7 @@ __export(lib_exports, {
538
538
  hasImportDeclaration: () => hasImportDeclaration,
539
539
  hasYield: () => hasYield,
540
540
  insertTrimmingSpace: () => insertTrimmingSpace,
541
+ isComma: () => isComma,
541
542
  isEmptyBareBlock: () => isEmptyBareBlock,
542
543
  isFunction: () => isFunction,
543
544
  isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
@@ -2320,11 +2321,21 @@ function serialize(value, context) {
2320
2321
  }
2321
2322
 
2322
2323
  // source/parser/function.civet
2324
+ function getTypeArguments(args) {
2325
+ while (typeof args === "object" && args != null && "args" in args) {
2326
+ args = args.args;
2327
+ }
2328
+ if (!Array.isArray(args)) {
2329
+ throw new Error("getTypeArguments could not find relevant array");
2330
+ }
2331
+ return args.filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "TypeArgument");
2332
+ }
2323
2333
  function isVoidType(t) {
2324
- return t?.type === "TypeLiteral" && t.t.type === "VoidType";
2334
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeLiteral" && "t" in t && typeof t.t === "object" && t.t != null && "type" in t.t && t.t.type === "VoidType";
2325
2335
  }
2326
2336
  function isPromiseVoidType(t) {
2327
- return t?.type === "TypeIdentifier" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
2337
+ let args;
2338
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeIdentifier" && "raw" in t && t.raw === "Promise" && (args = getTypeArguments(t.args?.args)).length === 1 && isVoidType(args[0].t);
2328
2339
  }
2329
2340
  function implicitFunctionBlock(f) {
2330
2341
  if (f.abstract || f.block || f.signature?.optional)
@@ -2910,7 +2921,7 @@ function processParams(f) {
2910
2921
  if (isConstructor) {
2911
2922
  const { ancestor } = findAncestor(f, ($5) => $5.type === "ClassExpression");
2912
2923
  if (ancestor != null) {
2913
- const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "Identifier").map(($8) => $8.name));
2924
+ const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "Identifier").map(($8) => $8.name));
2914
2925
  const classExpressions = ancestor.body.expressions;
2915
2926
  let index = findChildIndex(classExpressions, f);
2916
2927
  assert.notEqual(index, -1, "Could not find constructor in class");
@@ -2962,10 +2973,10 @@ function processParams(f) {
2962
2973
  if (isConstructor) {
2963
2974
  const superCalls = gatherNodes(
2964
2975
  expressions,
2965
- (a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "CallExpression" && "children" in a1 && Array.isArray(a1.children) && a1.children.length >= 1 && typeof a1.children[0] === "object" && a1.children[0] != null && "token" in a1.children[0] && a1.children[0].token === "super"
2976
+ (a2) => typeof a2 === "object" && a2 != null && "type" in a2 && a2.type === "CallExpression" && "children" in a2 && Array.isArray(a2.children) && a2.children.length >= 1 && typeof a2.children[0] === "object" && a2.children[0] != null && "token" in a2.children[0] && a2.children[0].token === "super"
2966
2977
  );
2967
2978
  if (superCalls.length) {
2968
- const { child } = findAncestor(superCalls[0], (a2) => a2 === block);
2979
+ const { child } = findAncestor(superCalls[0], (a3) => a3 === block);
2969
2980
  const index = findChildIndex(expressions, child);
2970
2981
  if (index < 0) {
2971
2982
  throw new Error("Could not find super call within top-level expressions");
@@ -2975,6 +2986,7 @@ function processParams(f) {
2975
2986
  }
2976
2987
  }
2977
2988
  expressions.unshift(...prefix);
2989
+ braceBlock(block);
2978
2990
  }
2979
2991
  function processSignature(f) {
2980
2992
  const { block, signature } = f;
@@ -3097,11 +3109,11 @@ function processCoffeeDo(ws, expression) {
3097
3109
  parameter = {
3098
3110
  ...parameter,
3099
3111
  initializer: void 0,
3100
- children: parameter.children.filter((a3) => a3 !== initializer)
3112
+ children: parameter.children.filter((a4) => a4 !== initializer)
3101
3113
  };
3102
3114
  } else {
3103
3115
  args.push(parameter.children.filter(
3104
- (a4) => a4 !== parameter.typeSuffix
3116
+ (a5) => a5 !== parameter.typeSuffix
3105
3117
  ));
3106
3118
  }
3107
3119
  }
@@ -3174,7 +3186,7 @@ function makeAmpersandFunction(rhs) {
3174
3186
  }
3175
3187
  if (gatherRecursiveWithinFunction(
3176
3188
  block,
3177
- (a5) => a5 === ref
3189
+ (a6) => a6 === ref
3178
3190
  ).length > 1) {
3179
3191
  fn.ampersandBlock = false;
3180
3192
  }
@@ -8071,6 +8083,7 @@ var grammar = {
8071
8083
  NestedTypeArgumentList,
8072
8084
  NestedTypeArgument,
8073
8085
  SingleLineTypeArgumentList,
8086
+ WTypeArgument,
8074
8087
  TypeArgumentDelimited,
8075
8088
  TypeArgument,
8076
8089
  TypeArgumentDelimiter,
@@ -8932,10 +8945,10 @@ var RHS$$ = [RHS$0, RHS$1];
8932
8945
  function RHS(ctx, state2) {
8933
8946
  return (0, import_lib4.$EVENT_C)(ctx, state2, "RHS", RHS$$);
8934
8947
  }
8935
- var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4) {
8948
+ var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$N)(CallExpressionRest), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8936
8949
  var pre = $2;
8937
8950
  var args = $3;
8938
- var post = $4;
8951
+ var post = $5;
8939
8952
  return processUnaryNestedExpression(pre, args, post) ?? $skip;
8940
8953
  });
8941
8954
  var UnaryExpression$1 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$Q)(UnaryOp), UnaryBody, (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3) {
@@ -18338,11 +18351,12 @@ function TypeArrowFunction(ctx, state2) {
18338
18351
  }
18339
18352
  var TypeArguments$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(OpenAngleBracket, (0, import_lib4.$P)((0, import_lib4.$S)(__, TypeArgumentDelimited)), __, CloseAngleBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
18340
18353
  var args = $2;
18341
- args = args.map(([ws, arg]) => [ws, ...arg]);
18354
+ args = args.flatMap(([ws, [arg, delim]]) => [prepend(ws, arg), delim]);
18355
+ args.pop();
18342
18356
  return {
18343
18357
  type: "TypeArguments",
18344
18358
  ts: true,
18345
- types: args.map(([, t]) => t),
18359
+ args,
18346
18360
  children: $0
18347
18361
  };
18348
18362
  });
@@ -18354,10 +18368,15 @@ var ImplicitTypeArguments$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeAppli
18354
18368
  var ws = $3;
18355
18369
  var args = $4;
18356
18370
  var close = $5;
18357
- let last = args[args.length - 1];
18358
- if (last?.token === ",")
18371
+ const last = args[args.length - 1];
18372
+ if (isComma(last))
18359
18373
  args = args.slice(0, -1);
18360
- return [open, ws, args, close];
18374
+ return {
18375
+ type: "TypeArguments",
18376
+ ts: true,
18377
+ args,
18378
+ children: [open, ws, args, close]
18379
+ };
18361
18380
  });
18362
18381
  function ImplicitTypeArguments(ctx, state2) {
18363
18382
  return (0, import_lib4.$EVENT)(ctx, state2, "ImplicitTypeArguments", ImplicitTypeArguments$0);
@@ -18375,10 +18394,10 @@ var ForbiddenImplicitTypeCalls$$ = [ForbiddenImplicitTypeCalls$0, ForbiddenImpli
18375
18394
  function ForbiddenImplicitTypeCalls(ctx, state2) {
18376
18395
  return (0, import_lib4.$EVENT_C)(ctx, state2, "ForbiddenImplicitTypeCalls", ForbiddenImplicitTypeCalls$$);
18377
18396
  }
18378
- var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), (0, import_lib4.$E)(_), TypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18397
+ var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), WTypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18379
18398
  return [
18380
18399
  $2,
18381
- ...$3.flatMap(([comma, eos, ws, arg]) => [comma, prepend(ws, arg)]),
18400
+ ...$3.flatMap(([comma, eos, arg]) => [comma, arg]),
18382
18401
  ...$4.flatMap(
18383
18402
  ([comma, args]) => Array.isArray(args) ? [comma, ...args] : [comma, args]
18384
18403
  )
@@ -18393,10 +18412,10 @@ var TypeArgumentList$1 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib
18393
18412
  ];
18394
18413
  });
18395
18414
  var TypeArgumentList$2 = NestedTypeArgumentList;
18396
- var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$E)(_), TypeArgument))), function($skip, $loc, $0, $1, $2) {
18415
+ var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18397
18416
  return [
18398
18417
  $1,
18399
- ...$2.flatMap(([comma, ws, arg]) => [comma, prepend(ws, arg)])
18418
+ ...$2.flatMap(([comma, arg]) => [comma, arg])
18400
18419
  ];
18401
18420
  });
18402
18421
  var TypeArgumentList$$ = [TypeArgumentList$0, TypeArgumentList$1, TypeArgumentList$2, TypeArgumentList$3];
@@ -18423,17 +18442,25 @@ var NestedTypeArgument$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(Nested, Sing
18423
18442
  function NestedTypeArgument(ctx, state2) {
18424
18443
  return (0, import_lib4.$EVENT)(ctx, state2, "NestedTypeArgument", NestedTypeArgument$0);
18425
18444
  }
18426
- var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), (0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument)))), function($skip, $loc, $0, $1, $2) {
18427
- return [$1, ...$2.flat()];
18445
+ var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(WTypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18446
+ return [$1, ...$2];
18428
18447
  });
18429
18448
  function SingleLineTypeArgumentList(ctx, state2) {
18430
18449
  return (0, import_lib4.$EVENT)(ctx, state2, "SingleLineTypeArgumentList", SingleLineTypeArgumentList$0);
18431
18450
  }
18451
+ var WTypeArgument$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), function($skip, $loc, $0, $1, $2) {
18452
+ return prepend($1, $2);
18453
+ });
18454
+ function WTypeArgument(ctx, state2) {
18455
+ return (0, import_lib4.$EVENT)(ctx, state2, "WTypeArgument", WTypeArgument$0);
18456
+ }
18432
18457
  var TypeArgumentDelimited$0 = (0, import_lib4.$S)(TypeArgument, TypeArgumentDelimiter);
18433
18458
  function TypeArgumentDelimited(ctx, state2) {
18434
18459
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgumentDelimited", TypeArgumentDelimited$0);
18435
18460
  }
18436
- var TypeArgument$0 = Type;
18461
+ var TypeArgument$0 = (0, import_lib4.$T)(Type, function(value) {
18462
+ return { "type": "TypeArgument", "ts": true, "t": value, "children": [value] };
18463
+ });
18437
18464
  function TypeArgument(ctx, state2) {
18438
18465
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgument", TypeArgument$0);
18439
18466
  }
package/dist/main.mjs CHANGED
@@ -518,6 +518,7 @@ __export(lib_exports, {
518
518
  hasImportDeclaration: () => hasImportDeclaration,
519
519
  hasYield: () => hasYield,
520
520
  insertTrimmingSpace: () => insertTrimmingSpace,
521
+ isComma: () => isComma,
521
522
  isEmptyBareBlock: () => isEmptyBareBlock,
522
523
  isFunction: () => isFunction,
523
524
  isWhitespaceOrEmpty: () => isWhitespaceOrEmpty,
@@ -2300,11 +2301,21 @@ function serialize(value, context) {
2300
2301
  }
2301
2302
 
2302
2303
  // source/parser/function.civet
2304
+ function getTypeArguments(args) {
2305
+ while (typeof args === "object" && args != null && "args" in args) {
2306
+ args = args.args;
2307
+ }
2308
+ if (!Array.isArray(args)) {
2309
+ throw new Error("getTypeArguments could not find relevant array");
2310
+ }
2311
+ return args.filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "TypeArgument");
2312
+ }
2303
2313
  function isVoidType(t) {
2304
- return t?.type === "TypeLiteral" && t.t.type === "VoidType";
2314
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeLiteral" && "t" in t && typeof t.t === "object" && t.t != null && "type" in t.t && t.t.type === "VoidType";
2305
2315
  }
2306
2316
  function isPromiseVoidType(t) {
2307
- return t?.type === "TypeIdentifier" && t.raw === "Promise" && t.args?.types?.length === 1 && isVoidType(t.args.types[0]);
2317
+ let args;
2318
+ return typeof t === "object" && t != null && "type" in t && t.type === "TypeIdentifier" && "raw" in t && t.raw === "Promise" && (args = getTypeArguments(t.args?.args)).length === 1 && isVoidType(args[0].t);
2308
2319
  }
2309
2320
  function implicitFunctionBlock(f) {
2310
2321
  if (f.abstract || f.block || f.signature?.optional)
@@ -2890,7 +2901,7 @@ function processParams(f) {
2890
2901
  if (isConstructor) {
2891
2902
  const { ancestor } = findAncestor(f, ($5) => $5.type === "ClassExpression");
2892
2903
  if (ancestor != null) {
2893
- const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "Identifier").map(($8) => $8.name));
2904
+ const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($6) => $6.type === "FieldDefinition").map(($7) => $7.id).filter((a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "Identifier").map(($8) => $8.name));
2894
2905
  const classExpressions = ancestor.body.expressions;
2895
2906
  let index = findChildIndex(classExpressions, f);
2896
2907
  assert.notEqual(index, -1, "Could not find constructor in class");
@@ -2942,10 +2953,10 @@ function processParams(f) {
2942
2953
  if (isConstructor) {
2943
2954
  const superCalls = gatherNodes(
2944
2955
  expressions,
2945
- (a1) => typeof a1 === "object" && a1 != null && "type" in a1 && a1.type === "CallExpression" && "children" in a1 && Array.isArray(a1.children) && a1.children.length >= 1 && typeof a1.children[0] === "object" && a1.children[0] != null && "token" in a1.children[0] && a1.children[0].token === "super"
2956
+ (a2) => typeof a2 === "object" && a2 != null && "type" in a2 && a2.type === "CallExpression" && "children" in a2 && Array.isArray(a2.children) && a2.children.length >= 1 && typeof a2.children[0] === "object" && a2.children[0] != null && "token" in a2.children[0] && a2.children[0].token === "super"
2946
2957
  );
2947
2958
  if (superCalls.length) {
2948
- const { child } = findAncestor(superCalls[0], (a2) => a2 === block);
2959
+ const { child } = findAncestor(superCalls[0], (a3) => a3 === block);
2949
2960
  const index = findChildIndex(expressions, child);
2950
2961
  if (index < 0) {
2951
2962
  throw new Error("Could not find super call within top-level expressions");
@@ -2955,6 +2966,7 @@ function processParams(f) {
2955
2966
  }
2956
2967
  }
2957
2968
  expressions.unshift(...prefix);
2969
+ braceBlock(block);
2958
2970
  }
2959
2971
  function processSignature(f) {
2960
2972
  const { block, signature } = f;
@@ -3077,11 +3089,11 @@ function processCoffeeDo(ws, expression) {
3077
3089
  parameter = {
3078
3090
  ...parameter,
3079
3091
  initializer: void 0,
3080
- children: parameter.children.filter((a3) => a3 !== initializer)
3092
+ children: parameter.children.filter((a4) => a4 !== initializer)
3081
3093
  };
3082
3094
  } else {
3083
3095
  args.push(parameter.children.filter(
3084
- (a4) => a4 !== parameter.typeSuffix
3096
+ (a5) => a5 !== parameter.typeSuffix
3085
3097
  ));
3086
3098
  }
3087
3099
  }
@@ -3154,7 +3166,7 @@ function makeAmpersandFunction(rhs) {
3154
3166
  }
3155
3167
  if (gatherRecursiveWithinFunction(
3156
3168
  block,
3157
- (a5) => a5 === ref
3169
+ (a6) => a6 === ref
3158
3170
  ).length > 1) {
3159
3171
  fn.ampersandBlock = false;
3160
3172
  }
@@ -8051,6 +8063,7 @@ var grammar = {
8051
8063
  NestedTypeArgumentList,
8052
8064
  NestedTypeArgument,
8053
8065
  SingleLineTypeArgumentList,
8066
+ WTypeArgument,
8054
8067
  TypeArgumentDelimited,
8055
8068
  TypeArgument,
8056
8069
  TypeArgumentDelimiter,
@@ -8912,10 +8925,10 @@ var RHS$$ = [RHS$0, RHS$1];
8912
8925
  function RHS(ctx, state2) {
8913
8926
  return (0, import_lib4.$EVENT_C)(ctx, state2, "RHS", RHS$$);
8914
8927
  }
8915
- var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4) {
8928
+ var UnaryExpression$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(IndentedApplicationAllowed, (0, import_lib4.$P)(UnaryOp), (0, import_lib4.$C)(ArrayLiteral, NestedArgumentList), (0, import_lib4.$N)(CallExpressionRest), (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
8916
8929
  var pre = $2;
8917
8930
  var args = $3;
8918
- var post = $4;
8931
+ var post = $5;
8919
8932
  return processUnaryNestedExpression(pre, args, post) ?? $skip;
8920
8933
  });
8921
8934
  var UnaryExpression$1 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$Q)(UnaryOp), UnaryBody, (0, import_lib4.$E)(UnaryPostfix)), function($skip, $loc, $0, $1, $2, $3) {
@@ -18318,11 +18331,12 @@ function TypeArrowFunction(ctx, state2) {
18318
18331
  }
18319
18332
  var TypeArguments$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(OpenAngleBracket, (0, import_lib4.$P)((0, import_lib4.$S)(__, TypeArgumentDelimited)), __, CloseAngleBracket), function($skip, $loc, $0, $1, $2, $3, $4) {
18320
18333
  var args = $2;
18321
- args = args.map(([ws, arg]) => [ws, ...arg]);
18334
+ args = args.flatMap(([ws, [arg, delim]]) => [prepend(ws, arg), delim]);
18335
+ args.pop();
18322
18336
  return {
18323
18337
  type: "TypeArguments",
18324
18338
  ts: true,
18325
- types: args.map(([, t]) => t),
18339
+ args,
18326
18340
  children: $0
18327
18341
  };
18328
18342
  });
@@ -18334,10 +18348,15 @@ var ImplicitTypeArguments$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeAppli
18334
18348
  var ws = $3;
18335
18349
  var args = $4;
18336
18350
  var close = $5;
18337
- let last = args[args.length - 1];
18338
- if (last?.token === ",")
18351
+ const last = args[args.length - 1];
18352
+ if (isComma(last))
18339
18353
  args = args.slice(0, -1);
18340
- return [open, ws, args, close];
18354
+ return {
18355
+ type: "TypeArguments",
18356
+ ts: true,
18357
+ args,
18358
+ children: [open, ws, args, close]
18359
+ };
18341
18360
  });
18342
18361
  function ImplicitTypeArguments(ctx, state2) {
18343
18362
  return (0, import_lib4.$EVENT)(ctx, state2, "ImplicitTypeArguments", ImplicitTypeArguments$0);
@@ -18355,10 +18374,10 @@ var ForbiddenImplicitTypeCalls$$ = [ForbiddenImplicitTypeCalls$0, ForbiddenImpli
18355
18374
  function ForbiddenImplicitTypeCalls(ctx, state2) {
18356
18375
  return (0, import_lib4.$EVENT_C)(ctx, state2, "ForbiddenImplicitTypeCalls", ForbiddenImplicitTypeCalls$$);
18357
18376
  }
18358
- var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), (0, import_lib4.$E)(_), TypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18377
+ var TypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$N)(EOS), TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$N)(EOS), WTypeArgument)), (0, import_lib4.$P)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$C)(NestedTypeBulletedTuple, NestedInterfaceBlock, NestedTypeArgumentList)))), function($skip, $loc, $0, $1, $2, $3, $4) {
18359
18378
  return [
18360
18379
  $2,
18361
- ...$3.flatMap(([comma, eos, ws, arg]) => [comma, prepend(ws, arg)]),
18380
+ ...$3.flatMap(([comma, eos, arg]) => [comma, arg]),
18362
18381
  ...$4.flatMap(
18363
18382
  ([comma, args]) => Array.isArray(args) ? [comma, ...args] : [comma, args]
18364
18383
  )
@@ -18373,10 +18392,10 @@ var TypeArgumentList$1 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib
18373
18392
  ];
18374
18393
  });
18375
18394
  var TypeArgumentList$2 = NestedTypeArgumentList;
18376
- var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, (0, import_lib4.$E)(_), TypeArgument))), function($skip, $loc, $0, $1, $2) {
18395
+ var TypeArgumentList$3 = (0, import_lib4.$TS)((0, import_lib4.$S)(TypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)(CommaDelimiter, WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18377
18396
  return [
18378
18397
  $1,
18379
- ...$2.flatMap(([comma, ws, arg]) => [comma, prepend(ws, arg)])
18398
+ ...$2.flatMap(([comma, arg]) => [comma, arg])
18380
18399
  ];
18381
18400
  });
18382
18401
  var TypeArgumentList$$ = [TypeArgumentList$0, TypeArgumentList$1, TypeArgumentList$2, TypeArgumentList$3];
@@ -18403,17 +18422,25 @@ var NestedTypeArgument$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(Nested, Sing
18403
18422
  function NestedTypeArgument(ctx, state2) {
18404
18423
  return (0, import_lib4.$EVENT)(ctx, state2, "NestedTypeArgument", NestedTypeArgument$0);
18405
18424
  }
18406
- var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), (0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument)))), function($skip, $loc, $0, $1, $2) {
18407
- return [$1, ...$2.flat()];
18425
+ var SingleLineTypeArgumentList$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(WTypeArgument, (0, import_lib4.$Q)((0, import_lib4.$S)((0, import_lib4.$S)((0, import_lib4.$E)(_), Comma), WTypeArgument))), function($skip, $loc, $0, $1, $2) {
18426
+ return [$1, ...$2];
18408
18427
  });
18409
18428
  function SingleLineTypeArgumentList(ctx, state2) {
18410
18429
  return (0, import_lib4.$EVENT)(ctx, state2, "SingleLineTypeArgumentList", SingleLineTypeArgumentList$0);
18411
18430
  }
18431
+ var WTypeArgument$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$E)(_), TypeArgument), function($skip, $loc, $0, $1, $2) {
18432
+ return prepend($1, $2);
18433
+ });
18434
+ function WTypeArgument(ctx, state2) {
18435
+ return (0, import_lib4.$EVENT)(ctx, state2, "WTypeArgument", WTypeArgument$0);
18436
+ }
18412
18437
  var TypeArgumentDelimited$0 = (0, import_lib4.$S)(TypeArgument, TypeArgumentDelimiter);
18413
18438
  function TypeArgumentDelimited(ctx, state2) {
18414
18439
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgumentDelimited", TypeArgumentDelimited$0);
18415
18440
  }
18416
- var TypeArgument$0 = Type;
18441
+ var TypeArgument$0 = (0, import_lib4.$T)(Type, function(value) {
18442
+ return { "type": "TypeArgument", "ts": true, "t": value, "children": [value] };
18443
+ });
18417
18444
  function TypeArgument(ctx, state2) {
18418
18445
  return (0, import_lib4.$EVENT)(ctx, state2, "TypeArgument", TypeArgument$0);
18419
18446
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.8.6",
4
+ "version": "0.8.7",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",