@danielx/civet 0.6.30 → 0.6.32

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/browser.js CHANGED
@@ -23,6 +23,10 @@ var Civet = (() => {
23
23
  return to;
24
24
  };
25
25
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
30
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
31
  mod
28
32
  ));
@@ -523,9 +527,10 @@ ${input.slice(result.pos)}
523
527
  }
524
528
  function addPostfixStatement(statement, ws, post) {
525
529
  let children, expressions;
526
- if (post.blockPrefix?.length) {
527
- let indent = post.blockPrefix[0][0];
528
- expressions = [...post.blockPrefix, [indent, statement]];
530
+ const prefix = post.blockPrefix || post.condition?.expression.blockPrefix;
531
+ if (prefix?.length) {
532
+ const indent = prefix[0][0];
533
+ expressions = [...prefix, [indent, statement]];
529
534
  children = [" {\n", ...expressions, "\n", indent?.slice?.(0, -2), "}"];
530
535
  } else {
531
536
  expressions = [["", statement]];
@@ -604,6 +609,7 @@ ${input.slice(result.pos)}
604
609
  children: [...elements.slice(0, restIndex), {
605
610
  ...rest,
606
611
  children: rest.children.slice(0, -1)
612
+ // remove trailing comma
607
613
  }],
608
614
  blockPrefix,
609
615
  length
@@ -648,7 +654,9 @@ ${input.slice(result.pos)}
648
654
  if (prefixStatements && prefixStatements.length) {
649
655
  const indent = getIndent(block.expressions[0]);
650
656
  if (indent) {
651
- prefixStatements = prefixStatements.map((statement) => [indent, ...statement.slice(1)]);
657
+ prefixStatements = prefixStatements.map((statement) => {
658
+ return [indent, ...statement.slice(1)];
659
+ });
652
660
  }
653
661
  const expressions = [...prefixStatements, ...block.expressions];
654
662
  block = {
@@ -833,7 +841,8 @@ ${input.slice(result.pos)}
833
841
  ...wrapIIFE([
834
842
  ["", ["const ", resultsRef, "=[]"], ";"],
835
843
  ...children,
836
- ["", ["; return ", resultsRef]]
844
+ ["", "; "],
845
+ ["", wrapWithReturn(resultsRef)]
837
846
  ], async)
838
847
  );
839
848
  }
@@ -948,6 +957,7 @@ ${input.slice(result.pos)}
948
957
  part.children[3]?.token === ":" ? part.children[3] : ":",
949
958
  value,
950
959
  part.delim
960
+ // comma delimiter
951
961
  ]
952
962
  });
953
963
  }
@@ -956,8 +966,10 @@ ${input.slice(result.pos)}
956
966
  type: "ObjectExpression",
957
967
  children: [
958
968
  glob.object.children[0],
969
+ // {
959
970
  ...parts,
960
971
  glob.object.children.at(-1)
972
+ // whitespace and }
961
973
  ],
962
974
  properties: parts,
963
975
  hoistDec
@@ -972,12 +984,14 @@ ${input.slice(result.pos)}
972
984
  if (i === children.length - 1)
973
985
  return object;
974
986
  return processCallMemberExpression({
987
+ // in case there are more
975
988
  ...node,
976
989
  children: [object, ...children.slice(i + 1)]
977
990
  });
