@danielx/civet 0.6.91 → 0.6.93

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/astro.js CHANGED
@@ -42,6 +42,11 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
+
46
+ // src/constants.ts
47
+ var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
48
+
49
+ // src/index.ts
45
50
  var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
51
  var postfixRE = /[?#].*$/s;
47
52
  var isWindows = import_os.default.platform() === "win32";
@@ -396,7 +401,7 @@ var rawPlugin = (options = {}, meta) => {
396
401
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
397
402
  if (implicitExtension) {
398
403
  config.resolve ?? (config.resolve = {});
399
- (_a = config.resolve).extensions ?? (_a.extensions = []);
404
+ (_a = config.resolve).extensions ?? (_a.extensions = DEFAULT_EXTENSIONS);
400
405
  config.resolve.extensions.push(".civet");
401
406
  }
402
407
  },
package/dist/browser.js CHANGED
@@ -377,13 +377,18 @@ var Civet = (() => {
377
377
  const { token } = pre[0];
378
378
  if (token === "-" || token === "+") {
379
379
  const children = [pre[0], ...exp.children];
380
- if (post)
381
- exp.children.push(post);
382
- return {
380
+ const literal = {
383
381
  type: "Literal",
384
382
  children,
385
383
  raw: `${token}${exp.raw}`
386
384
  };
385
+ if (post) {
386
+ return {
387
+ type: "UnaryExpression",
388
+ children: [literal, post]
389
+ };
390
+ }
391
+ return literal;
387
392
  }
388
393
  }
389
394
  }
@@ -494,12 +499,32 @@ var Civet = (() => {
494
499
  return;
495
500
  }
496
501
  function isExit(node) {
497
- return [
498
- "ReturnStatement",
499
- "ThrowStatement",
500
- "BreakStatement",
501
- "ContinueStatement"
502
- ].includes(node?.type);
502
+ if (!(node != null)) {
503
+ return false;
504
+ }
505
+ switch (node.type) {
506
+ case "ReturnStatement":
507
+ case "ThrowStatement":
508
+ case "BreakStatement":
509
+ case "ContinueStatement": {
510
+ return true;
511
+ }
512
+ case "IfStatement": {
513
+ return isExit(node.then) && isExit(node.else?.at(-1));
514
+ }
515
+ case "BlockStatement": {
516
+ return isExit(node.expressions.at(-1)?.[1]);
517
+ }
518
+ case "IterationStatement": {
519
+ return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
520
+ node.block,
521
+ ({ type }) => type === "BreakStatement"
522
+ ).length === 0;
523
+ }
524
+ default: {
525
+ return false;
526
+ }
527
+ }
503
528
  }
504
529
  function isComma(node) {
505
530
  if (node?.token === ",") {
@@ -629,12 +654,34 @@ var Civet = (() => {
629
654
  if (Array.isArray(node)) {
630
655
  return node.map(deepCopy);
631
656
  }
657
+ if (node?.type === "Ref")
658
+ return node;
632
659
  return Object.fromEntries(
633
660
  Object.entries(node).map(([key, value]) => {
634
661
  return [key, deepCopy(value)];
635
662
  })
636
663
  );
637
664
  }
665
+ function removeHoistDecs(node) {
666
+ if (node == null)
667
+ return;
668
+ if (typeof node !== "object")
669
+ return;
670
+ if ("hoistDec" in node) {
671
+ node.hoistDec = void 0;
672
+ }
673
+ if (Array.isArray(node)) {
674
+ for (const child of node) {
675
+ removeHoistDecs(child);
676
+ }
677
+ return;
678
+ }
679
+ if (node.children) {
680
+ for (const child of node.children) {
681
+ removeHoistDecs(child);
682
+ }
683
+ }
684
+ }
638
685
  function makeAmpersandFunction(bodyAfterRef = []) {
639
686
  const ref = makeRef("$");
640
687
  const body = [ref, ...bodyAfterRef];
@@ -1177,7 +1224,7 @@ var Civet = (() => {
1177
1224
  }
1178
1225
  function processBlocks(statements) {
1179
1226
  insertSemicolon(statements);
1180
- gatherRecursive(statements, ($) => $.type === "BlockStatement").forEach(function({ expressions }) {
1227
+ gatherRecursive(statements, ($) => $.type === "BlockStatement").forEach(({ expressions }) => {
1181
1228
  return processBlocks(expressions);
1182
1229
  });
1183
1230
  }
@@ -1187,7 +1234,7 @@ var Civet = (() => {
1187
1234
  const i = i1;
1188
1235
  const s = statements[i1];
1189
1236
  if (i < l - 1) {
1190
- if (needsPrecedingSemicolon(statements[i + 1])) {
1237
+ if (needsPrecedingSemicolon(statements[i + 1][1])) {
1191
1238
  const delim = s[2];
1192
1239
  if (!delim) {
1193
1240
  s[2] = ";";
@@ -1199,40 +1246,45 @@ var Civet = (() => {
1199
1246
  }
1200
1247
  }
1201
1248
  function needsPrecedingSemicolon(exp) {
1202
- let following;
1203
- if (Array.isArray(exp)) {
1204
- [, following] = exp;
1205
- } else {
1206
- following = exp;
1249
+ if (!exp) {
1250
+ return false;
1207
1251
  }
1208
- if (!following) {
1252
+ if (Array.isArray(exp)) {
1253
+ for (let i2 = 0, len1 = exp.length; i2 < len1; i2++) {
1254
+ const child = exp[i2];
1255
+ if (!(child != null)) {
1256
+ continue;
1257
+ }
1258
+ return needsPrecedingSemicolon(child);
1259
+ }
1209
1260
  return false;
1210
1261
  }
1211
- if (Array.isArray(following)) {
1212
- return needsPrecedingSemicolon(following[0]);
1262
+ if (typeof exp === "string") {
1263
+ return /^\s*[\(\[\`\+\-\/]/.test(exp);
1213
1264
  }
1214
- switch (following.type) {
1265
+ switch (exp.type) {
1215
1266
  case "ParenthesizedExpression":
1216
1267
  case "ArrayExpression":
1217
1268
  case "ArrowFunction":
1218
1269
  case "TemplateLiteral":
1219
1270
  case "RegularExpressionLiteral":
1220
- case "RangeExpression": {
1271
+ case "RangeExpression":
1272
+ case "ComputedPropertyName": {
1221
1273
  return true;
1222
1274
  }
1223
1275
  case "AssignmentExpression": {
1224
- return startsWith(following, /^(\[|\()/);
1276
+ return startsWith(exp, /^(\[|\()/);
1225
1277
  }
1226
1278
  case "Literal": {
1227
- return following.raw?.startsWith("-") || following.raw?.startsWith("+");
1279
+ return exp.raw?.startsWith("-") || exp.raw?.startsWith("+");
1228
1280
  }
1229
1281
  case "PipelineExpression":
1230
1282
  case "UnwrappedExpression": {
1231
- return needsPrecedingSemicolon(following.children[1]);
1283
+ return needsPrecedingSemicolon(exp.children[1]);
1232
1284
  }
1233
1285
  default: {
1234
- if (following.children) {
1235
- return needsPrecedingSemicolon(following.children[0]);
1286
+ if (exp.children) {
1287
+ return needsPrecedingSemicolon(exp.children);
1236
1288
  }
1237
1289
  ;
1238
1290
  return;
@@ -1371,8 +1423,7 @@ var Civet = (() => {
1371
1423
  const { clauses } = caseBlock;
1372
1424
  for (const c of clauses) {
1373
1425
  if (c.type === "WhenClause" && c.break) {
1374
- const last = c.block?.expressions?.at(-1)?.[1];
1375
- if (isExit(last)) {
1426
+ if (isExit(c.block)) {
1376
1427
  c.children.splice(c.children.indexOf(c.break), 1);
1377
1428
  c.break = void 0;
1378
1429
  }
@@ -1931,10 +1982,16 @@ var Civet = (() => {
1931
1982
  if (!Array.isArray(node)) {
1932
1983
  return;
1933
1984
  }
1934
- let [, exp] = node;
1985
+ let [, exp, semi] = node;
1986
+ if (semi?.type === "SemicolonDelimiter") {
1987
+ return;
1988
+ }
1935
1989
  if (!exp) {
1936
1990
  return;
1937
1991
  }
1992
+ if (isExit(exp)) {
1993
+ return;
1994
+ }
1938
1995
  const outer = exp;
1939
1996
  let { type } = exp;
1940
1997
  if (type === "LabelledStatement") {
@@ -2026,6 +2083,9 @@ var Civet = (() => {
2026
2083
  if (!exp) {
2027
2084
  return;
2028
2085
  }
2086
+ if (isExit(exp)) {
2087
+ return;
2088
+ }
2029
2089
  const outer = exp;
2030
2090
  let { type } = exp;
2031
2091
  if (type === "LabelledStatement") {
@@ -2718,6 +2778,7 @@ var Civet = (() => {
2718
2778
  switch (access.type) {
2719
2779
  case "PropertyAccess":
2720
2780
  case "SliceExpression":
2781
+ case "Index":
2721
2782
  break;
2722
2783
  default:
2723
2784
  children.unshift({
@@ -2754,6 +2815,7 @@ var Civet = (() => {
2754
2815
  exp: children
2755
2816
  });
2756
2817
  arg = clone(arg);
2818
+ removeHoistDecs(arg);
2757
2819
  if (arg.children[0].type === "Ref") {
2758
2820
  arg.children[0] = usingRef;
2759
2821
  }
@@ -3334,12 +3396,7 @@ var Civet = (() => {
3334
3396
  });
3335
3397
  }
3336
3398
  function quoteString(str) {
3337
- str = str.replace(/\\/g, "\\\\");
3338
- if (str.includes('"') && !str.includes("'")) {
3339
- return "'" + str.replace(/'/g, "\\'") + "'";
3340
- } else {
3341
- return '"' + str.replace(/"/g, '\\"') + '"';
3342
- }
3399
+ return JSON.stringify(str);
3343
3400
  }
3344
3401
  var indentRe;
3345
3402
  var init_string = __esm({
@@ -4398,7 +4455,7 @@ var Civet = (() => {
4398
4455
  const exp = _exp;
4399
4456
  let { ancestor } = findAncestor(exp, ($4) => $4?.type === "Call");
4400
4457
  ancestor = ancestor?.parent;
4401
- while (ancestor?.parent?.type === "UnaryExpression") {
4458
+ while (ancestor?.parent?.type === "UnaryExpression" || ancestor?.parent?.type === "NewExpression") {
4402
4459
  ancestor = ancestor.parent;
4403
4460
  }
4404
4461
  if (ancestor) {
@@ -6404,7 +6461,15 @@ ${input.slice(result.pos)}
6404
6461
  return $EVENT(ctx, state, "ArgumentsWithTrailingMemberExpressions", ArgumentsWithTrailingMemberExpressions$0);
6405
6462
  }
6406
6463
  var TrailingMemberExpressions$0 = $TS($S($Q(MemberExpressionRest), $Q($S(IndentedAtLeast, $Y($S($E($EXPECT($L6, 'TrailingMemberExpressions "?"')), $EXPECT($L7, 'TrailingMemberExpressions "."'), $N($EXPECT($R2, "TrailingMemberExpressions /[0-9]/")))), MemberExpressionRest))), function($skip, $loc, $0, $1, $2) {
6407
- return $1.concat($2);
6464
+ return $1.concat($2.map(([ws, , memberExpressionRest]) => {
6465
+ if (Array.isArray(memberExpressionRest)) {
6466
+ return [ws, ...memberExpressionRest];
6467
+ }
6468
+ return {
6469
+ ...memberExpressionRest,
6470
+ children: [ws, ...memberExpressionRest.children]
6471
+ };
6472
+ }));
6408
6473
  });
6409
6474
  function TrailingMemberExpressions(ctx, state) {
6410
6475
  return $EVENT(ctx, state, "TrailingMemberExpressions", TrailingMemberExpressions$0);
@@ -7123,19 +7188,25 @@ ${input.slice(result.pos)}
7123
7188
  return $EVENT(ctx, state, "ImplementsTarget", ImplementsTarget$0);
7124
7189
  }
7125
7190
  var ClassBody$0 = $TS($S(__, OpenBrace, $E(NestedClassElements), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7126
- var elements = $3;
7191
+ var expressions = $3;
7192
+ if (!expressions)
7193
+ expressions = $0[2] = [];
7127
7194
  return {
7128
- type: "ClassBody",
7195
+ type: "BlockStatement",
7196
+ subtype: "ClassBody",
7129
7197
  children: $0,
7130
- elements
7198
+ expressions
7131
7199
  };
7132
7200
  });
7133
7201
  var ClassBody$1 = $TS($S(InsertOpenBrace, $E(NestedClassElements), InsertNewline, InsertIndent, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7134
- var elements = $2;
7202
+ var expressions = $2;
7203
+ if (!expressions)
7204
+ expressions = $0[1] = [];
7135
7205
  return {
7136
- type: "ClassBody",
7206
+ type: "BlockStatement",
7207
+ subtype: "ClassBody",
7137
7208
  children: $0,
7138
- elements
7209
+ expressions
7139
7210
  };
7140
7211
  });
7141
7212
  var ClassBody$$ = [ClassBody$0, ClassBody$1];
@@ -10746,6 +10817,7 @@ ${input.slice(result.pos)}
10746
10817
  var clause = $1;
10747
10818
  var block = $2;
10748
10819
  return {
10820
+ ...clause,
10749
10821
  type: "IterationStatement",
10750
10822
  children: [...clause.children, block],
10751
10823
  block
@@ -10754,15 +10826,38 @@ ${input.slice(result.pos)}
10754
10826
  function LoopStatement(ctx, state) {
10755
10827
  return $EVENT(ctx, state, "LoopStatement", LoopStatement$0);
10756
10828
  }
10757
- var LoopClause$0 = $T($S(Loop), function(value) {
10758
- return { "type": "IterationStatement", "children": [value[0]] };
10829
+ var LoopClause$0 = $TV(Loop, function($skip, $loc, $0, $1) {
10830
+ var kind = $0;
10831
+ const expression = {
10832
+ type: "Literal",
10833
+ children: ["true"],
10834
+ raw: "true"
10835
+ };
10836
+ const condition = {
10837
+ type: "ParenthesizedExpression",
10838
+ children: ["(", expression, ")"],
10839
+ expression
10840
+ };
10841
+ return {
10842
+ type: "IterationStatement",
10843
+ subtype: kind.token,
10844
+ children: [kind, condition],
10845
+ condition
10846
+ };
10759
10847
  });
10760
10848
  function LoopClause(ctx, state) {
10761
10849
  return $EVENT(ctx, state, "LoopClause", LoopClause$0);
10762
10850
  }
10763
- var DoWhileStatement$0 = $T($S(Do, NoPostfixBracedBlock, __, WhileClause), function(value) {
10764
- var block = value[1];
10765
- return { "type": "IterationStatement", "children": value, "block": block };
10851
+ var DoWhileStatement$0 = $TS($S(Do, NoPostfixBracedBlock, __, WhileClause), function($skip, $loc, $0, $1, $2, $3, $4) {
10852
+ var block = $2;
10853
+ var clause = $4;
10854
+ return {
10855
+ ...clause,
10856
+ type: "IterationStatement",
10857
+ subtype: "do-while",
10858
+ children: $0,
10859
+ block
10860
+ };
10766
10861
  });
10767
10862
  function DoWhileStatement(ctx, state) {
10768
10863
  return $EVENT(ctx, state, "DoWhileStatement", DoWhileStatement$0);
@@ -10801,6 +10896,7 @@ ${input.slice(result.pos)}
10801
10896
  }
10802
10897
  return {
10803
10898
  type: "IterationStatement",
10899
+ subtype: kind.token,
10804
10900
  children: [kind, ws, condition],
10805
10901
  condition
10806
10902
  };
@@ -12925,7 +13021,7 @@ ${input.slice(result.pos)}
12925
13021
  return $EVENT_C(ctx, state, "LetOrConstOrVar", LetOrConstOrVar$$);
12926
13022
  }
12927
13023
  var Loop$0 = $TS($S($EXPECT($L167, 'Loop "loop"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
12928
- return { $loc, token: "while(true)" };
13024
+ return { $loc, token: "while" };
12929
13025
  });
12930
13026
  function Loop(ctx, state) {
12931
13027
  return $EVENT(ctx, state, "Loop", Loop$0);
@@ -14431,7 +14527,7 @@ ${input.slice(result.pos)}
14431
14527
  "]"
14432
14528
  ];
14433
14529
  });
14434
- var TypeIndexedAccess$2 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2, $3) {
14530
+ var TypeIndexedAccess$2 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E($C(IdentifierName, LengthShorthand))), function($skip, $loc, $0, $1, $2, $3) {
14435
14531
  var p = $2;
14436
14532
  var id = $3;
14437
14533
  const open = { ...p, token: '["' };
package/dist/esbuild.js CHANGED
@@ -42,6 +42,11 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
+
46
+ // src/constants.ts
47
+ var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
48
+
49
+ // src/index.ts
45
50
  var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
51
  var postfixRE = /[?#].*$/s;
47
52
  var isWindows = import_os.default.platform() === "win32";
@@ -396,7 +401,7 @@ var rawPlugin = (options = {}, meta) => {
396
401
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
397
402
  if (implicitExtension) {
398
403
  config.resolve ?? (config.resolve = {});
399
- (_a = config.resolve).extensions ?? (_a.extensions = []);
404
+ (_a = config.resolve).extensions ?? (_a.extensions = DEFAULT_EXTENSIONS);
400
405
  config.resolve.extensions.push(".civet");
401
406
  }
402
407
  },
package/dist/main.js CHANGED
@@ -369,13 +369,18 @@ function processUnaryExpression(pre, exp, post) {
369
369
  const { token } = pre[0];
370
370
  if (token === "-" || token === "+") {
371
371
  const children = [pre[0], ...exp.children];
372
- if (post)
373
- exp.children.push(post);
374
- return {
372
+ const literal = {
375
373
  type: "Literal",
376
374
  children,
377
375
  raw: `${token}${exp.raw}`
378
376
  };
377
+ if (post) {
378
+ return {
379
+ type: "UnaryExpression",
380
+ children: [literal, post]
381
+ };
382
+ }
383
+ return literal;
379
384
  }
380
385
  }
381
386
  }
@@ -486,12 +491,32 @@ function isWhitespaceOrEmpty(node) {
486
491
  return;
487
492
  }
488
493
  function isExit(node) {
489
- return [
490
- "ReturnStatement",
491
- "ThrowStatement",
492
- "BreakStatement",
493
- "ContinueStatement"
494
- ].includes(node?.type);
494
+ if (!(node != null)) {
495
+ return false;
496
+ }
497
+ switch (node.type) {
498
+ case "ReturnStatement":
499
+ case "ThrowStatement":
500
+ case "BreakStatement":
501
+ case "ContinueStatement": {
502
+ return true;
503
+ }
504
+ case "IfStatement": {
505
+ return isExit(node.then) && isExit(node.else?.at(-1));
506
+ }
507
+ case "BlockStatement": {
508
+ return isExit(node.expressions.at(-1)?.[1]);
509
+ }
510
+ case "IterationStatement": {
511
+ return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
512
+ node.block,
513
+ ({ type }) => type === "BreakStatement"
514
+ ).length === 0;
515
+ }
516
+ default: {
517
+ return false;
518
+ }
519
+ }
495
520
  }
496
521
  function isComma(node) {
497
522
  if (node?.token === ",") {
@@ -621,12 +646,34 @@ function deepCopy(node) {
621
646
  if (Array.isArray(node)) {
622
647
  return node.map(deepCopy);
623
648
  }
649
+ if (node?.type === "Ref")
650
+ return node;
624
651
  return Object.fromEntries(
625
652
  Object.entries(node).map(([key, value]) => {
626
653
  return [key, deepCopy(value)];
627
654
  })
628
655
  );
629
656
  }
657
+ function removeHoistDecs(node) {
658
+ if (node == null)
659
+ return;
660
+ if (typeof node !== "object")
661
+ return;
662
+ if ("hoistDec" in node) {
663
+ node.hoistDec = void 0;
664
+ }
665
+ if (Array.isArray(node)) {
666
+ for (const child of node) {
667
+ removeHoistDecs(child);
668
+ }
669
+ return;
670
+ }
671
+ if (node.children) {
672
+ for (const child of node.children) {
673
+ removeHoistDecs(child);
674
+ }
675
+ }
676
+ }
630
677
  function makeAmpersandFunction(bodyAfterRef = []) {
631
678
  const ref = makeRef("$");
632
679
  const body = [ref, ...bodyAfterRef];
@@ -1169,7 +1216,7 @@ function insertHoistDec(block, node, dec) {
1169
1216
  }
1170
1217
  function processBlocks(statements) {
1171
1218
  insertSemicolon(statements);
1172
- gatherRecursive(statements, ($) => $.type === "BlockStatement").forEach(function({ expressions }) {
1219
+ gatherRecursive(statements, ($) => $.type === "BlockStatement").forEach(({ expressions }) => {
1173
1220
  return processBlocks(expressions);
1174
1221
  });
1175
1222
  }
@@ -1179,7 +1226,7 @@ function insertSemicolon(statements) {
1179
1226
  const i = i1;
1180
1227
  const s = statements[i1];
1181
1228
  if (i < l - 1) {
1182
- if (needsPrecedingSemicolon(statements[i + 1])) {
1229
+ if (needsPrecedingSemicolon(statements[i + 1][1])) {
1183
1230
  const delim = s[2];
1184
1231
  if (!delim) {
1185
1232
  s[2] = ";";
@@ -1191,40 +1238,45 @@ function insertSemicolon(statements) {
1191
1238
  }
1192
1239
  }
1193
1240
  function needsPrecedingSemicolon(exp) {
1194
- let following;
1195
- if (Array.isArray(exp)) {
1196
- [, following] = exp;
1197
- } else {
1198
- following = exp;
1241
+ if (!exp) {
1242
+ return false;
1199
1243
  }
1200
- if (!following) {
1244
+ if (Array.isArray(exp)) {
1245
+ for (let i2 = 0, len1 = exp.length; i2 < len1; i2++) {
1246
+ const child = exp[i2];
1247
+ if (!(child != null)) {
1248
+ continue;
1249
+ }
1250
+ return needsPrecedingSemicolon(child);
1251
+ }
1201
1252
  return false;
1202
1253
  }
1203
- if (Array.isArray(following)) {
1204
- return needsPrecedingSemicolon(following[0]);
1254
+ if (typeof exp === "string") {
1255
+ return /^\s*[\(\[\`\+\-\/]/.test(exp);
1205
1256
  }
1206
- switch (following.type) {
1257
+ switch (exp.type) {
1207
1258
  case "ParenthesizedExpression":
1208
1259
  case "ArrayExpression":
1209
1260
  case "ArrowFunction":
1210
1261
  case "TemplateLiteral":
1211
1262
  case "RegularExpressionLiteral":
1212
- case "RangeExpression": {
1263
+ case "RangeExpression":
1264
+ case "ComputedPropertyName": {
1213
1265
  return true;
1214
1266
  }
1215
1267
  case "AssignmentExpression": {
1216
- return startsWith(following, /^(\[|\()/);
1268
+ return startsWith(exp, /^(\[|\()/);
1217
1269
  }
1218
1270
  case "Literal": {
1219
- return following.raw?.startsWith("-") || following.raw?.startsWith("+");
1271
+ return exp.raw?.startsWith("-") || exp.raw?.startsWith("+");
1220
1272
  }
1221
1273
  case "PipelineExpression":
1222
1274
  case "UnwrappedExpression": {
1223
- return needsPrecedingSemicolon(following.children[1]);
1275
+ return needsPrecedingSemicolon(exp.children[1]);
1224
1276
  }
1225
1277
  default: {
1226
- if (following.children) {
1227
- return needsPrecedingSemicolon(following.children[0]);
1278
+ if (exp.children) {
1279
+ return needsPrecedingSemicolon(exp.children);
1228
1280
  }
1229
1281
  ;
1230
1282
  return;
@@ -1363,8 +1415,7 @@ function processPatternMatching(statements, ReservedWord, getRef) {
1363
1415
  const { clauses } = caseBlock;
1364
1416
  for (const c of clauses) {
1365
1417
  if (c.type === "WhenClause" && c.break) {
1366
- const last = c.block?.expressions?.at(-1)?.[1];
1367
- if (isExit(last)) {
1418
+ if (isExit(c.block)) {
1368
1419
  c.children.splice(c.children.indexOf(c.break), 1);
1369
1420
  c.break = void 0;
1370
1421
  }
@@ -1923,10 +1974,16 @@ function assignResults(node, collect) {
1923
1974
  if (!Array.isArray(node)) {
1924
1975
  return;
1925
1976
  }
1926
- let [, exp] = node;
1977
+ let [, exp, semi] = node;
1978
+ if (semi?.type === "SemicolonDelimiter") {
1979
+ return;
1980
+ }
1927
1981
  if (!exp) {
1928
1982
  return;
1929
1983
  }
1984
+ if (isExit(exp)) {
1985
+ return;
1986
+ }
1930
1987
  const outer = exp;
1931
1988
  let { type } = exp;
1932
1989
  if (type === "LabelledStatement") {
@@ -2018,6 +2075,9 @@ function insertReturn(node, outerNode = node) {
2018
2075
  if (!exp) {
2019
2076
  return;
2020
2077
  }
2078
+ if (isExit(exp)) {
2079
+ return;
2080
+ }
2021
2081
  const outer = exp;
2022
2082
  let { type } = exp;
2023
2083
  if (type === "LabelledStatement") {
@@ -2710,6 +2770,7 @@ function processPipelineExpressions(statements) {
2710
2770
  switch (access.type) {
2711
2771
  case "PropertyAccess":
2712
2772
  case "SliceExpression":
2773
+ case "Index":
2713
2774
  break;
2714
2775
  default:
2715
2776
  children.unshift({
@@ -2746,6 +2807,7 @@ function processPipelineExpressions(statements) {
2746
2807
  exp: children
2747
2808
  });
2748
2809
  arg = clone(arg);
2810
+ removeHoistDecs(arg);
2749
2811
  if (arg.children[0].type === "Ref") {
2750
2812
  arg.children[0] = usingRef;
2751
2813
  }
@@ -3326,12 +3388,7 @@ function modifyString(str) {
3326
3388
  });
3327
3389
  }
3328
3390
  function quoteString(str) {
3329
- str = str.replace(/\\/g, "\\\\");
3330
- if (str.includes('"') && !str.includes("'")) {
3331
- return "'" + str.replace(/'/g, "\\'") + "'";
3332
- } else {
3333
- return '"' + str.replace(/"/g, '\\"') + '"';
3334
- }
3391
+ return JSON.stringify(str);
3335
3392
  }
3336
3393
  var indentRe;
3337
3394
  var init_string = __esm({
@@ -4390,7 +4447,7 @@ function processPartialPlaceholders(statements) {
4390
4447
  const exp = _exp;
4391
4448
  let { ancestor } = findAncestor(exp, ($4) => $4?.type === "Call");
4392
4449
  ancestor = ancestor?.parent;
4393
- while (ancestor?.parent?.type === "UnaryExpression") {
4450
+ while (ancestor?.parent?.type === "UnaryExpression" || ancestor?.parent?.type === "NewExpression") {
4394
4451
  ancestor = ancestor.parent;
4395
4452
  }
4396
4453
  if (ancestor) {
@@ -6396,7 +6453,15 @@ var require_parser = __commonJS({
6396
6453
  return $EVENT(ctx, state, "ArgumentsWithTrailingMemberExpressions", ArgumentsWithTrailingMemberExpressions$0);
6397
6454
  }
6398
6455
  var TrailingMemberExpressions$0 = $TS($S($Q(MemberExpressionRest), $Q($S(IndentedAtLeast, $Y($S($E($EXPECT($L6, 'TrailingMemberExpressions "?"')), $EXPECT($L7, 'TrailingMemberExpressions "."'), $N($EXPECT($R2, "TrailingMemberExpressions /[0-9]/")))), MemberExpressionRest))), function($skip, $loc, $0, $1, $2) {
6399
- return $1.concat($2);
6456
+ return $1.concat($2.map(([ws, , memberExpressionRest]) => {
6457
+ if (Array.isArray(memberExpressionRest)) {
6458
+ return [ws, ...memberExpressionRest];
6459
+ }
6460
+ return {
6461
+ ...memberExpressionRest,
6462
+ children: [ws, ...memberExpressionRest.children]
6463
+ };
6464
+ }));
6400
6465
  });
6401
6466
  function TrailingMemberExpressions(ctx, state) {
6402
6467
  return $EVENT(ctx, state, "TrailingMemberExpressions", TrailingMemberExpressions$0);
@@ -7115,19 +7180,25 @@ var require_parser = __commonJS({
7115
7180
  return $EVENT(ctx, state, "ImplementsTarget", ImplementsTarget$0);
7116
7181
  }
7117
7182
  var ClassBody$0 = $TS($S(__, OpenBrace, $E(NestedClassElements), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7118
- var elements = $3;
7183
+ var expressions = $3;
7184
+ if (!expressions)
7185
+ expressions = $0[2] = [];
7119
7186
  return {
7120
- type: "ClassBody",
7187
+ type: "BlockStatement",
7188
+ subtype: "ClassBody",
7121
7189
  children: $0,
7122
- elements
7190
+ expressions
7123
7191
  };
7124
7192
  });
7125
7193
  var ClassBody$1 = $TS($S(InsertOpenBrace, $E(NestedClassElements), InsertNewline, InsertIndent, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7126
- var elements = $2;
7194
+ var expressions = $2;
7195
+ if (!expressions)
7196
+ expressions = $0[1] = [];
7127
7197
  return {
7128
- type: "ClassBody",
7198
+ type: "BlockStatement",
7199
+ subtype: "ClassBody",
7129
7200
  children: $0,
7130
- elements
7201
+ expressions
7131
7202
  };
7132
7203
  });
7133
7204
  var ClassBody$$ = [ClassBody$0, ClassBody$1];
@@ -10738,6 +10809,7 @@ var require_parser = __commonJS({
10738
10809
  var clause = $1;
10739
10810
  var block = $2;
10740
10811
  return {
10812
+ ...clause,
10741
10813
  type: "IterationStatement",
10742
10814
  children: [...clause.children, block],
10743
10815
  block
@@ -10746,15 +10818,38 @@ var require_parser = __commonJS({
10746
10818
  function LoopStatement(ctx, state) {
10747
10819
  return $EVENT(ctx, state, "LoopStatement", LoopStatement$0);
10748
10820
  }
10749
- var LoopClause$0 = $T($S(Loop), function(value) {
10750
- return { "type": "IterationStatement", "children": [value[0]] };
10821
+ var LoopClause$0 = $TV(Loop, function($skip, $loc, $0, $1) {
10822
+ var kind = $0;
10823
+ const expression = {
10824
+ type: "Literal",
10825
+ children: ["true"],
10826
+ raw: "true"
10827
+ };
10828
+ const condition = {
10829
+ type: "ParenthesizedExpression",
10830
+ children: ["(", expression, ")"],
10831
+ expression
10832
+ };
10833
+ return {
10834
+ type: "IterationStatement",
10835
+ subtype: kind.token,
10836
+ children: [kind, condition],
10837
+ condition
10838
+ };
10751
10839
  });
10752
10840
  function LoopClause(ctx, state) {
10753
10841
  return $EVENT(ctx, state, "LoopClause", LoopClause$0);
10754
10842
  }
10755
- var DoWhileStatement$0 = $T($S(Do, NoPostfixBracedBlock, __, WhileClause), function(value) {
10756
- var block = value[1];
10757
- return { "type": "IterationStatement", "children": value, "block": block };
10843
+ var DoWhileStatement$0 = $TS($S(Do, NoPostfixBracedBlock, __, WhileClause), function($skip, $loc, $0, $1, $2, $3, $4) {
10844
+ var block = $2;
10845
+ var clause = $4;
10846
+ return {
10847
+ ...clause,
10848
+ type: "IterationStatement",
10849
+ subtype: "do-while",
10850
+ children: $0,
10851
+ block
10852
+ };
10758
10853
  });
10759
10854
  function DoWhileStatement(ctx, state) {
10760
10855
  return $EVENT(ctx, state, "DoWhileStatement", DoWhileStatement$0);
@@ -10793,6 +10888,7 @@ var require_parser = __commonJS({
10793
10888
  }
10794
10889
  return {
10795
10890
  type: "IterationStatement",
10891
+ subtype: kind.token,
10796
10892
  children: [kind, ws, condition],
10797
10893
  condition
10798
10894
  };
@@ -12917,7 +13013,7 @@ var require_parser = __commonJS({
12917
13013
  return $EVENT_C(ctx, state, "LetOrConstOrVar", LetOrConstOrVar$$);
12918
13014
  }
12919
13015
  var Loop$0 = $TS($S($EXPECT($L167, 'Loop "loop"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
12920
- return { $loc, token: "while(true)" };
13016
+ return { $loc, token: "while" };
12921
13017
  });
12922
13018
  function Loop(ctx, state) {
12923
13019
  return $EVENT(ctx, state, "Loop", Loop$0);
@@ -14423,7 +14519,7 @@ var require_parser = __commonJS({
14423
14519
  "]"
14424
14520
  ];
14425
14521
  });
14426
- var TypeIndexedAccess$2 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2, $3) {
14522
+ var TypeIndexedAccess$2 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E($C(IdentifierName, LengthShorthand))), function($skip, $loc, $0, $1, $2, $3) {
14427
14523
  var p = $2;
14428
14524
  var id = $3;
14429
14525
  const open = { ...p, token: '["' };
package/dist/main.mjs CHANGED
@@ -367,13 +367,18 @@ function processUnaryExpression(pre, exp, post) {
367
367
  const { token } = pre[0];
368
368
  if (token === "-" || token === "+") {
369
369
  const children = [pre[0], ...exp.children];
370
- if (post)
371
- exp.children.push(post);
372
- return {
370
+ const literal = {
373
371
  type: "Literal",
374
372
  children,
375
373
  raw: `${token}${exp.raw}`
376
374
  };
375
+ if (post) {
376
+ return {
377
+ type: "UnaryExpression",
378
+ children: [literal, post]
379
+ };
380
+ }
381
+ return literal;
377
382
  }
378
383
  }
379
384
  }
@@ -484,12 +489,32 @@ function isWhitespaceOrEmpty(node) {
484
489
  return;
485
490
  }
486
491
  function isExit(node) {
487
- return [
488
- "ReturnStatement",
489
- "ThrowStatement",
490
- "BreakStatement",
491
- "ContinueStatement"
492
- ].includes(node?.type);
492
+ if (!(node != null)) {
493
+ return false;
494
+ }
495
+ switch (node.type) {
496
+ case "ReturnStatement":
497
+ case "ThrowStatement":
498
+ case "BreakStatement":
499
+ case "ContinueStatement": {
500
+ return true;
501
+ }
502
+ case "IfStatement": {
503
+ return isExit(node.then) && isExit(node.else?.at(-1));
504
+ }
505
+ case "BlockStatement": {
506
+ return isExit(node.expressions.at(-1)?.[1]);
507
+ }
508
+ case "IterationStatement": {
509
+ return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(
510
+ node.block,
511
+ ({ type }) => type === "BreakStatement"
512
+ ).length === 0;
513
+ }
514
+ default: {
515
+ return false;
516
+ }
517
+ }
493
518
  }
494
519
  function isComma(node) {
495
520
  if (node?.token === ",") {
@@ -619,12 +644,34 @@ function deepCopy(node) {
619
644
  if (Array.isArray(node)) {
620
645
  return node.map(deepCopy);
621
646
  }
647
+ if (node?.type === "Ref")
648
+ return node;
622
649
  return Object.fromEntries(
623
650
  Object.entries(node).map(([key, value]) => {
624
651
  return [key, deepCopy(value)];
625
652
  })
626
653
  );
627
654
  }
655
+ function removeHoistDecs(node) {
656
+ if (node == null)
657
+ return;
658
+ if (typeof node !== "object")
659
+ return;
660
+ if ("hoistDec" in node) {
661
+ node.hoistDec = void 0;
662
+ }
663
+ if (Array.isArray(node)) {
664
+ for (const child of node) {
665
+ removeHoistDecs(child);
666
+ }
667
+ return;
668
+ }
669
+ if (node.children) {
670
+ for (const child of node.children) {
671
+ removeHoistDecs(child);
672
+ }
673
+ }
674
+ }
628
675
  function makeAmpersandFunction(bodyAfterRef = []) {
629
676
  const ref = makeRef("$");
630
677
  const body = [ref, ...bodyAfterRef];
@@ -1167,7 +1214,7 @@ function insertHoistDec(block, node, dec) {
1167
1214
  }
1168
1215
  function processBlocks(statements) {
1169
1216
  insertSemicolon(statements);
1170
- gatherRecursive(statements, ($) => $.type === "BlockStatement").forEach(function({ expressions }) {
1217
+ gatherRecursive(statements, ($) => $.type === "BlockStatement").forEach(({ expressions }) => {
1171
1218
  return processBlocks(expressions);
1172
1219
  });
1173
1220
  }
@@ -1177,7 +1224,7 @@ function insertSemicolon(statements) {
1177
1224
  const i = i1;
1178
1225
  const s = statements[i1];
1179
1226
  if (i < l - 1) {
1180
- if (needsPrecedingSemicolon(statements[i + 1])) {
1227
+ if (needsPrecedingSemicolon(statements[i + 1][1])) {
1181
1228
  const delim = s[2];
1182
1229
  if (!delim) {
1183
1230
  s[2] = ";";
@@ -1189,40 +1236,45 @@ function insertSemicolon(statements) {
1189
1236
  }
1190
1237
  }
1191
1238
  function needsPrecedingSemicolon(exp) {
1192
- let following;
1193
- if (Array.isArray(exp)) {
1194
- [, following] = exp;
1195
- } else {
1196
- following = exp;
1239
+ if (!exp) {
1240
+ return false;
1197
1241
  }
1198
- if (!following) {
1242
+ if (Array.isArray(exp)) {
1243
+ for (let i2 = 0, len1 = exp.length; i2 < len1; i2++) {
1244
+ const child = exp[i2];
1245
+ if (!(child != null)) {
1246
+ continue;
1247
+ }
1248
+ return needsPrecedingSemicolon(child);
1249
+ }
1199
1250
  return false;
1200
1251
  }
1201
- if (Array.isArray(following)) {
1202
- return needsPrecedingSemicolon(following[0]);
1252
+ if (typeof exp === "string") {
1253
+ return /^\s*[\(\[\`\+\-\/]/.test(exp);
1203
1254
  }
1204
- switch (following.type) {
1255
+ switch (exp.type) {
1205
1256
  case "ParenthesizedExpression":
1206
1257
  case "ArrayExpression":
1207
1258
  case "ArrowFunction":
1208
1259
  case "TemplateLiteral":
1209
1260
  case "RegularExpressionLiteral":
1210
- case "RangeExpression": {
1261
+ case "RangeExpression":
1262
+ case "ComputedPropertyName": {
1211
1263
  return true;
1212
1264
  }
1213
1265
  case "AssignmentExpression": {
1214
- return startsWith(following, /^(\[|\()/);
1266
+ return startsWith(exp, /^(\[|\()/);
1215
1267
  }
1216
1268
  case "Literal": {
1217
- return following.raw?.startsWith("-") || following.raw?.startsWith("+");
1269
+ return exp.raw?.startsWith("-") || exp.raw?.startsWith("+");
1218
1270
  }
1219
1271
  case "PipelineExpression":
1220
1272
  case "UnwrappedExpression": {
1221
- return needsPrecedingSemicolon(following.children[1]);
1273
+ return needsPrecedingSemicolon(exp.children[1]);
1222
1274
  }
1223
1275
  default: {
1224
- if (following.children) {
1225
- return needsPrecedingSemicolon(following.children[0]);
1276
+ if (exp.children) {
1277
+ return needsPrecedingSemicolon(exp.children);
1226
1278
  }
1227
1279
  ;
1228
1280
  return;
@@ -1361,8 +1413,7 @@ function processPatternMatching(statements, ReservedWord, getRef) {
1361
1413
  const { clauses } = caseBlock;
1362
1414
  for (const c of clauses) {
1363
1415
  if (c.type === "WhenClause" && c.break) {
1364
- const last = c.block?.expressions?.at(-1)?.[1];
1365
- if (isExit(last)) {
1416
+ if (isExit(c.block)) {
1366
1417
  c.children.splice(c.children.indexOf(c.break), 1);
1367
1418
  c.break = void 0;
1368
1419
  }
@@ -1921,10 +1972,16 @@ function assignResults(node, collect) {
1921
1972
  if (!Array.isArray(node)) {
1922
1973
  return;
1923
1974
  }
1924
- let [, exp] = node;
1975
+ let [, exp, semi] = node;
1976
+ if (semi?.type === "SemicolonDelimiter") {
1977
+ return;
1978
+ }
1925
1979
  if (!exp) {
1926
1980
  return;
1927
1981
  }
1982
+ if (isExit(exp)) {
1983
+ return;
1984
+ }
1928
1985
  const outer = exp;
1929
1986
  let { type } = exp;
1930
1987
  if (type === "LabelledStatement") {
@@ -2016,6 +2073,9 @@ function insertReturn(node, outerNode = node) {
2016
2073
  if (!exp) {
2017
2074
  return;
2018
2075
  }
2076
+ if (isExit(exp)) {
2077
+ return;
2078
+ }
2019
2079
  const outer = exp;
2020
2080
  let { type } = exp;
2021
2081
  if (type === "LabelledStatement") {
@@ -2708,6 +2768,7 @@ function processPipelineExpressions(statements) {
2708
2768
  switch (access.type) {
2709
2769
  case "PropertyAccess":
2710
2770
  case "SliceExpression":
2771
+ case "Index":
2711
2772
  break;
2712
2773
  default:
2713
2774
  children.unshift({
@@ -2744,6 +2805,7 @@ function processPipelineExpressions(statements) {
2744
2805
  exp: children
2745
2806
  });
2746
2807
  arg = clone(arg);
2808
+ removeHoistDecs(arg);
2747
2809
  if (arg.children[0].type === "Ref") {
2748
2810
  arg.children[0] = usingRef;
2749
2811
  }
@@ -3324,12 +3386,7 @@ function modifyString(str) {
3324
3386
  });
3325
3387
  }
3326
3388
  function quoteString(str) {
3327
- str = str.replace(/\\/g, "\\\\");
3328
- if (str.includes('"') && !str.includes("'")) {
3329
- return "'" + str.replace(/'/g, "\\'") + "'";
3330
- } else {
3331
- return '"' + str.replace(/"/g, '\\"') + '"';
3332
- }
3389
+ return JSON.stringify(str);
3333
3390
  }
3334
3391
  var indentRe;
3335
3392
  var init_string = __esm({
@@ -4388,7 +4445,7 @@ function processPartialPlaceholders(statements) {
4388
4445
  const exp = _exp;
4389
4446
  let { ancestor } = findAncestor(exp, ($4) => $4?.type === "Call");
4390
4447
  ancestor = ancestor?.parent;
4391
- while (ancestor?.parent?.type === "UnaryExpression") {
4448
+ while (ancestor?.parent?.type === "UnaryExpression" || ancestor?.parent?.type === "NewExpression") {
4392
4449
  ancestor = ancestor.parent;
4393
4450
  }
4394
4451
  if (ancestor) {
@@ -6394,7 +6451,15 @@ var require_parser = __commonJS({
6394
6451
  return $EVENT(ctx, state, "ArgumentsWithTrailingMemberExpressions", ArgumentsWithTrailingMemberExpressions$0);
6395
6452
  }
6396
6453
  var TrailingMemberExpressions$0 = $TS($S($Q(MemberExpressionRest), $Q($S(IndentedAtLeast, $Y($S($E($EXPECT($L6, 'TrailingMemberExpressions "?"')), $EXPECT($L7, 'TrailingMemberExpressions "."'), $N($EXPECT($R2, "TrailingMemberExpressions /[0-9]/")))), MemberExpressionRest))), function($skip, $loc, $0, $1, $2) {
6397
- return $1.concat($2);
6454
+ return $1.concat($2.map(([ws, , memberExpressionRest]) => {
6455
+ if (Array.isArray(memberExpressionRest)) {
6456
+ return [ws, ...memberExpressionRest];
6457
+ }
6458
+ return {
6459
+ ...memberExpressionRest,
6460
+ children: [ws, ...memberExpressionRest.children]
6461
+ };
6462
+ }));
6398
6463
  });
6399
6464
  function TrailingMemberExpressions(ctx, state) {
6400
6465
  return $EVENT(ctx, state, "TrailingMemberExpressions", TrailingMemberExpressions$0);
@@ -7113,19 +7178,25 @@ var require_parser = __commonJS({
7113
7178
  return $EVENT(ctx, state, "ImplementsTarget", ImplementsTarget$0);
7114
7179
  }
7115
7180
  var ClassBody$0 = $TS($S(__, OpenBrace, $E(NestedClassElements), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7116
- var elements = $3;
7181
+ var expressions = $3;
7182
+ if (!expressions)
7183
+ expressions = $0[2] = [];
7117
7184
  return {
7118
- type: "ClassBody",
7185
+ type: "BlockStatement",
7186
+ subtype: "ClassBody",
7119
7187
  children: $0,
7120
- elements
7188
+ expressions
7121
7189
  };
7122
7190
  });
7123
7191
  var ClassBody$1 = $TS($S(InsertOpenBrace, $E(NestedClassElements), InsertNewline, InsertIndent, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7124
- var elements = $2;
7192
+ var expressions = $2;
7193
+ if (!expressions)
7194
+ expressions = $0[1] = [];
7125
7195
  return {
7126
- type: "ClassBody",
7196
+ type: "BlockStatement",
7197
+ subtype: "ClassBody",
7127
7198
  children: $0,
7128
- elements
7199
+ expressions
7129
7200
  };
7130
7201
  });
7131
7202
  var ClassBody$$ = [ClassBody$0, ClassBody$1];
@@ -10736,6 +10807,7 @@ var require_parser = __commonJS({
10736
10807
  var clause = $1;
10737
10808
  var block = $2;
10738
10809
  return {
10810
+ ...clause,
10739
10811
  type: "IterationStatement",
10740
10812
  children: [...clause.children, block],
10741
10813
  block
@@ -10744,15 +10816,38 @@ var require_parser = __commonJS({
10744
10816
  function LoopStatement(ctx, state) {
10745
10817
  return $EVENT(ctx, state, "LoopStatement", LoopStatement$0);
10746
10818
  }
10747
- var LoopClause$0 = $T($S(Loop), function(value) {
10748
- return { "type": "IterationStatement", "children": [value[0]] };
10819
+ var LoopClause$0 = $TV(Loop, function($skip, $loc, $0, $1) {
10820
+ var kind = $0;
10821
+ const expression = {
10822
+ type: "Literal",
10823
+ children: ["true"],
10824
+ raw: "true"
10825
+ };
10826
+ const condition = {
10827
+ type: "ParenthesizedExpression",
10828
+ children: ["(", expression, ")"],
10829
+ expression
10830
+ };
10831
+ return {
10832
+ type: "IterationStatement",
10833
+ subtype: kind.token,
10834
+ children: [kind, condition],
10835
+ condition
10836
+ };
10749
10837
  });
10750
10838
  function LoopClause(ctx, state) {
10751
10839
  return $EVENT(ctx, state, "LoopClause", LoopClause$0);
10752
10840
  }
10753
- var DoWhileStatement$0 = $T($S(Do, NoPostfixBracedBlock, __, WhileClause), function(value) {
10754
- var block = value[1];
10755
- return { "type": "IterationStatement", "children": value, "block": block };
10841
+ var DoWhileStatement$0 = $TS($S(Do, NoPostfixBracedBlock, __, WhileClause), function($skip, $loc, $0, $1, $2, $3, $4) {
10842
+ var block = $2;
10843
+ var clause = $4;
10844
+ return {
10845
+ ...clause,
10846
+ type: "IterationStatement",
10847
+ subtype: "do-while",
10848
+ children: $0,
10849
+ block
10850
+ };
10756
10851
  });
10757
10852
  function DoWhileStatement(ctx, state) {
10758
10853
  return $EVENT(ctx, state, "DoWhileStatement", DoWhileStatement$0);
@@ -10791,6 +10886,7 @@ var require_parser = __commonJS({
10791
10886
  }
10792
10887
  return {
10793
10888
  type: "IterationStatement",
10889
+ subtype: kind.token,
10794
10890
  children: [kind, ws, condition],
10795
10891
  condition
10796
10892
  };
@@ -12915,7 +13011,7 @@ var require_parser = __commonJS({
12915
13011
  return $EVENT_C(ctx, state, "LetOrConstOrVar", LetOrConstOrVar$$);
12916
13012
  }
12917
13013
  var Loop$0 = $TS($S($EXPECT($L167, 'Loop "loop"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
12918
- return { $loc, token: "while(true)" };
13014
+ return { $loc, token: "while" };
12919
13015
  });
12920
13016
  function Loop(ctx, state) {
12921
13017
  return $EVENT(ctx, state, "Loop", Loop$0);
@@ -14421,7 +14517,7 @@ var require_parser = __commonJS({
14421
14517
  "]"
14422
14518
  ];
14423
14519
  });
14424
- var TypeIndexedAccess$2 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E(IdentifierName)), function($skip, $loc, $0, $1, $2, $3) {
14520
+ var TypeIndexedAccess$2 = $TS($S(CoffeePrototypeEnabled, DoubleColon, $E($C(IdentifierName, LengthShorthand))), function($skip, $loc, $0, $1, $2, $3) {
14425
14521
  var p = $2;
14426
14522
  var id = $3;
14427
14523
  const open = { ...p, token: '["' };
package/dist/rollup.js CHANGED
@@ -42,6 +42,11 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
+
46
+ // src/constants.ts
47
+ var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
48
+
49
+ // src/index.ts
45
50
  var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
51
  var postfixRE = /[?#].*$/s;
47
52
  var isWindows = import_os.default.platform() === "win32";
@@ -396,7 +401,7 @@ var rawPlugin = (options = {}, meta) => {
396
401
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
397
402
  if (implicitExtension) {
398
403
  config.resolve ?? (config.resolve = {});
399
- (_a = config.resolve).extensions ?? (_a.extensions = []);
404
+ (_a = config.resolve).extensions ?? (_a.extensions = DEFAULT_EXTENSIONS);
400
405
  config.resolve.extensions.push(".civet");
401
406
  }
402
407
  },
@@ -9,6 +9,11 @@ import * as fs from "fs";
9
9
  import path from "path";
10
10
  import * as tsvfs from "@typescript/vfs";
11
11
  import os from "os";
12
+
13
+ // src/constants.ts
14
+ var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
15
+
16
+ // src/index.ts
12
17
  var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
13
18
  var postfixRE = /[?#].*$/s;
14
19
  var isWindows = os.platform() === "win32";
@@ -363,7 +368,7 @@ var rawPlugin = (options = {}, meta) => {
363
368
  rootDir = path.resolve(process.cwd(), config.root ?? "");
364
369
  if (implicitExtension) {
365
370
  config.resolve ?? (config.resolve = {});
366
- (_a = config.resolve).extensions ?? (_a.extensions = []);
371
+ (_a = config.resolve).extensions ?? (_a.extensions = DEFAULT_EXTENSIONS);
367
372
  config.resolve.extensions.push(".civet");
368
373
  }
369
374
  },
package/dist/unplugin.js CHANGED
@@ -42,6 +42,11 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
+
46
+ // src/constants.ts
47
+ var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
48
+
49
+ // src/index.ts
45
50
  var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
51
  var postfixRE = /[?#].*$/s;
47
52
  var isWindows = import_os.default.platform() === "win32";
@@ -396,7 +401,7 @@ var rawPlugin = (options = {}, meta) => {
396
401
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
397
402
  if (implicitExtension) {
398
403
  config.resolve ?? (config.resolve = {});
399
- (_a = config.resolve).extensions ?? (_a.extensions = []);
404
+ (_a = config.resolve).extensions ?? (_a.extensions = DEFAULT_EXTENSIONS);
400
405
  config.resolve.extensions.push(".civet");
401
406
  }
402
407
  },
package/dist/vite.js CHANGED
@@ -42,6 +42,11 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
+
46
+ // src/constants.ts
47
+ var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
48
+
49
+ // src/index.ts
45
50
  var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
51
  var postfixRE = /[?#].*$/s;
47
52
  var isWindows = import_os.default.platform() === "win32";
@@ -396,7 +401,7 @@ var rawPlugin = (options = {}, meta) => {
396
401
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
397
402
  if (implicitExtension) {
398
403
  config.resolve ?? (config.resolve = {});
399
- (_a = config.resolve).extensions ?? (_a.extensions = []);
404
+ (_a = config.resolve).extensions ?? (_a.extensions = DEFAULT_EXTENSIONS);
400
405
  config.resolve.extensions.push(".civet");
401
406
  }
402
407
  },
package/dist/webpack.js CHANGED
@@ -42,6 +42,11 @@ var fs = __toESM(require("fs"));
42
42
  var import_path = __toESM(require("path"));
43
43
  var tsvfs = __toESM(require("@typescript/vfs"));
44
44
  var import_os = __toESM(require("os"));
45
+
46
+ // src/constants.ts
47
+ var DEFAULT_EXTENSIONS = [".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
48
+
49
+ // src/index.ts
45
50
  var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
46
51
  var postfixRE = /[?#].*$/s;
47
52
  var isWindows = import_os.default.platform() === "win32";
@@ -396,7 +401,7 @@ var rawPlugin = (options = {}, meta) => {
396
401
  rootDir = import_path.default.resolve(process.cwd(), config.root ?? "");
397
402
  if (implicitExtension) {
398
403
  config.resolve ?? (config.resolve = {});
399
- (_a = config.resolve).extensions ?? (_a.extensions = []);
404
+ (_a = config.resolve).extensions ?? (_a.extensions = DEFAULT_EXTENSIONS);
400
405
  config.resolve.extensions.push(".civet");
401
406
  }
402
407
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
3
  "type": "commonjs",
4
- "version": "0.6.91",
4
+ "version": "0.6.93",
5
5
  "description": "CoffeeScript style syntax for TypeScript",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/main.mjs",
@@ -118,7 +118,8 @@
118
118
  "source"
119
119
  ],
120
120
  "exclude": [
121
- "source/parser/types.civet"
121
+ "source/parser/types.civet",
122
+ "source/bun-civet.civet"
122
123
  ]
123
124
  },
124
125
  "mocha": {