@danielx/civet 0.8.2 → 0.8.3

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,9 @@ 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.3 (2024-10-15, [diff](https://github.com/DanielXMoore/Civet/compare/v0.8.2...v0.8.3), [commits](https://github.com/DanielXMoore/Civet/commits/v0.8.3))
8
+ * Automatically type fields using `@arg` in constructor [[#1469](https://github.com/DanielXMoore/Civet/pull/1469)]
9
+
7
10
  ## 0.8.2 (2024-10-14, [diff](https://github.com/DanielXMoore/Civet/compare/v0.8.1...v0.8.2), [commits](https://github.com/DanielXMoore/Civet/commits/v0.8.2))
8
11
  * Compiler directives `iife` and `repl` for wrapping program, fix `comptime` implicitly returned from function [[#1463](https://github.com/DanielXMoore/Civet/pull/1463)]
9
12
  * `repl` directive hoists function and class declarations too, fix one-line declarations in `if` [[#1466](https://github.com/DanielXMoore/Civet/pull/1466)]
package/dist/browser.js CHANGED
@@ -2855,12 +2855,13 @@ ${js}`
2855
2855
  if (type === "ArrowFunction" && parameters && parameters.tp && parameters.tp.parameters.length === 1) {
2856
2856
  parameters.tp.parameters.push(",");
2857
2857
  }
2858
- if (!block)
2858
+ if (!block) {
2859
2859
  return;
2860
+ }
2860
2861
  const { expressions } = block;
2861
- if (!expressions)
2862
+ if (!expressions) {
2862
2863
  return;
2863
- const { blockPrefix } = parameters;
2864
+ }
2864
2865
  let indent;
2865
2866
  if (!expressions.length) {
2866
2867
  indent = "";
@@ -2870,6 +2871,45 @@ ${js}`
2870
2871
  const [splices, thisAssignments] = gatherBindingCode(parameters, {
2871
2872
  injectParamProps: isConstructor
2872
2873
  });
2874
+ if (isConstructor) {
2875
+ const { ancestor } = findAncestor(f, ($4) => $4.type === "ClassExpression");
2876
+ if (ancestor != null) {
2877
+ const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($5) => $5.type === "FieldDefinition").map(($6) => $6.id).filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "Identifier").map(($7) => $7.name));
2878
+ const classExpressions = ancestor.body.expressions;
2879
+ let index = findChildIndex(classExpressions, f);
2880
+ assert.notEqual(index, -1, "Could not find constructor in class");
2881
+ let m2;
2882
+ while (m2 = classExpressions[index - 1]?.[1], typeof m2 === "object" && m2 != null && "type" in m2 && m2.type === "MethodDefinition" && "name" in m2 && m2.name === "constructor") {
2883
+ index--;
2884
+ }
2885
+ const fStatement = classExpressions[index];
2886
+ for (let ref8 = gatherRecursive(parameters, ($8) => $8.type === "Parameter"), i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
2887
+ const parameter = ref8[i1];
2888
+ if (!parameter.typeSuffix) {
2889
+ continue;
2890
+ }
2891
+ for (let ref9 = gatherRecursive(parameter, ($9) => $9.type === "AtBinding"), i2 = 0, len1 = ref9.length; i2 < len1; i2++) {
2892
+ const binding = ref9[i2];
2893
+ const typeSuffix = binding.parent?.typeSuffix;
2894
+ if (!typeSuffix) {
2895
+ continue;
2896
+ }
2897
+ const id = binding.ref.id;
2898
+ if (fields.has(id)) {
2899
+ continue;
2900
+ }
2901
+ classExpressions.splice(index++, 0, [fStatement[0], {
2902
+ type: "FieldDefinition",
2903
+ ts: true,
2904
+ id,
2905
+ typeSuffix,
2906
+ children: [id, typeSuffix]
2907
+ }, ";"]);
2908
+ fStatement[0] = "";
2909
+ }
2910
+ }
2911
+ }
2912
+ }
2873
2913
  const delimiter = {
2874
2914
  type: "SemicolonDelimiter",
2875
2915
  children: [";"]
@@ -2881,15 +2921,16 @@ ${js}`
2881
2921
  children: [indent, ...s.children, delimiter]
2882
2922
  } : [indent, s, delimiter]
2883
2923
  );
2884
- if (!prefix.length)
2924
+ if (!prefix.length) {
2885
2925
  return;
2926
+ }
2886
2927
  if (isConstructor) {
2887
2928
  const superCalls = gatherNodes(
2888
2929
  expressions,
2889
- (a) => typeof a === "object" && a != null && "type" in a && a.type === "CallExpression" && "children" in a && Array.isArray(a.children) && a.children.length >= 1 && typeof a.children[0] === "object" && a.children[0] != null && "token" in a.children[0] && a.children[0].token === "super"
2930
+ (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"
2890
2931
  );
2891
2932
  if (superCalls.length) {
2892
- const { child } = findAncestor(superCalls[0], (a1) => a1 === block);
2933
+ const { child } = findAncestor(superCalls[0], (a2) => a2 === block);
2893
2934
  const index = findChildIndex(expressions, child);
2894
2935
  if (index < 0) {
2895
2936
  throw new Error("Could not find super call within top-level expressions");
@@ -2908,8 +2949,8 @@ ${js}`
2908
2949
  }
2909
2950
  if (hasYield(block) && !f.generator?.length) {
2910
2951
  if (f.type === "ArrowFunction") {
2911
- gatherRecursiveWithinFunction(block, ($4) => $4.type === "YieldExpression").forEach((y) => {
2912
- const i = y.children.findIndex(($5) => $5.type === "Yield");
2952
+ gatherRecursiveWithinFunction(block, ($10) => $10.type === "YieldExpression").forEach((y) => {
2953
+ const i = y.children.findIndex(($11) => $11.type === "Yield");
2913
2954
  return y.children.splice(i + 1, 0, {
2914
2955
  type: "Error",
2915
2956
  message: "Can't use yield inside of => arrow function"
@@ -3010,21 +3051,21 @@ ${js}`
3010
3051
  ...parameters,
3011
3052
  children: (() => {
3012
3053
  const results1 = [];
3013
- for (let ref8 = parameters.children, i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
3014
- let parameter = ref8[i1];
3054
+ for (let ref10 = parameters.children, i3 = 0, len22 = ref10.length; i3 < len22; i3++) {
3055
+ let parameter = ref10[i3];
3015
3056
  if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
3016
- let ref9;
3017
- if (ref9 = parameter.initializer) {
3018
- const initializer = ref9;
3057
+ let ref11;
3058
+ if (ref11 = parameter.initializer) {
3059
+ const initializer = ref11;
3019
3060
  args.push(initializer.expression, parameter.delim);
3020
3061
  parameter = {
3021
3062
  ...parameter,
3022
3063
  initializer: void 0,
3023
- children: parameter.children.filter((a2) => a2 !== initializer)
3064
+ children: parameter.children.filter((a3) => a3 !== initializer)
3024
3065
  };
3025
3066
  } else {
3026
3067
  args.push(parameter.children.filter(
3027
- (a3) => a3 !== parameter.typeSuffix
3068
+ (a4) => a4 !== parameter.typeSuffix
3028
3069
  ));
3029
3070
  }
3030
3071
  }
@@ -3036,7 +3077,7 @@ ${js}`
3036
3077
  expression = {
3037
3078
  ...expression,
3038
3079
  parameters: newParameters,
3039
- children: expression.children.map(($6) => $6 === parameters ? newParameters : $6)
3080
+ children: expression.children.map(($12) => $12 === parameters ? newParameters : $12)
3040
3081
  };
3041
3082
  }
3042
3083
  return {
@@ -3058,7 +3099,7 @@ ${js}`
3058
3099
  ref = makeRef("$");
3059
3100
  inplacePrepend(ref, body);
3060
3101
  }
3061
- if (startsWithPredicate(body, ($7) => $7.type === "ObjectExpression")) {
3102
+ if (startsWithPredicate(body, ($13) => $13.type === "ObjectExpression")) {
3062
3103
  body = makeLeftHandSideExpression(body);
3063
3104
  }
3064
3105
  const parameters = makeNode({
@@ -3097,7 +3138,7 @@ ${js}`
3097
3138
  }
3098
3139
  if (gatherRecursiveWithinFunction(
3099
3140
  block,
3100
- (a4) => a4 === ref
3141
+ (a5) => a5 === ref
3101
3142
  ).length > 1) {
3102
3143
  fn.ampersandBlock = false;
3103
3144
  }
@@ -9386,12 +9427,15 @@ ${js}`
9386
9427
  default:
9387
9428
  return {
9388
9429
  type: "FieldDefinition",
9430
+ id,
9389
9431
  children: [id, " = ", exp]
9390
9432
  };
9391
9433
  }
9392
9434
  });
9393
9435
  var FieldDefinition$1 = (0, import_lib4.$TS)((0, import_lib4.$S)(InsertReadonly, ClassElementName, (0, import_lib4.$E)(TypeSuffix), __, ConstAssignment, MaybeNestedExpression), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
9394
9436
  var r = $1;
9437
+ var id = $2;
9438
+ var typeSuffix = $3;
9395
9439
  var ca = $5;
9396
9440
  r.children[0].$loc = {
9397
9441
  pos: ca.$loc.pos - 1,
@@ -9399,15 +9443,20 @@ ${js}`
9399
9443
  };
9400
9444
  return {
9401
9445
  type: "FieldDefinition",
9446
+ id,
9447
+ typeSuffix,
9402
9448
  children: $0
9403
9449
  };
9404
9450
  });
9405
9451
  var FieldDefinition$2 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$E)((0, import_lib4.$S)(Abstract, (0, import_lib4.$E)(_))), (0, import_lib4.$E)((0, import_lib4.$S)(Readonly, (0, import_lib4.$E)(_))), ClassElementName, (0, import_lib4.$E)(TypeSuffix), (0, import_lib4.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
9406
- if ($1)
9407
- return { children: $0, ts: true };
9452
+ var id = $3;
9453
+ var typeSuffix = $4;
9408
9454
  return {
9409
9455
  type: "FieldDefinition",
9410
- children: $0
9456
+ children: $0,
9457
+ ts: $1 ? true : void 0,
9458
+ id,
9459
+ typeSuffix
9411
9460
  };
9412
9461
  });
9413
9462
  var FieldDefinition$$ = [FieldDefinition$0, FieldDefinition$1, FieldDefinition$2];
@@ -10142,7 +10191,8 @@ ${js}`
10142
10191
  typeSuffix,
10143
10192
  accessModifier,
10144
10193
  initializer,
10145
- delim
10194
+ delim,
10195
+ binding
10146
10196
  };
10147
10197
  });
10148
10198
  function ParameterElement(ctx, state2) {
package/dist/main.js CHANGED
@@ -2831,12 +2831,13 @@ function processParams(f) {
2831
2831
  if (type === "ArrowFunction" && parameters && parameters.tp && parameters.tp.parameters.length === 1) {
2832
2832
  parameters.tp.parameters.push(",");
2833
2833
  }
2834
- if (!block)
2834
+ if (!block) {
2835
2835
  return;
2836
+ }
2836
2837
  const { expressions } = block;
2837
- if (!expressions)
2838
+ if (!expressions) {
2838
2839
  return;
2839
- const { blockPrefix } = parameters;
2840
+ }
2840
2841
  let indent;
2841
2842
  if (!expressions.length) {
2842
2843
  indent = "";
@@ -2846,6 +2847,45 @@ function processParams(f) {
2846
2847
  const [splices, thisAssignments] = gatherBindingCode(parameters, {
2847
2848
  injectParamProps: isConstructor
2848
2849
  });
2850
+ if (isConstructor) {
2851
+ const { ancestor } = findAncestor(f, ($4) => $4.type === "ClassExpression");
2852
+ if (ancestor != null) {
2853
+ const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($5) => $5.type === "FieldDefinition").map(($6) => $6.id).filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "Identifier").map(($7) => $7.name));
2854
+ const classExpressions = ancestor.body.expressions;
2855
+ let index = findChildIndex(classExpressions, f);
2856
+ assert.notEqual(index, -1, "Could not find constructor in class");
2857
+ let m2;
2858
+ while (m2 = classExpressions[index - 1]?.[1], typeof m2 === "object" && m2 != null && "type" in m2 && m2.type === "MethodDefinition" && "name" in m2 && m2.name === "constructor") {
2859
+ index--;
2860
+ }
2861
+ const fStatement = classExpressions[index];
2862
+ for (let ref8 = gatherRecursive(parameters, ($8) => $8.type === "Parameter"), i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
2863
+ const parameter = ref8[i1];
2864
+ if (!parameter.typeSuffix) {
2865
+ continue;
2866
+ }
2867
+ for (let ref9 = gatherRecursive(parameter, ($9) => $9.type === "AtBinding"), i2 = 0, len1 = ref9.length; i2 < len1; i2++) {
2868
+ const binding = ref9[i2];
2869
+ const typeSuffix = binding.parent?.typeSuffix;
2870
+ if (!typeSuffix) {
2871
+ continue;
2872
+ }
2873
+ const id = binding.ref.id;
2874
+ if (fields.has(id)) {
2875
+ continue;
2876
+ }
2877
+ classExpressions.splice(index++, 0, [fStatement[0], {
2878
+ type: "FieldDefinition",
2879
+ ts: true,
2880
+ id,
2881
+ typeSuffix,
2882
+ children: [id, typeSuffix]
2883
+ }, ";"]);
2884
+ fStatement[0] = "";
2885
+ }
2886
+ }
2887
+ }
2888
+ }
2849
2889
  const delimiter = {
2850
2890
  type: "SemicolonDelimiter",
2851
2891
  children: [";"]
@@ -2857,15 +2897,16 @@ function processParams(f) {
2857
2897
  children: [indent, ...s.children, delimiter]
2858
2898
  } : [indent, s, delimiter]
2859
2899
  );
2860
- if (!prefix.length)
2900
+ if (!prefix.length) {
2861
2901
  return;
2902
+ }
2862
2903
  if (isConstructor) {
2863
2904
  const superCalls = gatherNodes(
2864
2905
  expressions,
2865
- (a) => typeof a === "object" && a != null && "type" in a && a.type === "CallExpression" && "children" in a && Array.isArray(a.children) && a.children.length >= 1 && typeof a.children[0] === "object" && a.children[0] != null && "token" in a.children[0] && a.children[0].token === "super"
2906
+ (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"
2866
2907
  );
2867
2908
  if (superCalls.length) {
2868
- const { child } = findAncestor(superCalls[0], (a1) => a1 === block);
2909
+ const { child } = findAncestor(superCalls[0], (a2) => a2 === block);
2869
2910
  const index = findChildIndex(expressions, child);
2870
2911
  if (index < 0) {
2871
2912
  throw new Error("Could not find super call within top-level expressions");
@@ -2884,8 +2925,8 @@ function processSignature(f) {
2884
2925
  }
2885
2926
  if (hasYield(block) && !f.generator?.length) {
2886
2927
  if (f.type === "ArrowFunction") {
2887
- gatherRecursiveWithinFunction(block, ($4) => $4.type === "YieldExpression").forEach((y) => {
2888
- const i = y.children.findIndex(($5) => $5.type === "Yield");
2928
+ gatherRecursiveWithinFunction(block, ($10) => $10.type === "YieldExpression").forEach((y) => {
2929
+ const i = y.children.findIndex(($11) => $11.type === "Yield");
2889
2930
  return y.children.splice(i + 1, 0, {
2890
2931
  type: "Error",
2891
2932
  message: "Can't use yield inside of => arrow function"
@@ -2986,21 +3027,21 @@ function processCoffeeDo(ws, expression) {
2986
3027
  ...parameters,
2987
3028
  children: (() => {
2988
3029
  const results1 = [];
2989
- for (let ref8 = parameters.children, i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
2990
- let parameter = ref8[i1];
3030
+ for (let ref10 = parameters.children, i3 = 0, len22 = ref10.length; i3 < len22; i3++) {
3031
+ let parameter = ref10[i3];
2991
3032
  if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
2992
- let ref9;
2993
- if (ref9 = parameter.initializer) {
2994
- const initializer = ref9;
3033
+ let ref11;
3034
+ if (ref11 = parameter.initializer) {
3035
+ const initializer = ref11;
2995
3036
  args.push(initializer.expression, parameter.delim);
2996
3037
  parameter = {
2997
3038
  ...parameter,
2998
3039
  initializer: void 0,
2999
- children: parameter.children.filter((a2) => a2 !== initializer)
3040
+ children: parameter.children.filter((a3) => a3 !== initializer)
3000
3041
  };
3001
3042
  } else {
3002
3043
  args.push(parameter.children.filter(
3003
- (a3) => a3 !== parameter.typeSuffix
3044
+ (a4) => a4 !== parameter.typeSuffix
3004
3045
  ));
3005
3046
  }
3006
3047
  }
@@ -3012,7 +3053,7 @@ function processCoffeeDo(ws, expression) {
3012
3053
  expression = {
3013
3054
  ...expression,
3014
3055
  parameters: newParameters,
3015
- children: expression.children.map(($6) => $6 === parameters ? newParameters : $6)
3056
+ children: expression.children.map(($12) => $12 === parameters ? newParameters : $12)
3016
3057
  };
3017
3058
  }
3018
3059
  return {
@@ -3034,7 +3075,7 @@ function makeAmpersandFunction(rhs) {
3034
3075
  ref = makeRef("$");
3035
3076
  inplacePrepend(ref, body);
3036
3077
  }
3037
- if (startsWithPredicate(body, ($7) => $7.type === "ObjectExpression")) {
3078
+ if (startsWithPredicate(body, ($13) => $13.type === "ObjectExpression")) {
3038
3079
  body = makeLeftHandSideExpression(body);
3039
3080
  }
3040
3081
  const parameters = makeNode({
@@ -3073,7 +3114,7 @@ function makeAmpersandFunction(rhs) {
3073
3114
  }
3074
3115
  if (gatherRecursiveWithinFunction(
3075
3116
  block,
3076
- (a4) => a4 === ref
3117
+ (a5) => a5 === ref
3077
3118
  ).length > 1) {
3078
3119
  fn.ampersandBlock = false;
3079
3120
  }
@@ -9362,12 +9403,15 @@ var FieldDefinition$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(CoffeeClassesEn
9362
9403
  default:
9363
9404
  return {
9364
9405
  type: "FieldDefinition",
9406
+ id,
9365
9407
  children: [id, " = ", exp]
9366
9408
  };
9367
9409
  }
9368
9410
  });
9369
9411
  var FieldDefinition$1 = (0, import_lib4.$TS)((0, import_lib4.$S)(InsertReadonly, ClassElementName, (0, import_lib4.$E)(TypeSuffix), __, ConstAssignment, MaybeNestedExpression), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
9370
9412
  var r = $1;
9413
+ var id = $2;
9414
+ var typeSuffix = $3;
9371
9415
  var ca = $5;
9372
9416
  r.children[0].$loc = {
9373
9417
  pos: ca.$loc.pos - 1,
@@ -9375,15 +9419,20 @@ var FieldDefinition$1 = (0, import_lib4.$TS)((0, import_lib4.$S)(InsertReadonly,
9375
9419
  };
9376
9420
  return {
9377
9421
  type: "FieldDefinition",
9422
+ id,
9423
+ typeSuffix,
9378
9424
  children: $0
9379
9425
  };
9380
9426
  });
9381
9427
  var FieldDefinition$2 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$E)((0, import_lib4.$S)(Abstract, (0, import_lib4.$E)(_))), (0, import_lib4.$E)((0, import_lib4.$S)(Readonly, (0, import_lib4.$E)(_))), ClassElementName, (0, import_lib4.$E)(TypeSuffix), (0, import_lib4.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
9382
- if ($1)
9383
- return { children: $0, ts: true };
9428
+ var id = $3;
9429
+ var typeSuffix = $4;
9384
9430
  return {
9385
9431
  type: "FieldDefinition",
9386
- children: $0
9432
+ children: $0,
9433
+ ts: $1 ? true : void 0,
9434
+ id,
9435
+ typeSuffix
9387
9436
  };
9388
9437
  });
9389
9438
  var FieldDefinition$$ = [FieldDefinition$0, FieldDefinition$1, FieldDefinition$2];
@@ -10118,7 +10167,8 @@ var ParameterElement$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib
10118
10167
  typeSuffix,
10119
10168
  accessModifier,
10120
10169
  initializer,
10121
- delim
10170
+ delim,
10171
+ binding
10122
10172
  };
10123
10173
  });
10124
10174
  function ParameterElement(ctx, state2) {
package/dist/main.mjs CHANGED
@@ -2811,12 +2811,13 @@ function processParams(f) {
2811
2811
  if (type === "ArrowFunction" && parameters && parameters.tp && parameters.tp.parameters.length === 1) {
2812
2812
  parameters.tp.parameters.push(",");
2813
2813
  }
2814
- if (!block)
2814
+ if (!block) {
2815
2815
  return;
2816
+ }
2816
2817
  const { expressions } = block;
2817
- if (!expressions)
2818
+ if (!expressions) {
2818
2819
  return;
2819
- const { blockPrefix } = parameters;
2820
+ }
2820
2821
  let indent;
2821
2822
  if (!expressions.length) {
2822
2823
  indent = "";
@@ -2826,6 +2827,45 @@ function processParams(f) {
2826
2827
  const [splices, thisAssignments] = gatherBindingCode(parameters, {
2827
2828
  injectParamProps: isConstructor
2828
2829
  });
2830
+ if (isConstructor) {
2831
+ const { ancestor } = findAncestor(f, ($4) => $4.type === "ClassExpression");
2832
+ if (ancestor != null) {
2833
+ const fields = new Set(gatherRecursiveWithinFunction(ancestor, ($5) => $5.type === "FieldDefinition").map(($6) => $6.id).filter((a) => typeof a === "object" && a != null && "type" in a && a.type === "Identifier").map(($7) => $7.name));
2834
+ const classExpressions = ancestor.body.expressions;
2835
+ let index = findChildIndex(classExpressions, f);
2836
+ assert.notEqual(index, -1, "Could not find constructor in class");
2837
+ let m2;
2838
+ while (m2 = classExpressions[index - 1]?.[1], typeof m2 === "object" && m2 != null && "type" in m2 && m2.type === "MethodDefinition" && "name" in m2 && m2.name === "constructor") {
2839
+ index--;
2840
+ }
2841
+ const fStatement = classExpressions[index];
2842
+ for (let ref8 = gatherRecursive(parameters, ($8) => $8.type === "Parameter"), i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
2843
+ const parameter = ref8[i1];
2844
+ if (!parameter.typeSuffix) {
2845
+ continue;
2846
+ }
2847
+ for (let ref9 = gatherRecursive(parameter, ($9) => $9.type === "AtBinding"), i2 = 0, len1 = ref9.length; i2 < len1; i2++) {
2848
+ const binding = ref9[i2];
2849
+ const typeSuffix = binding.parent?.typeSuffix;
2850
+ if (!typeSuffix) {
2851
+ continue;
2852
+ }
2853
+ const id = binding.ref.id;
2854
+ if (fields.has(id)) {
2855
+ continue;
2856
+ }
2857
+ classExpressions.splice(index++, 0, [fStatement[0], {
2858
+ type: "FieldDefinition",
2859
+ ts: true,
2860
+ id,
2861
+ typeSuffix,
2862
+ children: [id, typeSuffix]
2863
+ }, ";"]);
2864
+ fStatement[0] = "";
2865
+ }
2866
+ }
2867
+ }
2868
+ }
2829
2869
  const delimiter = {
2830
2870
  type: "SemicolonDelimiter",
2831
2871
  children: [";"]
@@ -2837,15 +2877,16 @@ function processParams(f) {
2837
2877
  children: [indent, ...s.children, delimiter]
2838
2878
  } : [indent, s, delimiter]
2839
2879
  );
2840
- if (!prefix.length)
2880
+ if (!prefix.length) {
2841
2881
  return;
2882
+ }
2842
2883
  if (isConstructor) {
2843
2884
  const superCalls = gatherNodes(
2844
2885
  expressions,
2845
- (a) => typeof a === "object" && a != null && "type" in a && a.type === "CallExpression" && "children" in a && Array.isArray(a.children) && a.children.length >= 1 && typeof a.children[0] === "object" && a.children[0] != null && "token" in a.children[0] && a.children[0].token === "super"
2886
+ (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"
2846
2887
  );
2847
2888
  if (superCalls.length) {
2848
- const { child } = findAncestor(superCalls[0], (a1) => a1 === block);
2889
+ const { child } = findAncestor(superCalls[0], (a2) => a2 === block);
2849
2890
  const index = findChildIndex(expressions, child);
2850
2891
  if (index < 0) {
2851
2892
  throw new Error("Could not find super call within top-level expressions");
@@ -2864,8 +2905,8 @@ function processSignature(f) {
2864
2905
  }
2865
2906
  if (hasYield(block) && !f.generator?.length) {
2866
2907
  if (f.type === "ArrowFunction") {
2867
- gatherRecursiveWithinFunction(block, ($4) => $4.type === "YieldExpression").forEach((y) => {
2868
- const i = y.children.findIndex(($5) => $5.type === "Yield");
2908
+ gatherRecursiveWithinFunction(block, ($10) => $10.type === "YieldExpression").forEach((y) => {
2909
+ const i = y.children.findIndex(($11) => $11.type === "Yield");
2869
2910
  return y.children.splice(i + 1, 0, {
2870
2911
  type: "Error",
2871
2912
  message: "Can't use yield inside of => arrow function"
@@ -2966,21 +3007,21 @@ function processCoffeeDo(ws, expression) {
2966
3007
  ...parameters,
2967
3008
  children: (() => {
2968
3009
  const results1 = [];
2969
- for (let ref8 = parameters.children, i1 = 0, len3 = ref8.length; i1 < len3; i1++) {
2970
- let parameter = ref8[i1];
3010
+ for (let ref10 = parameters.children, i3 = 0, len22 = ref10.length; i3 < len22; i3++) {
3011
+ let parameter = ref10[i3];
2971
3012
  if (typeof parameter === "object" && parameter != null && "type" in parameter && parameter.type === "Parameter") {
2972
- let ref9;
2973
- if (ref9 = parameter.initializer) {
2974
- const initializer = ref9;
3013
+ let ref11;
3014
+ if (ref11 = parameter.initializer) {
3015
+ const initializer = ref11;
2975
3016
  args.push(initializer.expression, parameter.delim);
2976
3017
  parameter = {
2977
3018
  ...parameter,
2978
3019
  initializer: void 0,
2979
- children: parameter.children.filter((a2) => a2 !== initializer)
3020
+ children: parameter.children.filter((a3) => a3 !== initializer)
2980
3021
  };
2981
3022
  } else {
2982
3023
  args.push(parameter.children.filter(
2983
- (a3) => a3 !== parameter.typeSuffix
3024
+ (a4) => a4 !== parameter.typeSuffix
2984
3025
  ));
2985
3026
  }
2986
3027
  }
@@ -2992,7 +3033,7 @@ function processCoffeeDo(ws, expression) {
2992
3033
  expression = {
2993
3034
  ...expression,
2994
3035
  parameters: newParameters,
2995
- children: expression.children.map(($6) => $6 === parameters ? newParameters : $6)
3036
+ children: expression.children.map(($12) => $12 === parameters ? newParameters : $12)
2996
3037
  };
2997
3038
  }
2998
3039
  return {
@@ -3014,7 +3055,7 @@ function makeAmpersandFunction(rhs) {
3014
3055
  ref = makeRef("$");
3015
3056
  inplacePrepend(ref, body);
3016
3057
  }
3017
- if (startsWithPredicate(body, ($7) => $7.type === "ObjectExpression")) {
3058
+ if (startsWithPredicate(body, ($13) => $13.type === "ObjectExpression")) {
3018
3059
  body = makeLeftHandSideExpression(body);
3019
3060
  }
3020
3061
  const parameters = makeNode({
@@ -3053,7 +3094,7 @@ function makeAmpersandFunction(rhs) {
3053
3094
  }
3054
3095
  if (gatherRecursiveWithinFunction(
3055
3096
  block,
3056
- (a4) => a4 === ref
3097
+ (a5) => a5 === ref
3057
3098
  ).length > 1) {
3058
3099
  fn.ampersandBlock = false;
3059
3100
  }
@@ -9342,12 +9383,15 @@ var FieldDefinition$0 = (0, import_lib4.$TS)((0, import_lib4.$S)(CoffeeClassesEn
9342
9383
  default:
9343
9384
  return {
9344
9385
  type: "FieldDefinition",
9386
+ id,
9345
9387
  children: [id, " = ", exp]
9346
9388
  };
9347
9389
  }
9348
9390
  });
9349
9391
  var FieldDefinition$1 = (0, import_lib4.$TS)((0, import_lib4.$S)(InsertReadonly, ClassElementName, (0, import_lib4.$E)(TypeSuffix), __, ConstAssignment, MaybeNestedExpression), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
9350
9392
  var r = $1;
9393
+ var id = $2;
9394
+ var typeSuffix = $3;
9351
9395
  var ca = $5;
9352
9396
  r.children[0].$loc = {
9353
9397
  pos: ca.$loc.pos - 1,
@@ -9355,15 +9399,20 @@ var FieldDefinition$1 = (0, import_lib4.$TS)((0, import_lib4.$S)(InsertReadonly,
9355
9399
  };
9356
9400
  return {
9357
9401
  type: "FieldDefinition",
9402
+ id,
9403
+ typeSuffix,
9358
9404
  children: $0
9359
9405
  };
9360
9406
  });
9361
9407
  var FieldDefinition$2 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib4.$E)((0, import_lib4.$S)(Abstract, (0, import_lib4.$E)(_))), (0, import_lib4.$E)((0, import_lib4.$S)(Readonly, (0, import_lib4.$E)(_))), ClassElementName, (0, import_lib4.$E)(TypeSuffix), (0, import_lib4.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
9362
- if ($1)
9363
- return { children: $0, ts: true };
9408
+ var id = $3;
9409
+ var typeSuffix = $4;
9364
9410
  return {
9365
9411
  type: "FieldDefinition",
9366
- children: $0
9412
+ children: $0,
9413
+ ts: $1 ? true : void 0,
9414
+ id,
9415
+ typeSuffix
9367
9416
  };
9368
9417
  });
9369
9418
  var FieldDefinition$$ = [FieldDefinition$0, FieldDefinition$1, FieldDefinition$2];
@@ -10098,7 +10147,8 @@ var ParameterElement$0 = (0, import_lib4.$TS)((0, import_lib4.$S)((0, import_lib
10098
10147
  typeSuffix,
10099
10148
  accessModifier,
10100
10149
  initializer,
10101
- delim
10150
+ delim,
10151
+ binding
10102
10152
  };
10103
10153
  });
10104
10154
  function ParameterElement(ctx, state2) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.8.2",
4
+ "version": "0.8.3",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",