978
991
  } else if (glob?.type === "PropertyBind") {
979
992
  const prefix = children.slice(0, i);
980
993
  return processCallMemberExpression({
994
+ // in case there are more
981
995
  ...node,
982
996
  children: [
983
997
  prefix,
@@ -1113,35 +1127,41 @@ ${input.slice(result.pos)}
1113
1127
  ;
1114
1128
  return;
1115
1129
  }
1130
+ var relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
1131
+ function isRelationalOp(op) {
1132
+ return relationalOps.includes(op.token) || op.relational;
1133
+ }
1116
1134
  function expandChainedComparisons([first, binops]) {
1117
- const relationalOps = ["==", "===", "!=", "!==", "<", "<=", ">", ">=", "in"];
1118
1135
  const lowerPrecedenceOps = ["??", "&&", "||", "&", "|", "^"];
1119
- let results = [];
1136
+ const results = [];
1120
1137
  let i = 0;
1121
1138
  const l = binops.length;
1122
1139
  let start = 0;
1123
1140
  let chains = [];
1141
+ let op;
1124
1142
  while (i < l) {
1125
- const [, op] = binops[i];
1126
- if (relationalOps.includes(op.token) || op.relational) {
1143
+ [, op] = binops[i];
1144
+ if (isRelationalOp(op)) {
1127
1145
  chains.push(i);
1128
1146
  } else if (lowerPrecedenceOps.includes(op.token)) {
1129
- processChains();
1147
+ processChains(op);
1130
1148
  first = [];
1131
1149
  }
1132
1150
  i++;
1133
1151
  }
1134
- processChains();
1152
+ processChains(op);
1135
1153
  return results;
1136
- function processChains() {
1137
- first = expandExistence(first);
1154
+ function processChains(op2) {
1155
+ if (isRelationalOp(op2)) {
1156
+ first = expandExistence(first);
1157
+ }
1138
1158
  if (chains.length > 1) {
1139
1159
  chains.forEach((index, k) => {
1140
1160
  if (k > 0) {
1141
1161
  results.push(" ", "&&", " ");
1142
1162
  }
1143
1163
  const binop = binops[index];
1144
- let [pre, op, post, exp] = binop;
1164
+ let [pre, op3, post, exp] = binop;
1145
1165
  exp = binop[3] = expandExistence(exp);
1146
1166
  let endIndex;
1147
1167
  if (k < chains.length - 1) {
@@ -1297,7 +1317,6 @@ ${input.slice(result.pos)}
1297
1317
  default:
1298
1318
  return gatherNodes(node.children, predicate);
1299
1319
  }
1300
- return [];
1301
1320
  }
1302
1321
  function gatherRecursive(node, predicate, skipPredicate) {
1303
1322
  if (node == null)
@@ -1479,6 +1498,7 @@ ${input.slice(result.pos)}
1479
1498
  else
1480
1499
  exp.children.push(["", {
1481
1500
  type: "ReturnStatement",
1501
+ // NOTE: add a prefixed semi-colon because the if block may not be braced
1482
1502
  children: [";return"]
1483
1503
  }]);
1484
1504
  return;
@@ -1498,17 +1518,9 @@ ${input.slice(result.pos)}
1498
1518
  node.splice(1, 1, returnStatement);
1499
1519
  }
1500
1520
  function insertSwitchReturns(exp) {
1501
- switch (exp.type) {
1502
- case "SwitchStatement":
1503
- exp.caseBlock.clauses.forEach((clause) => {
1504
- insertReturn:
1505
- insertReturn(clause);
1506
- });
1507
- return;
1508
- case "SwitchExpression":
1509
- exp.caseBlock.clauses.forEach(insertReturn);
1510
- return;
1511
- }
1521
+ exp.caseBlock.clauses.forEach((clause) => {
1522
+ return insertReturn(clause);
1523
+ });
1512
1524
  }
1513
1525
  function isEmptyBareBlock(node) {
1514
1526
  if (node?.type !== "BlockStatement")
@@ -1647,6 +1659,7 @@ ${input.slice(result.pos)}
1647
1659
  declaration,
1648
1660
  blockPrefix,
1649
1661
  children: [awaits, eachOwnError, open, declaration, ws, inOf, expRef ?? exp, step, close]
1662
+ // omit declaration2, replace eachOwn with eachOwnError, replace exp with expRef
1650
1663
  };
1651
1664
  }
1652
1665
  let ws2, decl2;
@@ -1714,6 +1727,7 @@ ${input.slice(result.pos)}
1714
1727
  return {
1715
1728
  declaration,
1716
1729
  children: [awaits, eachOwnError, open, declaration, ws, inOf, exp, step, close],
1730
+ // omit declaration2, replace each with eachOwnError
1717
1731
  blockPrefix,
1718
1732
  hoistDec
1719
1733
  };
@@ -2090,14 +2104,6 @@ ${input.slice(result.pos)}
2090
2104
  return processReturn(f, config.implicitReturns);
2091
2105
  });
2092
2106
  }
2093
- function processSwitchExpressions(statements) {
2094
- gatherRecursiveAll(statements, (n) => n.type === "SwitchExpression").forEach(insertSwitchReturns);
2095
- }
2096
- function processTryExpressions(statements) {
2097
- gatherRecursiveAll(statements, (n) => n.type === "TryExpression").forEach(({ blocks }) => {
2098
- blocks.forEach(insertReturn);
2099
- });
2100
- }
2101
2107
  function processBindingPatternLHS(lhs, tail) {
2102
2108
  adjustAtBindings(lhs, true);
2103
2109
  const [splices, thisAssignments] = gatherBindingCode(lhs);
@@ -2477,7 +2483,7 @@ ${input.slice(result.pos)}
2477
2483
  return declarations;
2478
2484
  }
2479
2485
  function processPatternMatching(statements, ReservedWord) {
2480
- gatherRecursiveAll(statements, (n) => n.type === "SwitchStatement" || n.type === "SwitchExpression").forEach((s) => {
2486
+ gatherRecursiveAll(statements, (n) => n.type === "SwitchStatement").forEach((s) => {
2481
2487
  const { caseBlock } = s;
2482
2488
  const { clauses } = caseBlock;
2483
2489
  let errors = false;
@@ -2583,10 +2589,6 @@ ${input.slice(result.pos)}
2583
2589
  refAssignment = [];
2584
2590
  return prev = next;
2585
2591
  });
2586
- if (s.type === "SwitchExpression") {
2587
- insertReturn(root[0]);
2588
- root.splice(0, 1, wrapIIFE(root[0]));
2589
- }
2590
2592
  s.type = "PatternMatchingStatement";
2591
2593
  s.children = [root];
2592
2594
  return addParentPointers(s, s.parent);
@@ -2732,8 +2734,6 @@ ${input.slice(result.pos)}
2732
2734
  processPipelineExpressions(statements);
2733
2735
  processAssignments(statements);
2734
2736
  processPatternMatching(statements, ReservedWord);
2735
- processSwitchExpressions(statements);
2736
- processTryExpressions(statements);
2737
2737
  gatherRecursiveAll(statements, (n) => n.type === "IterationExpression").forEach((e) => expressionizeIteration(e));
2738
2738
  hoistRefDecs(statements);
2739
2739
  processFunctions(statements, config);
@@ -2970,20 +2970,31 @@ ${input.slice(result.pos)}
2970
2970
  if (post?.token === "?") {
2971
2971
  post = {
2972
2972
  $loc: post.$loc,
2973
- token: "!="
2973
+ token: " != null"
2974
2974
  };
2975
2975
  if (pre.length) {
2976
- exp = {
2977
- type: "UnaryExpression",
2978
- children: [...pre, exp, void 0]
2979
- };
2976
+ const lastPre = pre[pre.length - 1];
2977
+ if (lastPre.token === "!") {
2978
+ post.token = " == null";
2979
+ pre = pre.slice(0, -1);
2980
+ } else if (lastPre.length === 2 && lastPre[0].token === "!") {
2981
+ post.token = " == null";
2982
+ pre = pre.slice(0, -1);
2983
+ }
2980
2984
  }
2981
2985
  const existence = {
2982
2986
  type: "Existence",
2983
2987
  expression: exp,
2984
- children: [exp, " ", post, " ", "null"]
2988
+ children: [exp, post]
2985
2989
  };
2986
- return makeLeftHandSideExpression(existence);
2990
+ exp = makeLeftHandSideExpression(existence);
2991
+ if (pre.length) {
2992
+ return {
2993
+ type: "UnaryExpression",
2994
+ children: [...pre, exp]
2995
+ };
2996
+ }
2997
+ return exp;
2987
2998
  }
2988
2999
  if (exp.type === "Literal") {
2989
3000
  if (pre.length === 1 && pre[0].token === "-") {
@@ -3180,31 +3191,53 @@ ${input.slice(result.pos)}
3180
3191
  ;
3181
3192
  return;
3182
3193
  }
3183
- function wrapIIFE(exp, async) {
3184
- let prefix, suffix;
3194
+ function wrapIIFE(expressions, async) {
3195
+ let prefix;
3185
3196
  if (async) {
3186
- prefix = "(async ()=>";
3187
- suffix = ")()";
3188
- } else if (hasAwait(exp)) {
3189
- prefix = "(await (async ()=>";
3190
- suffix = ")())";
3191
- } else {
3192
- prefix = "(()=>";
3193
- suffix = ")()";
3197
+ async = "async ";
3198
+ } else if (hasAwait(expressions)) {
3199
+ async = "async ";
3200
+ prefix = {
3201
+ type: "Await",
3202
+ children: ["await "]
3203
+ };
3194
3204
  }
3195
- const expressions = Array.isArray(exp) ? [...exp] : [exp];
3196
3205
  const block = {
3197
3206
  type: "BlockStatement",
3198
3207
  expressions,
3199
3208
  children: ["{", expressions, "}"],
3200
3209
  bare: false
3201
3210
  };
3202
- updateParentPointers(block);
3203
- return [
3204
- prefix,
3211
+ const parameters = {
3212
+ type: "Parameters",
3213
+ children: ["()"],
3214
+ names: []
3215
+ };
3216
+ const signature = {
3217
+ modifier: {
3218
+ async: !!async
3219
+ },
3220
+ returnType: void 0
3221
+ };
3222
+ const fn = {
3223
+ type: "ArrowFunction",
3224
+ signature,
3225
+ parameters,
3226
+ returnType: void 0,
3227
+ ts: false,
3228
+ async,
3205
3229
  block,
3206
- suffix
3207
- ];
3230
+ children: [async, parameters, "=>", block]
3231
+ };
3232
+ updateParentPointers(block, fn);
3233
+ const exp = {
3234
+ type: "CallExpression",
3235
+ children: [makeLeftHandSideExpression(fn), "()"]
3236
+ };
3237
+ if (prefix) {
3238
+ return [makeLeftHandSideExpression([prefix, exp])];
3239
+ }
3240
+ return [exp];
3208
3241
  }
3209
3242
  module.exports = {
3210
3243
  addParentPointers,
@@ -3616,6 +3649,8 @@ ${input.slice(result.pos)}
3616
3649
  RestoreAll,
3617
3650
  ExpressionStatement,
3618
3651
  KeywordStatement,
3652
+ DebuggerStatement,
3653
+ ThrowStatement,
3619
3654
  Break,
3620
3655
  Continue,
3621
3656
  Debugger,
@@ -4709,6 +4744,8 @@ ${input.slice(result.pos)}
4709
4744
  return {
4710
4745
  type: "AssignmentExpression",
4711
4746
  children: $0,
4747
+ // NOTE: This null marks the assignment for later processing to distinguish it
4748
+ // from fake assignments that only add a name to a scope
4712
4749
  names: null,
4713
4750
  lhs: $1,
4714
4751
  assigned: $1[0][1],
@@ -4749,7 +4786,8 @@ ${input.slice(result.pos)}
4749
4786
  signature: {
4750
4787
  modifier: {
4751
4788
  async: !!async
4752
- }
4789
+ },
4790
+ returnType: suffix
4753
4791
  },
4754
4792
  parameters,
4755
4793
  returnType: suffix,
@@ -5347,6 +5385,7 @@ ${input.slice(result.pos)}
5347
5385
  var num = $3;
5348
5386
  return [
5349
5387
  { type: "PropertyAccess", children: [dot, "at"] },
5388
+ // not including `name` so that `{x.-1}` doesn't use it
5350
5389
  { type: "Call", children: ["(", neg, num, ")"] }
5351
5390
  ];
5352
5391
  });
@@ -5479,6 +5518,7 @@ ${input.slice(result.pos)}
5479
5518
  type: "PropertyBind",
5480
5519
  name: id.name,
5481
5520
  children: [modifier, dot, id]
5521
+ // omit `@` from children
5482
5522
  };
5483
5523
  });
5484
5524
  function PropertyBind(ctx, state) {
@@ -5574,6 +5614,7 @@ ${input.slice(result.pos)}
5574
5614
  open,
5575
5615
  tt,
5576
5616
  ...pes,
5617
+ // Remove delimiter
5577
5618
  { ...rest, children: rest.children.slice(0, -1) },
5578
5619
  close
5579
5620
  ],
@@ -5729,6 +5770,7 @@ ${input.slice(result.pos)}
5729
5770
  var c = $3;
5730
5771
  return {
5731
5772
  ...c,
5773
+ // names, blockPrefix, length
5732
5774
  type: "ArrayBindingPattern",
5733
5775
  elements: c.children,
5734
5776
  children: [$1, $2, c.children, $4, $5]
@@ -5753,6 +5795,7 @@ ${input.slice(result.pos)}
5753
5795
  return elements.map(([element, delim]) => {
5754
5796
  return {
5755
5797
  ...element,
5798
+ // BindingElement.children is a tuple of the form [ws, element]
5756
5799
  children: [...element.children, delim]
5757
5800
  };
5758
5801
  });
@@ -5769,6 +5812,7 @@ ${input.slice(result.pos)}
5769
5812
  return {
5770
5813
  ...element,
5771
5814
  children: [indent, ...element.children.slice(1)]
5815
+ // replace ws wth indent
5772
5816
  };
5773
5817
  });
5774
5818
  });
@@ -5998,6 +6042,7 @@ ${input.slice(result.pos)}
5998
6042
  },
5999
6043
  block: null,
6000
6044
  children: !parameters.implicit ? [async, func, generator, wid, w, parameters, suffix] : [async, func, generator, wid, parameters, w, suffix]
6045
+ // move whitespace w to after implicit () in parameters
6001
6046
  };
6002
6047
  });
