@danielx/civet 0.7.29 → 0.7.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.mjs CHANGED
@@ -658,7 +658,7 @@ var statementTypes = /* @__PURE__ */ new Set([
658
658
  "ForStatement",
659
659
  "IfStatement",
660
660
  "IterationStatement",
661
- "LabeledStatement",
661
+ "LabelledStatement",
662
662
  "ReturnStatement",
663
663
  "SwitchStatement",
664
664
  "ThrowStatement",
@@ -703,13 +703,16 @@ function isExit(node) {
703
703
  return node.expressions.some((s) => isExit(s[1]));
704
704
  }
705
705
  case "IterationStatement": {
706
- return node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true" && gatherRecursiveWithinFunction(node.block, ($) => $.type === "BreakStatement").length === 0;
706
+ return isLoopStatement(node) && gatherRecursiveWithinFunction(node.block, ($) => $.type === "BreakStatement").length === 0;
707
707
  }
708
708
  default: {
709
709
  return false;
710
710
  }
711
711
  }
712
712
  }
713
+ function isLoopStatement(node) {
714
+ return node.type === "IterationStatement" && node.condition?.type === "ParenthesizedExpression" && node.condition.expression?.type === "Literal" && node.condition.expression?.raw === "true";
715
+ }
713
716
  function isComma(node) {
714
717
  if (node?.token === ",") {
715
718
  return node;
@@ -1075,7 +1078,7 @@ function parenthesizeType(type) {
1075
1078
  }
1076
1079
  return ["(", type, ")"];
1077
1080
  }
1078
- function wrapIIFE(expressions, asyncFlag) {
1081
+ function wrapIIFE(expressions, asyncFlag, generator) {
1079
1082
  let prefix;
1080
1083
  const async = [];
1081
1084
  if (asyncFlag) {
@@ -1101,23 +1104,49 @@ function wrapIIFE(expressions, asyncFlag) {
1101
1104
  };
1102
1105
  const signature = {
1103
1106
  modifier: {
1104
- async: !!async.length
1107
+ async: !!async.length,
1108
+ generator: !!generator
1105
1109
  },
1106
1110
  returnType: void 0
1107
1111
  };
1108
- const fn = makeNode({
1109
- type: "ArrowFunction",
1110
- signature,
1111
- parameters,
1112
- returnType: void 0,
1113
- ts: false,
1114
- async,
1115
- block,
1116
- children: [async, parameters, "=>", block]
1117
- });
1112
+ let fn;
1113
+ if (generator) {
1114
+ fn = makeNode({
1115
+ type: "FunctionExpression",
1116
+ signature,
1117
+ parameters,
1118
+ returnType: void 0,
1119
+ ts: false,
1120
+ async,
1121
+ block,
1122
+ generator,
1123
+ children: [async, "function", generator, parameters, block]
1124
+ });
1125
+ } else {
1126
+ fn = makeNode({
1127
+ type: "ArrowFunction",
1128
+ signature,
1129
+ parameters,
1130
+ returnType: void 0,
1131
+ ts: false,
1132
+ async,
1133
+ block,
1134
+ children: [async, parameters, "=>", block]
1135
+ });
1136
+ }
1137
+ const children = [makeLeftHandSideExpression(fn), "()"];
1138
+ if (fn.type === "FunctionExpression") {
1139
+ if (gatherRecursiveWithinFunction(block, (a1) => typeof a1 === "object" && a1 != null && "token" in a1 && a1.token === "this").length) {
1140
+ children.splice(1, 0, ".bind(this)");
1141
+ }
1142
+ if (gatherRecursiveWithinFunction(block, (a2) => typeof a2 === "object" && a2 != null && "token" in a2 && a2.token === "arguments").length) {
1143
+ let ref2;
1144
+ children[children.length - 1] = (ref2 = parameters.children)[ref2.length - 1] = "(arguments)";
1145
+ }
1146
+ }
1118
1147
  const exp = makeNode({
1119
1148
  type: "CallExpression",
1120
- children: [makeLeftHandSideExpression(fn), "()"]
1149
+ children
1121
1150
  });
1122
1151
  if (prefix) {
1123
1152
  return makeLeftHandSideExpression([prefix, exp]);
@@ -1738,7 +1767,7 @@ function assignResults(node, collect) {
1738
1767
  ({ type } = exp);
1739
1768
  }
1740
1769
  let ref4;
1741
- switch (exp.type) {
1770
+ switch (type) {
1742
1771
  case "BreakStatement":
1743
1772
  case "ContinueStatement":
1744
1773
  case "DebuggerStatement":
@@ -1959,6 +1988,58 @@ function insertSwitchReturns(exp) {
1959
1988
  return insertReturn(clause);
1960
1989
  });
1961
1990
  }
1991
+ function processBreakContinueWith(statement) {
1992
+ let changed = false;
1993
+ for (const control of gatherRecursiveWithinFunction(
1994
+ statement.block,
1995
+ ($) => $.type === "BreakStatement" || $.type === "ContinueStatement"
1996
+ )) {
1997
+ let controlName2 = function() {
1998
+ switch (control.type) {
1999
+ case "BreakStatement": {
2000
+ return "break";
2001
+ }
2002
+ case "ContinueStatement": {
2003
+ return "continue";
2004
+ }
2005
+ }
2006
+ };
2007
+ var controlName = controlName2;
2008
+ if (control.with) {
2009
+ if (control.label) {
2010
+ let m1;
2011
+ if (!(m1 = statement.parent, typeof m1 === "object" && m1 != null && "type" in m1 && m1.type === "LabelledStatement" && "label" in m1 && typeof m1.label === "object" && m1.label != null && "name" in m1.label && m1.label.name === control.label.name)) {
2012
+ continue;
2013
+ }
2014
+ } else {
2015
+ const { ancestor } = findAncestor(
2016
+ control,
2017
+ (s) => s === statement || s.type === "IterationStatement" || s.type === "ForStatement" || s.type === "SwitchStatement" && control.type === "BreakStatement"
2018
+ );
2019
+ if (!(ancestor === statement)) {
2020
+ continue;
2021
+ }
2022
+ }
2023
+ control.children.unshift(
2024
+ control.type === "BreakStatement" ? (changed = true, [statement.resultsRef, " =", control.with, ";"]) : (
2025
+ // control.type is "ContinueStatement"
2026
+ [statement.resultsRef, ".push(", trimFirstSpace(control.with), ");"]
2027
+ )
2028
+ );
2029
+ updateParentPointers(control.with, control);
2030
+ const i = control.children.findIndex(($1) => $1?.type === "Error");
2031
+ if (i >= 0) {
2032
+ control.children.splice(i, 1);
2033
+ }
2034
+ const block = control.parent;
2035
+ if (!(block?.type === "BlockStatement")) {
2036
+ throw new Error(`Expected parent of ${controlName2()} to be BlockStatement`);
2037
+ }
2038
+ braceBlock(block);
2039
+ }
2040
+ }
2041
+ return changed;
2042
+ }
1962
2043
  function wrapIterationReturningResults(statement, outer, collect) {
1963
2044
  if (statement.type === "DoStatement" || statement.type === "ComptimeStatement") {
1964
2045
  if (collect) {
@@ -1974,14 +2055,37 @@ function wrapIterationReturningResults(statement, outer, collect) {
1974
2055
  "wrapIterationReturningResults should not be called twice on the same statement"
1975
2056
  );
1976
2057
  const resultsRef = statement.resultsRef = makeRef("results");
2058
+ let decl = "const";
2059
+ if (statement.type === "IterationStatement" || statement.type === "ForStatement") {
2060
+ if (processBreakContinueWith(statement)) {
2061
+ decl = "let";
2062
+ }
2063
+ }
2064
+ const breakWithOnly = decl === "let" && isLoopStatement(statement) && gatherRecursive(
2065
+ statement.block,
2066
+ (s) => s.type === "BreakStatement" && !s.with,
2067
+ (s) => isFunction(s) || s.type === "IterationStatement"
2068
+ ).length === 0;
1977
2069
  const declaration = {
1978
2070
  type: "Declaration",
1979
- children: ["const ", resultsRef, "=[]"]
2071
+ children: [decl, " ", resultsRef],
2072
+ decl,
2073
+ names: [],
2074
+ bindings: []
1980
2075
  };
2076
+ if (decl === "const") {
2077
+ declaration.children.push("=[]");
2078
+ } else {
2079
+ if (!breakWithOnly) {
2080
+ declaration.children.push(";", resultsRef, "=[]");
2081
+ }
2082
+ }
1981
2083
  outer.children.unshift(["", declaration, ";"]);
1982
- assignResults(statement.block, (node) => {
1983
- return [resultsRef, ".push(", node, ")"];
1984
- });
2084
+ if (!breakWithOnly) {
2085
+ assignResults(statement.block, (node) => {
2086
+ return [resultsRef, ".push(", node, ")"];
2087
+ });
2088
+ }
1985
2089
  if (collect) {
1986
2090
  statement.children.push(collect(resultsRef));
1987
2091
  } else {
@@ -2047,8 +2151,8 @@ function processSignature(f) {
2047
2151
  }
2048
2152
  if (hasYield(block) && !f.generator?.length) {
2049
2153
  if (f.type === "ArrowFunction") {
2050
- gatherRecursiveWithinFunction(block, ($) => $.type === "YieldExpression").forEach((y) => {
2051
- const i = y.children.findIndex(($1) => $1.type === "Yield");
2154
+ gatherRecursiveWithinFunction(block, ($2) => $2.type === "YieldExpression").forEach((y) => {
2155
+ const i = y.children.findIndex(($3) => $3.type === "Yield");
2052
2156
  return y.children.splice(i + 1, 0, {
2053
2157
  type: "Error",
2054
2158
  message: "Can't use yield inside of => arrow function"
@@ -2076,31 +2180,55 @@ function processFunctions(statements, config2) {
2076
2180
  });
2077
2181
  }
2078
2182
  function expressionizeIteration(exp) {
2079
- const { async, subtype, block, children, statement } = exp;
2183
+ const { async, generator, subtype, block, children, statement } = exp;
2080
2184
  const i = children.indexOf(statement);
2081
2185
  if (i < 0) {
2082
2186
  throw new Error("Could not find iteration statement in iteration expression");
2083
2187
  }
2084
2188
  if (subtype === "DoStatement" || subtype === "ComptimeStatement") {
2085
- children.splice(i, 1, wrapIIFE([["", statement, void 0]], async));
2189
+ children.splice(i, 1, wrapIIFE([["", statement, void 0]], async, generator));
2086
2190
  updateParentPointers(exp);
2087
2191
  return;
2088
2192
  }
2089
- exp.resultsRef ??= makeRef("results");
2090
- const { resultsRef } = exp;
2091
- assignResults(block, (node) => {
2092
- return [resultsRef, ".push(", node, ")"];
2093
- });
2094
- braceBlock(block);
2095
- children.splice(
2096
- i,
2097
- 1,
2098
- wrapIIFE([
2099
- ["", ["const ", resultsRef, "=[]"], ";"],
2100
- ...children.map((c) => ["", c, void 0]),
2101
- ["", wrapWithReturn(resultsRef)]
2102
- ], async)
2103
- );
2193
+ if (generator) {
2194
+ assignResults(block, (node) => {
2195
+ return {
2196
+ type: "YieldExpression",
2197
+ expression: node,
2198
+ children: ["yield ", node]
2199
+ };
2200
+ });
2201
+ braceBlock(block);
2202
+ children.splice(
2203
+ i,
2204
+ 1,
2205
+ wrapIIFE([
2206
+ ["", statement, void 0],
2207
+ // Prevent implicit return in generator, by adding an explicit return
2208
+ ["", {
2209
+ type: "ReturnStatement",
2210
+ expression: void 0,
2211
+ children: [";return"]
2212
+ }, void 0]
2213
+ ], async, generator)
2214
+ );
2215
+ } else {
2216
+ exp.resultsRef ??= makeRef("results");
2217
+ const { resultsRef } = exp;
2218
+ assignResults(block, (node) => {
2219
+ return [resultsRef, ".push(", node, ")"];
2220
+ });
2221
+ braceBlock(block);
2222
+ children.splice(
2223
+ i,
2224
+ 1,
2225
+ wrapIIFE([
2226
+ ["", ["const ", resultsRef, "=[]"], ";"],
2227
+ ["", statement, void 0],
2228
+ ["", wrapWithReturn(resultsRef)]
2229
+ ], async)
2230
+ );
2231
+ }
2104
2232
  updateParentPointers(exp);
2105
2233
  }
2106
2234
  function skipImplicitArguments(args) {
@@ -2114,7 +2242,7 @@ function skipImplicitArguments(args) {
2114
2242
  return false;
2115
2243
  }
2116
2244
  function processCoffeeDo(ws, expression) {
2117
- ws = insertTrimmingSpace(ws, "");
2245
+ ws = trimFirstSpace(ws);
2118
2246
  const args = [];
2119
2247
  if (typeof expression === "object" && expression != null && "type" in expression && expression.type === "ArrowFunction" || typeof expression === "object" && expression != null && "type" in expression && expression.type === "FunctionExpression") {
2120
2248
  const { parameters } = expression;
@@ -2148,7 +2276,7 @@ function processCoffeeDo(ws, expression) {
2148
2276
  expression = {
2149
2277
  ...expression,
2150
2278
  parameters: newParameters,
2151
- children: expression.children.map(($2) => $2 === parameters ? newParameters : $2)
2279
+ children: expression.children.map(($4) => $4 === parameters ? newParameters : $4)
2152
2280
  };
2153
2281
  }
2154
2282
  return {
@@ -2169,7 +2297,7 @@ function makeAmpersandFunction(rhs) {
2169
2297
  ref = makeRef("$");
2170
2298
  inplacePrepend(ref, body);
2171
2299
  }
2172
- if (startsWithPredicate(body, ($3) => $3.type === "ObjectExpression")) {
2300
+ if (startsWithPredicate(body, ($5) => $5.type === "ObjectExpression")) {
2173
2301
  body = makeLeftHandSideExpression(body);
2174
2302
  }
2175
2303
  const parameters = makeNode({
@@ -3430,7 +3558,7 @@ function prependStatementExpressionBlock(initializer, statement) {
3430
3558
  const blockStatement = ["", statementExp];
3431
3559
  let ref;
3432
3560
  if (statementExp.type === "IterationExpression") {
3433
- if (statementExp.async) {
3561
+ if (statementExp.async || statementExp.generator) {
3434
3562
  return;
3435
3563
  }
3436
3564
  const statement2 = statementExp.statement;
@@ -5978,7 +6106,8 @@ function attachPostfixStatementAsExpression(exp, post) {
5978
6106
  type: "IterationExpression",
5979
6107
  children: [statement],
5980
6108
  block: statement.block,
5981
- statement
6109
+ statement,
6110
+ generator: statement.generator
5982
6111
  };
5983
6112
  }
5984
6113
  case "IfStatement": {
@@ -6505,6 +6634,7 @@ var grammar = {
6505
6634
  ReservedBinary,
6506
6635
  ArgumentsWithTrailingMemberExpressions,
6507
6636
  TrailingMemberExpressions,
6637
+ IndentedTrailingMemberExpression,
6508
6638
  AllowedTrailingMemberExpressions,
6509
6639
  TrailingCallExpressions,
6510
6640
  AllowedTrailingCallExpressions,
@@ -6773,6 +6903,7 @@ var grammar = {
6773
6903
  BlockStatement,
6774
6904
  LabelledStatement,
6775
6905
  Label,
6906
+ LabelIdentifier,
6776
6907
  LabelledItem,
6777
6908
  IfStatement,
6778
6909
  ElseClause,
@@ -7832,7 +7963,7 @@ var ExplicitArguments$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(OpenParen, (0
7832
7963
  function ExplicitArguments(ctx, state2) {
7833
7964
  return (0, import_lib3.$EVENT)(ctx, state2, "ExplicitArguments", ExplicitArguments$0);
7834
7965
  }
7835
- var ApplicationStart$0 = (0, import_lib3.$S)(IndentedApplicationAllowed, (0, import_lib3.$Y)((0, import_lib3.$S)(IndentedFurther, (0, import_lib3.$N)(IdentifierBinaryOp), (0, import_lib3.$N)(AccessStart))));
7966
+ var ApplicationStart$0 = (0, import_lib3.$S)(IndentedApplicationAllowed, (0, import_lib3.$Y)((0, import_lib3.$S)(IndentedFurther, (0, import_lib3.$N)(IdentifierBinaryOp))), (0, import_lib3.$N)(IndentedTrailingMemberExpression));
7836
7967
  var ApplicationStart$1 = (0, import_lib3.$S)((0, import_lib3.$N)(EOS), (0, import_lib3.$Y)((0, import_lib3.$S)(_, (0, import_lib3.$C)(BracedApplicationAllowed, (0, import_lib3.$N)((0, import_lib3.$EXPECT)($L1, 'ApplicationStart "{"'))), (0, import_lib3.$N)(ForbiddenImplicitCalls))));
7837
7968
  var ApplicationStart$$ = [ApplicationStart$0, ApplicationStart$1];
7838
7969
  function ApplicationStart(ctx, state2) {
@@ -7873,20 +8004,20 @@ var ArgumentsWithTrailingMemberExpressions$0 = (0, import_lib3.$TS)((0, import_l
7873
8004
  function ArgumentsWithTrailingMemberExpressions(ctx, state2) {
7874
8005
  return (0, import_lib3.$EVENT)(ctx, state2, "ArgumentsWithTrailingMemberExpressions", ArgumentsWithTrailingMemberExpressions$0);
7875
8006
  }
7876
- var TrailingMemberExpressions$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$Q)(MemberExpressionRest), (0, import_lib3.$Q)((0, import_lib3.$S)(IndentedAtLeast, (0, import_lib3.$Y)((0, import_lib3.$S)((0, import_lib3.$E)((0, import_lib3.$EXPECT)($L6, 'TrailingMemberExpressions "?"')), (0, import_lib3.$EXPECT)($L7, 'TrailingMemberExpressions "."'), (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R3, "TrailingMemberExpressions /[0-9]/")))), MemberExpressionRest))), function($skip, $loc, $0, $1, $2) {
7877
- return $1.concat($2.map(([ws, , memberExpressionRest]) => {
7878
- if (Array.isArray(memberExpressionRest)) {
7879
- return [ws, ...memberExpressionRest];
7880
- }
7881
- return {
7882
- ...memberExpressionRest,
7883
- children: [ws, ...memberExpressionRest.children]
7884
- };
7885
- }));
8007
+ var TrailingMemberExpressions$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$Q)(MemberExpressionRest), (0, import_lib3.$Q)(IndentedTrailingMemberExpression)), function($skip, $loc, $0, $1, $2) {
8008
+ return [...$1, ...$2];
7886
8009
  });
7887
8010
  function TrailingMemberExpressions(ctx, state2) {
7888
8011
  return (0, import_lib3.$EVENT)(ctx, state2, "TrailingMemberExpressions", TrailingMemberExpressions$0);
7889
8012
  }
8013
+ var IndentedTrailingMemberExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(IndentedAtLeast, (0, import_lib3.$Y)((0, import_lib3.$S)((0, import_lib3.$E)((0, import_lib3.$EXPECT)($L6, 'IndentedTrailingMemberExpression "?"')), (0, import_lib3.$EXPECT)($L7, 'IndentedTrailingMemberExpression "."'), (0, import_lib3.$N)((0, import_lib3.$EXPECT)($R3, "IndentedTrailingMemberExpression /[0-9]/")))), MemberExpressionRest), function($skip, $loc, $0, $1, $2, $3) {
8014
+ var ws = $1;
8015
+ var rest = $3;
8016
+ return prepend(ws, rest);
8017
+ });
8018
+ function IndentedTrailingMemberExpression(ctx, state2) {
8019
+ return (0, import_lib3.$EVENT)(ctx, state2, "IndentedTrailingMemberExpression", IndentedTrailingMemberExpression$0);
8020
+ }
7890
8021
  var AllowedTrailingMemberExpressions$0 = (0, import_lib3.$T)((0, import_lib3.$S)(TrailingMemberPropertyAllowed, TrailingMemberExpressions), function(value) {
7891
8022
  return value[1];
7892
8023
  });
@@ -12430,8 +12561,10 @@ var Statement$1 = VariableStatement;
12430
12561
  var Statement$2 = (0, import_lib3.$T)((0, import_lib3.$S)(IfStatement, (0, import_lib3.$N)(ShouldExpressionize)), function(value) {
12431
12562
  return value[0];
12432
12563
  });
12433
- var Statement$3 = (0, import_lib3.$T)((0, import_lib3.$S)(IterationStatement, (0, import_lib3.$N)(ShouldExpressionize)), function(value) {
12434
- return value[0];
12564
+ var Statement$3 = (0, import_lib3.$TS)((0, import_lib3.$S)(IterationStatement, (0, import_lib3.$N)(ShouldExpressionize)), function($skip, $loc, $0, $1, $2) {
12565
+ if ($1.generator)
12566
+ return $skip;
12567
+ return $1;
12435
12568
  });
12436
12569
  var Statement$4 = (0, import_lib3.$T)((0, import_lib3.$S)(SwitchStatement, (0, import_lib3.$N)(ShouldExpressionize)), function(value) {
12437
12570
  return value[0];
@@ -12502,11 +12635,22 @@ var Label$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Colon, Identifier, Whites
12502
12635
  var colon = $1;
12503
12636
  var id = $2;
12504
12637
  var w = $3;
12505
- return [id, colon, w];
12638
+ return {
12639
+ type: "Label",
12640
+ name: id.name,
12641
+ children: [id, colon, w]
12642
+ };
12506
12643
  });
12507
12644
  function Label(ctx, state2) {
12508
12645
  return (0, import_lib3.$EVENT)(ctx, state2, "Label", Label$0);
12509
12646
  }
12647
+ var LabelIdentifier$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$E)(Colon), Identifier), function(value) {
12648
+ var id = value[1];
12649
+ return id;
12650
+ });
12651
+ function LabelIdentifier(ctx, state2) {
12652
+ return (0, import_lib3.$EVENT)(ctx, state2, "LabelIdentifier", LabelIdentifier$0);
12653
+ }
12510
12654
  var LabelledItem$0 = Statement;
12511
12655
  var LabelledItem$1 = FunctionDeclaration;
12512
12656
  var LabelledItem$$ = [LabelledItem$0, LabelledItem$1];
@@ -12603,7 +12747,8 @@ var IterationExpression$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_
12603
12747
  children: [statement],
12604
12748
  block: statement.block,
12605
12749
  statement,
12606
- async
12750
+ async,
12751
+ generator: statement.generator
12607
12752
  };
12608
12753
  });
12609
12754
  function IterationExpression(ctx, state2) {
@@ -12622,8 +12767,9 @@ var LoopStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(LoopClause, Block
12622
12767
  function LoopStatement(ctx, state2) {
12623
12768
  return (0, import_lib3.$EVENT)(ctx, state2, "LoopStatement", LoopStatement$0);
12624
12769
  }
12625
- var LoopClause$0 = (0, import_lib3.$TV)(Loop, function($skip, $loc, $0, $1) {
12626
- var kind = $0;
12770
+ var LoopClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Loop, (0, import_lib3.$E)((0, import_lib3.$S)((0, import_lib3.$E)(_), Star))), function($skip, $loc, $0, $1, $2) {
12771
+ var kind = $1;
12772
+ var generator = $2;
12627
12773
  const expression = {
12628
12774
  type: "Literal",
12629
12775
  children: ["true"],
@@ -12638,33 +12784,41 @@ var LoopClause$0 = (0, import_lib3.$TV)(Loop, function($skip, $loc, $0, $1) {
12638
12784
  type: "IterationStatement",
12639
12785
  subtype: kind.token,
12640
12786
  children: [kind, condition],
12641
- condition
12787
+ condition,
12788
+ generator
12642
12789
  };
12643
12790
  });
12644
12791
  function LoopClause(ctx, state2) {
12645
12792
  return (0, import_lib3.$EVENT)(ctx, state2, "LoopClause", LoopClause$0);
12646
12793
  }
12647
- var DoWhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Do, NoPostfixBracedOrEmptyBlock, __, WhileClause), function($skip, $loc, $0, $1, $2, $3, $4) {
12648
- var block = $2;
12649
- var clause = $4;
12794
+ var DoWhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Do, (0, import_lib3.$E)((0, import_lib3.$S)((0, import_lib3.$E)(_), Star)), NoPostfixBracedOrEmptyBlock, __, WhileClause), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
12795
+ var d = $1;
12796
+ var generator = $2;
12797
+ var block = $3;
12798
+ var ws = $4;
12799
+ var clause = $5;
12650
12800
  return {
12651
12801
  ...clause,
12652
12802
  type: "IterationStatement",
12653
12803
  subtype: "do-while",
12654
- children: $0,
12655
- block
12804
+ children: [d, block, ws, clause],
12805
+ block,
12806
+ generator
12656
12807
  };
12657
12808
  });
12658
12809
  function DoWhileStatement(ctx, state2) {
12659
12810
  return (0, import_lib3.$EVENT)(ctx, state2, "DoWhileStatement", DoWhileStatement$0);
12660
12811
  }
12661
- var DoStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Do, NoPostfixBracedOrEmptyBlock), function($skip, $loc, $0, $1, $2) {
12662
- var block = $2;
12812
+ var DoStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Do, (0, import_lib3.$E)((0, import_lib3.$S)((0, import_lib3.$E)(_), Star)), NoPostfixBracedOrEmptyBlock), function($skip, $loc, $0, $1, $2, $3) {
12813
+ var d = $1;
12814
+ var generator = $2;
12815
+ var block = $3;
12663
12816
  block = trimFirstSpace(block);
12664
12817
  return {
12665
12818
  type: "DoStatement",
12666
12819
  children: [block],
12667
- block
12820
+ block,
12821
+ generator
12668
12822
  };
12669
12823
  });
12670
12824
  function DoStatement(ctx, state2) {
@@ -12699,10 +12853,11 @@ var WhileStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(WhileClause, Blo
12699
12853
  function WhileStatement(ctx, state2) {
12700
12854
  return (0, import_lib3.$EVENT)(ctx, state2, "WhileStatement", WhileStatement$0);
12701
12855
  }
12702
- var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)(While, Until), (0, import_lib3.$E)(_), Condition), function($skip, $loc, $0, $1, $2, $3) {
12856
+ var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)(While, Until), (0, import_lib3.$E)((0, import_lib3.$S)((0, import_lib3.$E)(_), Star)), (0, import_lib3.$E)(_), Condition), function($skip, $loc, $0, $1, $2, $3, $4) {
12703
12857
  var kind = $1;
12704
- var ws = $2;
12705
- var condition = $3;
12858
+ var generator = $2;
12859
+ var ws = $3;
12860
+ var condition = $4;
12706
12861
  if (kind.negated) {
12707
12862
  kind = { ...kind, token: "while" };
12708
12863
  condition = negateCondition(condition);
@@ -12712,6 +12867,7 @@ var WhileClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$C)
12712
12867
  subtype: kind.token,
12713
12868
  children: [kind, ws, condition],
12714
12869
  condition,
12870
+ generator,
12715
12871
  negated: kind.negated
12716
12872
  };
12717
12873
  });
@@ -12731,16 +12887,18 @@ var ForStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(ForClause, BlockOr
12731
12887
  function ForStatement(ctx, state2) {
12732
12888
  return (0, import_lib3.$EVENT)(ctx, state2, "ForStatement", ForStatement$0);
12733
12889
  }
12734
- var ForClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(For, __, ForStatementControl), function($skip, $loc, $0, $1, $2, $3) {
12735
- var c = $3;
12890
+ var ForClause$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(For, (0, import_lib3.$E)((0, import_lib3.$S)((0, import_lib3.$E)(_), Star)), __, ForStatementControl), function($skip, $loc, $0, $1, $2, $3, $4) {
12891
+ var generator = $2;
12892
+ var c = $4;
12736
12893
  const { children, declaration } = c;
12737
12894
  return {
12738
12895
  type: "ForStatement",
12739
- children: [$1, ...$2, ...children],
12896
+ children: [$1, ...$3, ...children],
12740
12897
  declaration,
12741
12898
  block: null,
12742
12899
  blockPrefix: c.blockPrefix,
12743
- hoistDec: c.hoistDec
12900
+ hoistDec: c.hoistDec,
12901
+ generator
12744
12902
  };
12745
12903
  });
12746
12904
  function ForClause(ctx, state2) {
@@ -13507,11 +13665,21 @@ var ExpressionStatement$$ = [ExpressionStatement$0, ExpressionStatement$1];
13507
13665
  function ExpressionStatement(ctx, state2) {
13508
13666
  return (0, import_lib3.$EVENT_C)(ctx, state2, "ExpressionStatement", ExpressionStatement$$);
13509
13667
  }
13510
- var KeywordStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Break, (0, import_lib3.$E)((0, import_lib3.$S)(_, (0, import_lib3.$E)(Colon), Identifier))), function($skip, $loc, $0, $1, $2) {
13668
+ var KeywordStatement$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Break, (0, import_lib3.$E)((0, import_lib3.$S)(_, LabelIdentifier)), (0, import_lib3.$E)((0, import_lib3.$S)(_, With, MaybeNestedExtendedExpression))), function($skip, $loc, $0, $1, $2, $3) {
13669
+ const children = [$1];
13670
+ if ($2)
13671
+ children.push($2);
13672
+ if ($3)
13673
+ children.push({
13674
+ type: "Error",
13675
+ subtype: "Warning",
13676
+ message: "'break with' outside of loop that returns a value"
13677
+ });
13511
13678
  return {
13512
13679
  type: "BreakStatement",
13513
- children: $2 ? [$1, $2[0], $2[2]] : [$1]
13514
- // omit colon
13680
+ label: $2?.[1],
13681
+ with: $3?.[2],
13682
+ children
13515
13683
  };
13516
13684
  });
13517
13685
  var KeywordStatement$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Continue, _, Switch), function($skip, $loc, $0, $1, $2, $3) {
@@ -13521,11 +13689,21 @@ var KeywordStatement$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Continue, _, S
13521
13689
  children: []
13522
13690
  };
13523
13691
  });
13524
- var KeywordStatement$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(Continue, (0, import_lib3.$E)((0, import_lib3.$S)(_, (0, import_lib3.$E)(Colon), Identifier))), function($skip, $loc, $0, $1, $2) {
13692
+ var KeywordStatement$2 = (0, import_lib3.$TS)((0, import_lib3.$S)(Continue, (0, import_lib3.$E)((0, import_lib3.$S)(_, LabelIdentifier)), (0, import_lib3.$E)((0, import_lib3.$S)(_, With, MaybeNestedExtendedExpression))), function($skip, $loc, $0, $1, $2, $3) {
13693
+ const children = [$1];
13694
+ if ($2)
13695
+ children.push($2);
13696
+ if ($3)
13697
+ children.push({
13698
+ type: "Error",
13699
+ subtype: "Warning",
13700
+ message: "'continue with' outside of loop that returns a value"
13701
+ });
13525
13702
  return {
13526
13703
  type: "ContinueStatement",
13527
- children: $2 ? [$1, $2[0], $2[2]] : [$1]
13528
- // omit colon
13704
+ label: $2?.[1],
13705
+ with: $3?.[2],
13706
+ children
13529
13707
  };
13530
13708
  });
13531
13709
  var KeywordStatement$3 = DebuggerStatement;
@@ -17674,19 +17852,6 @@ var Reset$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L0, 'Reset ""'), fu
17674
17852
  }
17675
17853
  });
17676
17854
  Object.assign(config, initialConfig);
17677
- return {
17678
- type: "ParserMeta",
17679
- children: [],
17680
- getStateKey() {
17681
- const stateInt = state.currentIndent.level % 256 << 8 | state.classImplicitCallForbidden << 7 | state.indentedApplicationForbidden << 6 | state.bracedApplicationForbidden << 5 | state.trailingMemberPropertyForbidden << 4 | state.newlineBinaryOpForbidden << 3 | // This is slightly different than the rest of the state,
17682
- // since it is affected by the directive prologue and may be hit
17683
- // by the EOL rule early in the parse. Later if we wanted to
17684
- // allow block scoping of the compat directives we would need to
17685
- // add them all here.
17686
- config.coffeeComment << 2;
17687
- return [stateInt, state.currentJSXTag];
17688
- }
17689
- };
17690
17855
  });
17691
17856
  function Reset(ctx, state2) {
17692
17857
  return (0, import_lib3.$EVENT)(ctx, state2, "Reset", Reset$0);
@@ -17888,6 +18053,15 @@ Object.defineProperties(state, {
17888
18053
  }
17889
18054
  }
17890
18055
  });
18056
+ function getStateKey() {
18057
+ const stateInt = state.currentIndent.level % 256 << 8 | state.classImplicitCallForbidden << 7 | state.indentedApplicationForbidden << 6 | state.bracedApplicationForbidden << 5 | state.trailingMemberPropertyForbidden << 4 | state.newlineBinaryOpForbidden << 3 | // This is slightly different than the rest of the state,
18058
+ // since it is affected by the directive prologue and may be hit
18059
+ // by the EOL rule early in the parse. Later if we wanted to
18060
+ // allow block scoping of the compat directives we would need to
18061
+ // add them all here.
18062
+ config.coffeeComment << 2;
18063
+ return [stateInt, state.currentJSXTag];
18064
+ }
17891
18065
  function parseProgram(input, options) {
17892
18066
  filename = options?.filename;
17893
18067
  initialConfig = options?.parseOptions;
@@ -18114,7 +18288,11 @@ var encodeBase64 = function(value) {
18114
18288
  })();
18115
18289
  };
18116
18290
  var base64Encode = function(src) {
18117
- return Buffer.from(src).toString("base64");
18291
+ if (typeof Buffer !== "undefined") {
18292
+ return Buffer.from(src).toString("base64");
18293
+ } else {
18294
+ return btoa(src);
18295
+ }
18118
18296
  };
18119
18297
  var vlqTable = new Uint8Array(128);
18120
18298
  var vlqChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -18418,7 +18596,6 @@ var makeCache = function({ hits, trace } = {}) {
18418
18596
  meta.logs = logs;
18419
18597
  }
18420
18598
  const stateCache = new StateCache();
18421
- let getStateKey = null;
18422
18599
  const stack = [];
18423
18600
  const events = {
18424
18601
  meta,
@@ -18447,14 +18624,12 @@ var makeCache = function({ hits, trace } = {}) {
18447
18624
  return;
18448
18625
  },
18449
18626
  exit: function(ruleName, state2, result) {
18450
- if (ruleName === "Reset") {
18451
- ({ getStateKey } = result.value);
18452
- }
18453
- if (!uncacheable.has(ruleName)) {
18454
- const [stateKey, tagKey] = getStateKey();
18455
- const key = [tagKey, stateKey, state2.pos, ruleName];
18456
- stateCache.set(key, result);
18627
+ if (uncacheable.has(ruleName)) {
18628
+ return;
18457
18629
  }
18630
+ const [stateKey, tagKey] = getStateKey();
18631
+ const key = [tagKey, stateKey, state2.pos, ruleName];
18632
+ stateCache.set(key, result);
18458
18633
  if (getConfig().verbose && result) {
18459
18634
  console.log(`Parsed ${JSON.stringify(state2.input.slice(state2.pos, result.pos))} [pos ${state2.pos}-${result.pos}] as ${ruleName}`);
18460
18635
  }