6003
6048
  function FunctionSignature(ctx, state) {
@@ -6388,6 +6433,7 @@ ${input.slice(result.pos)}
6388
6433
  return {
6389
6434
  type: "BlockStatement",
6390
6435
  expressions: s.expressions,
6436
+ // Remove !EOS assertion
6391
6437
  children: [o, s.children, ws, c]
6392
6438
  };
6393
6439
  });
@@ -6406,6 +6452,7 @@ ${input.slice(result.pos)}
6406
6452
  return {
6407
6453
  type: "BlockStatement",
6408
6454
  expressions: s.expressions,
6455
+ // Remove !EOS assertion
6409
6456
  children: [o, s.children, ws, c]
6410
6457
  };
6411
6458
  });
@@ -6433,6 +6480,7 @@ ${input.slice(result.pos)}
6433
6480
  return {
6434
6481
  type: "BlockStatement",
6435
6482
  expressions: [s],
6483
+ // Remove &EOS assertion
6436
6484
  children: [$1, s, $3]
6437
6485
  };
6438
6486
  });
@@ -6456,6 +6504,7 @@ ${input.slice(result.pos)}
6456
6504
  type: "BlockStatement",
6457
6505
  expressions,
6458
6506
  children: [expressions],
6507
+ // avoid aliasing
6459
6508
  bare: true
6460
6509
  };
6461
6510
  });
@@ -6881,6 +6930,8 @@ ${input.slice(result.pos)}
6881
6930
  last = {
6882
6931
  ...last,
6883
6932
  delim,
6933
+ // __ will consume all whitespace that _? in PropertyDefinition could,
6934
+ // so replace _? (via slice) with __
6884
6935
  children: [ws, ...last.children.slice(1), delim]
6885
6936
  };
6886
6937
  return [...prop.slice(0, prop.length - 1), last];
@@ -7322,6 +7373,7 @@ ${input.slice(result.pos)}
7322
7373
  name,
7323
7374
  optional,
7324
7375
  modifier,
7376
+ // get/set/async/generator
7325
7377
  returnType,
7326
7378
  parameters
7327
7379
  };
@@ -7601,6 +7653,7 @@ ${input.slice(result.pos)}
7601
7653
  token: $1,
7602
7654
  relational: true,
7603
7655
  special: true
7656
+ // for typeof shorthand
7604
7657
  };
7605
7658
  });
7606
7659
  var BinaryOpSymbol$40 = $TS($S(Not, __, $EXPECT($L93, 'BinaryOpSymbol "instanceof"'), NonIdContinue), function($skip, $loc, $0, $1, $2, $3, $4) {
@@ -7893,6 +7946,7 @@ ${input.slice(result.pos)}
7893
7946
  condition = insertTrimmingSpace(condition, "");
7894
7947
  return {
7895
7948
  type: "IfStatement",
7949
+ // TODO: Don't add unnecessary parens
7896
7950
  children: [kind, ["(!", condition, ")"]],
7897
7951
  condition
7898
7952
  };
@@ -8429,12 +8483,12 @@ ${input.slice(result.pos)}
8429
8483
  return $EVENT(ctx, state, "EmptyCondition", EmptyCondition$0);
8430
8484
  }
8431
8485
  var SwitchExpression$0 = $TV(SwitchStatement, function($skip, $loc, $0, $1) {
8432
- var e = $0;
8486
+ var s = $0;
8433
8487
  return {
8434
8488
  type: "SwitchExpression",
8435
- children: wrapIIFE(e.children),
8436
- expression: e.expression,
8437
- caseBlock: e.caseBlock
8489
+ // wrap with IIFE
8490
+ children: wrapIIFE([["", s]]),
8491
+ statement: s
8438
8492
  };
8439
8493
  });
8440
8494
  function SwitchExpression(ctx, state) {
@@ -8474,6 +8528,7 @@ ${input.slice(result.pos)}
8474
8528
  var clause = $2;
8475
8529
  return {
8476
8530
  ...clause,
8531
+ // Bring the indent into the clause
8477
8532
  children: [indent, ...clause.children]
8478
8533
  };
8479
8534
  });
@@ -8625,7 +8680,7 @@ ${input.slice(result.pos)}
8625
8680
  return {
8626
8681
  type: "TryExpression",
8627
8682
  blocks: t.blocks,
8628
- children: wrapIIFE(t)
8683
+ children: wrapIIFE([["", t]])
8629
8684
  };
8630
8685
  });
8631
8686
  function TryExpression(ctx, state) {
@@ -8901,28 +8956,38 @@ ${input.slice(result.pos)}
8901
8956
  return {
8902
8957
  type: "BreakStatement",
8903
8958
  children: $2 ? [$1, $2[0], $2[2]] : [$1]
8959
+ // omit colon
8904
8960
  };
8905
8961
  });
8906
8962
  var KeywordStatement$1 = $TS($S(Continue, $E($S(_, $E(Colon), Identifier))), function($skip, $loc, $0, $1, $2) {
8907
8963
  return {
8908
8964
  type: "ContinueStatement",
8909
8965
  children: $2 ? [$1, $2[0], $2[2]] : [$1]
8966
+ // omit colon
8910
8967
  };
8911
8968
  });
8912
- var KeywordStatement$2 = $T($S(Debugger), function(value) {
8913
- return { "type": "DebuggerStatement", "children": value };
8914
- });
8969
+ var KeywordStatement$2 = DebuggerStatement;
8915
8970
  var KeywordStatement$3 = $T($S(Return, $N($C($EXPECT($L12, 'KeywordStatement ":"'), $EXPECT($L6, 'KeywordStatement "."'), AfterReturnShorthand)), $E(MaybeNestedExpression)), function(value) {
8916
8971
  var expression = value[2];
8917
8972
  return { "type": "ReturnStatement", "expression": expression, "children": value };
8918
8973
  });
8919
- var KeywordStatement$4 = $T($S(Throw, ExtendedExpression), function(value) {
8920
- return { "type": "ThrowStatement", "children": value };
8921
- });
8974
+ var KeywordStatement$4 = ThrowStatement;
8922
8975
  var KeywordStatement$$ = [KeywordStatement$0, KeywordStatement$1, KeywordStatement$2, KeywordStatement$3, KeywordStatement$4];
8923
8976
  function KeywordStatement(ctx, state) {
8924
8977
  return $EVENT_C(ctx, state, "KeywordStatement", KeywordStatement$$);
8925
8978
  }
8979
+ var DebuggerStatement$0 = $T($S(Debugger), function(value) {
8980
+ return { "type": "DebuggerStatement", "children": value };
8981
+ });
8982
+ function DebuggerStatement(ctx, state) {
8983
+ return $EVENT(ctx, state, "DebuggerStatement", DebuggerStatement$0);
8984
+ }
8985
+ var ThrowStatement$0 = $T($S(Throw, ExtendedExpression), function(value) {
8986
+ return { "type": "ThrowStatement", "children": value };
8987
+ });
8988
+ function ThrowStatement(ctx, state) {
8989
+ return $EVENT(ctx, state, "ThrowStatement", ThrowStatement$0);
8990
+ }
8926
8991
  var Break$0 = $TS($S($EXPECT($L102, 'Break "break"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
8927
8992
  return { $loc, token: $1 };
8928
8993
  });
@@ -8941,19 +9006,21 @@ ${input.slice(result.pos)}
8941
9006
  function Debugger(ctx, state) {
8942
9007
  return $EVENT(ctx, state, "Debugger", Debugger$0);
8943
9008
  }
8944
- var DebuggerExpression$0 = $TS($S(Debugger), function($skip, $loc, $0, $1) {
9009
+ var DebuggerExpression$0 = $TV(DebuggerStatement, function($skip, $loc, $0, $1) {
9010
+ var s = $0;
8945
9011
  return {
8946
9012
  type: "DebuggerExpression",
8947
- children: wrapIIFE($1)
9013
+ children: wrapIIFE([["", s]])
8948
9014
  };
8949
9015
  });
8950
9016
  function DebuggerExpression(ctx, state) {
8951
9017
  return $EVENT(ctx, state, "DebuggerExpression", DebuggerExpression$0);
8952
9018
  }
8953
- var ThrowExpression$0 = $TS($S(Throw, ExtendedExpression), function($skip, $loc, $0, $1, $2) {
9019
+ var ThrowExpression$0 = $TV(ThrowStatement, function($skip, $loc, $0, $1) {
9020
+ var s = $0;
8954
9021
  return {
8955
9022
  type: "ThrowExpression",
8956
- children: wrapIIFE($0)
9023
+ children: wrapIIFE([["", s]])
8957
9024
  };
8958
9025
  });
8959
9026
  function ThrowExpression(ctx, state) {
@@ -9502,6 +9569,7 @@ ${input.slice(result.pos)}
9502
9569
  if (hasSubstitutions) {
9503
9570
  const result = [
9504
9571
  { ...open, token: "RegExp(`" },
9572
+ // Escape backticks, backslashes, and '$' in the body text
9505
9573
  body.map(
9506
9574
  (e) => e.type === "Substitution" ? e : {
9507
9575
  ...e,
@@ -10381,7 +10449,9 @@ ${input.slice(result.pos)}
10381
10449
  parts = [
10382
10450
  ...$0,
10383
10451
  "\n",
10452
+ // InsertNewline
10384
10453
  module.currentIndent.token,
10454
+ // InsertIndent
10385
10455
  ["</", open[1], ">"]
10386
10456
  ];
10387
10457
  } else {
@@ -10449,7 +10519,9 @@ ${input.slice(result.pos)}
10449
10519
  const parts = close ? $0 : [
10450
10520
  ...$0,
10451
10521
  "\n",
10522
+ // InsertNewline
10452
10523
  module.currentIndent.token,
10524
+ // InsertIndent
10453
10525
  "</>"
10454
10526
  ];
10455
10527
  return { type: "JSXFragment", children: parts, jsxChildren: children.jsxChildren };
@@ -12036,9 +12108,11 @@ ${input.slice(result.pos)}
12036
12108
  react: false,
12037
12109
  solid: false,
12038
12110
  client: false,
12111
+ // default behavior: client only
12039
12112
  rewriteTsImports: true,
12040
12113
  server: false,
12041
12114
  tab: void 0,
12115
+ // default behavior = same as space
12042
12116
  verbose: false
12043
12117
  };
12044
12118
  const asAny = {
@@ -12176,7 +12250,12 @@ ${input.slice(result.pos)}
12176
12250
  type: "ParserMeta",
12177
12251
  children: [],
12178
12252
  getStateKey() {
12179
- const stateInt = module.currentIndent.level % 256 << 8 | module.classImplicitCallForbidden << 7 | module.indentedApplicationForbidden << 6 | module.bracedApplicationForbidden << 5 | module.trailingMemberPropertyForbidden << 4 | module.newlineBinaryOpForbidden << 3 | module.config.coffeeComment << 2;
12253
+ const stateInt = module.currentIndent.level % 256 << 8 | module.classImplicitCallForbidden << 7 | module.indentedApplicationForbidden << 6 | module.bracedApplicationForbidden << 5 | module.trailingMemberPropertyForbidden << 4 | module.newlineBinaryOpForbidden << 3 | // This is slightly different than the rest of the state,
12254
+ // since it is affected by the directive prologue and may be hit
12255
+ // by the EOL rule early in the parse. Later if we wanted to
12256
+ // allow block scoping of the compat directives we would need to
12257
+ // add them all here.
12258
+ module.config.coffeeComment << 2;
12180
12259
  return [stateInt, module.currentJSXTag];
12181
12260
  }
12182
12261
  };
@@ -12201,7 +12280,8 @@ ${input.slice(result.pos)}
12201
12280
  if (module.config.tab) {
12202
12281
  const tabs = $0.match(/\t/g);
12203
12282
  const numTabs = tabs ? tabs.length : 0;
12204
- level = numTabs * module.config.tab + ($0.length - numTabs);
12283
+ level = numTabs * module.config.tab + /*spaces*/
12284
+ ($0.length - numTabs);
12205
12285
  } else {
12206
12286
  level = $0.length;
12207
12287
  }
@@ -12624,6 +12704,8 @@ ${input.slice(result.pos)}
12624
12704
  exports.RestoreAll = RestoreAll;
12625
12705
  exports.ExpressionStatement = ExpressionStatement;
12626
12706
  exports.KeywordStatement = KeywordStatement;
12707
+ exports.DebuggerStatement = DebuggerStatement;
12708
+ exports.ThrowStatement = ThrowStatement;
12627
12709
  exports.Break = Break;
12628
12710
  exports.Continue = Continue;
12629
12711
  exports.Debugger = Debugger;
@@ -13453,6 +13535,10 @@ ${input.slice(result.pos)}
13453
13535
  get(key) {
13454
13536
  return this.cache.get(key[0])?.get(key[1])?.get(key[2])?.get(key[3]);
13455
13537
  }
13538
+ /**
13539
+ * Check if this multi-layer cache has the given key.
13540
+ * Since the intermediate layers are always other maps we only need to check the last layer.
13541
+ */
13456
13542
  has(key) {
13457
13543
  return !!this.cache.get(key[0])?.get(key[1])?.get(key[2])?.has(key[3]);
13458
13544
  }
@@ -13487,16 +13573,23 @@ ${input.slice(result.pos)}
13487
13573
  var { parse } = import_parser.default;
13488
13574
  var { SourceMap: SourceMap2 } = util_exports;
13489
13575
  var uncacheable = /* @__PURE__ */ new Set([
13576
+ // Meta
13490
13577
  "DebugHere",
13491
13578
  "Init",
13492
13579
  "Program",
13493
13580
  "Reset",
13581
+ // Indentation
13582
+ // We need to no-cache the state modifying rules up to the point where they
13583
+ // balance within a parent so PushIndent needs to be marked no-cache even
13584
+ // though it only calls TrackIndented which does the actual work.
13494
13585
  "PushIndent",
13495
13586
  "PopIndent",
13496
13587
  "TrackIndented",
13588
+ // JSX
13497
13589
  "PushJSXOpeningElement",
13498
13590
  "PushJSXOpeningFragment",
13499
13591
  "PopJSXStack",
13592
+ // State
13500
13593
  "AllowAll",
13501
13594
  "AllowClassImplicitCall",
13502
13595
  "AllowBracedApplication",
@@ -13599,7 +13692,8 @@ ${input.slice(result.pos)}
13599
13692
  return events;
13600
13693
  }
13601
13694
  var isCompileError = function(err) {
13602
- return err instanceof Error && [err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
13695
+ return err instanceof Error && //@ts-ignore
13696
+ [err.message, err.name, err.filename, err.line, err.column, err.offset].every(($1) => $1 !== void 0);
13603
13697
  };
13604
13698
  var main_default = { parse, generate: generate_default, util: util_exports, compile, isCompileError };
13605
13699
  return __toCommonJS(main_exports);