@danielx/civet 0.9.4 → 0.9.6

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
@@ -536,6 +536,7 @@ __export(lib_civet_exports, {
536
536
  maybeRefAssignment: () => maybeRefAssignment,
537
537
  modifyString: () => modifyString,
538
538
  negateCondition: () => negateCondition,
539
+ precedenceCustomDefault: () => precedenceCustomDefault,
539
540
  precedenceStep: () => precedenceStep,
540
541
  prepend: () => prepend,
541
542
  processAssignmentDeclaration: () => processAssignmentDeclaration,
@@ -1631,6 +1632,15 @@ function gatherRecursiveAll(node, predicate) {
1631
1632
  }
1632
1633
 
1633
1634
  // unplugin-civet:C:\Users\edemaine\Projects\Civet\source\parser\ref.civet.jsx
1635
+ var range = (start, end) => {
1636
+ const length = end - start;
1637
+ if (length <= 0) return [];
1638
+ const arr = Array(length);
1639
+ for (let i = 0; i < length; ++i) {
1640
+ arr[i] = i + start;
1641
+ }
1642
+ return arr;
1643
+ };
1634
1644
  function makeRef(base = "ref", id = base) {
1635
1645
  return {
1636
1646
  type: "Ref",
@@ -1643,7 +1653,7 @@ function needsRef(expression, base = "ref") {
1643
1653
  return;
1644
1654
  }
1645
1655
  if (Array.isArray(expression)) {
1646
- const nonempty = ((s) => Array.from({ length: expression.length - s }, (_2, i) => s + i))(0).filter((i) => !isWhitespaceOrEmpty(expression[i]));
1656
+ const nonempty = range(0, expression.length).filter((i) => !isWhitespaceOrEmpty(expression[i]));
1647
1657
  if (nonempty.length === 1) {
1648
1658
  let ref1;
1649
1659
  if (ref1 = needsRef(expression[nonempty[0]], base)) {
@@ -1659,8 +1669,9 @@ function needsRef(expression, base = "ref") {
1659
1669
  case "Ref":
1660
1670
  case "Identifier":
1661
1671
  case "Literal":
1662
- case "Placeholder":
1672
+ case "Placeholder": {
1663
1673
  return;
1674
+ }
1664
1675
  }
1665
1676
  return makeRef(base);
1666
1677
  }
@@ -1690,10 +1701,34 @@ function maybeRefAssignment(exp, base = "ref") {
1690
1701
  return { ref, ...makeRefAssignment(ref, exp) };
1691
1702
  }
1692
1703
  }
1704
+ function populateRefs(statements) {
1705
+ const refNodes = gatherRecursive(statements, ($) => $.type === "Ref");
1706
+ if (!refNodes.length) {
1707
+ return;
1708
+ }
1709
+ const ids = gatherRecursive(statements, ($1) => $1.type === "Identifier");
1710
+ const names = new Set(ids.flatMap(({ names: names2 }) => names2 || []));
1711
+ for (let i1 = 0, len3 = refNodes.length; i1 < len3; i1++) {
1712
+ const ref = refNodes[i1];
1713
+ if (!(ref.type === "Ref")) {
1714
+ continue;
1715
+ }
1716
+ const { base } = ref;
1717
+ ref.type = "Identifier";
1718
+ let n = 0;
1719
+ let name = base;
1720
+ while (names.has(name)) {
1721
+ n++;
1722
+ name = `${base}${n}`;
1723
+ }
1724
+ names.add(name);
1725
+ ref.children = ref.names = [name];
1726
+ }
1727
+ }
1693
1728
 
1694
1729
  // unplugin-civet:C:\Users\edemaine\Projects\Civet\source\parser\binding.civet.jsx
1695
1730
  function adjustAtBindings(statements, asThis = false) {
1696
- for (let ref1 = gatherRecursiveAll(statements, ($) => $.type === "AtBindingProperty"), i1 = 0, len3 = ref1.length; i1 < len3; i1++) {
1731
+ for (let ref1 = gatherRecursiveAll(statements, ($1) => $1.type === "AtBindingProperty"), i1 = 0, len3 = ref1.length; i1 < len3; i1++) {
1697
1732
  const binding = ref1[i1];
1698
1733
  const { ref } = binding;
1699
1734
  if (asThis) {
@@ -1711,7 +1746,7 @@ function adjustAtBindings(statements, asThis = false) {
1711
1746
  }
1712
1747
  }
1713
1748
  function adjustBindingElements(elements) {
1714
- const names = elements.flatMap(($1) => $1.names || []);
1749
+ const names = elements.flatMap(($2) => $2.names || []);
1715
1750
  const { length } = elements;
1716
1751
  let blockPrefix, restIndex = -1, restCount = 0;
1717
1752
  for (let i2 = 0, len1 = elements.length; i2 < len1; i2++) {
@@ -1769,16 +1804,40 @@ function adjustBindingElements(elements) {
1769
1804
  length
1770
1805
  };
1771
1806
  }
1807
+ function gatherSubbindings(node, subbindings = []) {
1808
+ for (let ref2 = gatherRecursiveAll(node, ($) => $.subbinding != null), i3 = 0, len22 = ref2.length; i3 < len22; i3++) {
1809
+ const p = ref2[i3];
1810
+ const { subbinding } = p;
1811
+ subbindings.push(", ", subbinding);
1812
+ gatherSubbindings(subbinding, subbindings);
1813
+ }
1814
+ return subbindings;
1815
+ }
1816
+ function simplifyBindingProperties(node) {
1817
+ const results = [];
1818
+ for (let ref3 = gatherRecursiveAll(node, ($3) => $3.type === "BindingProperty"), i4 = 0, len3 = ref3.length; i4 < len3; i4++) {
1819
+ const p = ref3[i4];
1820
+ const { name, value } = p;
1821
+ if (value?.type === "NamedBindingPattern" && value.binding === name) {
1822
+ const [ws] = p.children;
1823
+ results.push(p.children = [ws, name, p.delim]);
1824
+ } else {
1825
+ results.push(void 0);
1826
+ }
1827
+ }
1828
+ ;
1829
+ return results;
1830
+ }
1772
1831
  function gatherBindingCode(statements, opts) {
1773
1832
  const thisAssignments = [];
1774
1833
  const splices = [];
1775
1834
  function insertRestSplices(s, p, thisAssignments2) {
1776
1835
  let m;
1777
- for (let ref2 = gatherRecursiveAll(
1836
+ for (let ref4 = gatherRecursiveAll(
1778
1837
  s,
1779
1838
  (n) => n.blockPrefix || opts?.injectParamProps && n.accessModifier || n.type === "AtBinding" || opts?.assignPins && (m = n.type, m === "PinPattern" || m === "PinProperty")
1780
- ), i3 = 0, len22 = ref2.length; i3 < len22; i3++) {
1781
- let n = ref2[i3];
1839
+ ), i5 = 0, len4 = ref4.length; i5 < len4; i5++) {
1840
+ let n = ref4[i5];
1782
1841
  if (n.type === "AtBinding") {
1783
1842
  const { ref } = n;
1784
1843
  const { id } = ref;
@@ -1787,7 +1846,7 @@ function gatherBindingCode(statements, opts) {
1787
1846
  }
1788
1847
  if (opts?.assignPins) {
1789
1848
  if (n.type === "PinProperty") {
1790
- n.children = n.children.flatMap(($2) => $2 === n.name ? [n.name, ": ", n.value] : $2);
1849
+ n.children = n.children.flatMap(($4) => $4 === n.name ? [n.name, ": ", n.value] : $4);
1791
1850
  updateParentPointers(n);
1792
1851
  n = n.value;
1793
1852
  }
@@ -1809,8 +1868,8 @@ function gatherBindingCode(statements, opts) {
1809
1868
  }
1810
1869
  }
1811
1870
  if (opts?.injectParamProps && n.type === "Parameter" && n.accessModifier) {
1812
- for (let ref3 = n.names, i4 = 0, len3 = ref3.length; i4 < len3; i4++) {
1813
- const id = ref3[i4];
1871
+ for (let ref5 = n.names, i6 = 0, len5 = ref5.length; i6 < len5; i6++) {
1872
+ const id = ref5[i6];
1814
1873
  thisAssignments2.push({
1815
1874
  type: "AssignmentExpression",
1816
1875
  children: [`this.${id} = `, id],
@@ -1828,8 +1887,8 @@ function gatherBindingCode(statements, opts) {
1828
1887
  return [splices, thisAssignments];
1829
1888
  }
1830
1889
  function arrayElementHasTrailingComma(elementNode) {
1831
- let ref4;
1832
- const lastChild = (ref4 = elementNode.children)[ref4.length - 1];
1890
+ let ref6;
1891
+ const lastChild = (ref6 = elementNode.children)[ref6.length - 1];
1833
1892
  return lastChild && lastChild[lastChild.length - 1]?.token === ",";
1834
1893
  }
1835
1894
  function gatherBindingPatternTypeSuffix(pattern) {
@@ -1840,9 +1899,9 @@ function gatherBindingPatternTypeSuffix(pattern) {
1840
1899
  switch (pattern.type) {
1841
1900
  case "ArrayBindingPattern": {
1842
1901
  {
1843
- const results = [];
1844
- for (let ref5 = pattern.elements, i5 = 0, len4 = ref5.length; i5 < len4; i5++) {
1845
- const elem = ref5[i5];
1902
+ const results1 = [];
1903
+ for (let ref7 = pattern.elements, i7 = 0, len6 = ref7.length; i7 < len6; i7++) {
1904
+ const elem = ref7[i7];
1846
1905
  let { typeSuffix } = elem;
1847
1906
  typeSuffix ??= elem.binding?.typeSuffix;
1848
1907
  if (typeSuffix) {
@@ -1859,10 +1918,10 @@ function gatherBindingPatternTypeSuffix(pattern) {
1859
1918
  } else {
1860
1919
  typeElement[0] ??= "unknown";
1861
1920
  }
1862
- results.push(typeElement);
1921
+ results1.push(typeElement);
1863
1922
  }
1864
1923
  ;
1865
- const types = results;
1924
+ const types = results1;
1866
1925
  if (count) {
1867
1926
  const t = [": [", types, "]"];
1868
1927
  pattern.typeSuffix = {
@@ -1879,9 +1938,9 @@ function gatherBindingPatternTypeSuffix(pattern) {
1879
1938
  case "ObjectBindingPattern": {
1880
1939
  {
1881
1940
  let restType;
1882
- const results1 = [];
1883
- for (let ref6 = pattern.properties, i6 = 0, len5 = ref6.length; i6 < len5; i6++) {
1884
- const prop = ref6[i6];
1941
+ const results2 = [];
1942
+ for (let ref8 = pattern.properties, i8 = 0, len7 = ref8.length; i8 < len7; i8++) {
1943
+ const prop = ref8[i8];
1885
1944
  let { typeSuffix } = prop;
1886
1945
  typeSuffix ??= prop.value?.typeSuffix;
1887
1946
  if (typeSuffix) {
@@ -1895,12 +1954,12 @@ function gatherBindingPatternTypeSuffix(pattern) {
1895
1954
  switch (prop.type) {
1896
1955
  case "BindingProperty": {
1897
1956
  const ws = prop.children.slice(0, prop.children.indexOf(prop.name));
1898
- results1.push([...ws, prop.name, typeSuffix, prop.delim]);
1957
+ results2.push([...ws, prop.name, typeSuffix, prop.delim]);
1899
1958
  break;
1900
1959
  }
1901
1960
  case "AtBindingProperty": {
1902
1961
  const ws = prop.children.slice(0, prop.children.indexOf(prop.binding));
1903
- results1.push([...ws, prop.ref.id, typeSuffix, prop.delim]);
1962
+ results2.push([...ws, prop.ref.id.replace(/^#/, ""), typeSuffix, prop.delim]);
1904
1963
  break;
1905
1964
  }
1906
1965
  case "BindingRestProperty": {
@@ -1910,7 +1969,7 @@ function gatherBindingPatternTypeSuffix(pattern) {
1910
1969
  }
1911
1970
  }
1912
1971
  ;
1913
- const types = results1;
1972
+ const types = results2;
1914
1973
  if (count) {
1915
1974
  const t = ["{", types, "}"];
1916
1975
  if (restType != null) {
@@ -3023,6 +3082,7 @@ function assignResults(node, collect) {
3023
3082
  exp = exp.statement;
3024
3083
  }
3025
3084
  let ref6;
3085
+ let m1;
3026
3086
  switch (exp.type) {
3027
3087
  case "BreakStatement":
3028
3088
  case "ContinueStatement":
@@ -3102,6 +3162,9 @@ function assignResults(node, collect) {
3102
3162
  return;
3103
3163
  }
3104
3164
  case "PipelineExpression": {
3165
+ if (m1 = exp.children[1]?.type, m1 === "ReturnStatement" || m1 === "ThrowStatement") {
3166
+ return;
3167
+ }
3105
3168
  const semi2 = exp.children.lastIndexOf(";");
3106
3169
  if (0 <= semi2 && semi2 < exp.children.length - 1) {
3107
3170
  exp.children.splice(semi2 + 1, 1 / 0, ...[collect(exp.children.slice(semi2 + 1))]);
@@ -3127,8 +3190,8 @@ function insertReturn(node) {
3127
3190
  const last = node.expressions[node.expressions.length - 1];
3128
3191
  insertReturn(last);
3129
3192
  } else {
3130
- let m1;
3131
- if (m1 = node.parent?.type, m1 === "CatchClause" || m1 === "WhenClause") {
3193
+ let m2;
3194
+ if (m2 = node.parent?.type, m2 === "CatchClause" || m2 === "WhenClause") {
3132
3195
  node.expressions.push(["", wrapWithReturn(void 0, node)]);
3133
3196
  }
3134
3197
  }
@@ -3174,6 +3237,7 @@ function insertReturn(node) {
3174
3237
  exp = exp.statement;
3175
3238
  }
3176
3239
  let ref11;
3240
+ let m3;
3177
3241
  switch (exp.type) {
3178
3242
  case "BreakStatement":
3179
3243
  case "ContinueStatement":
@@ -3265,6 +3329,9 @@ function insertReturn(node) {
3265
3329
  return;
3266
3330
  }
3267
3331
  case "PipelineExpression": {
3332
+ if (m3 = exp.children[1]?.type, m3 === "ReturnStatement" || m3 === "ThrowStatement") {
3333
+ return;
3334
+ }
3268
3335
  const semi2 = exp.children.lastIndexOf(";");
3269
3336
  if (0 <= semi2 && semi2 < exp.children.length - 1) {
3270
3337
  exp.children.splice(semi2 + 1, 1 / 0, ...[wrapWithReturn(exp.children.slice(semi2 + 1))]);
@@ -3287,8 +3354,8 @@ function processBreakContinueWith(statement) {
3287
3354
  )) {
3288
3355
  if (control.with) {
3289
3356
  if (control.label) {
3290
- let m2;
3291
- if (!(m2 = statement.parent, typeof m2 === "object" && m2 != null && "type" in m2 && m2.type === "LabelledStatement" && "label" in m2 && typeof m2.label === "object" && m2.label != null && "name" in m2.label && m2.label.name === control.label.name)) {
3357
+ let m4;
3358
+ if (!(m4 = statement.parent, typeof m4 === "object" && m4 != null && "type" in m4 && m4.type === "LabelledStatement" && "label" in m4 && typeof m4.label === "object" && m4.label != null && "name" in m4.label && m4.label.name === control.label.name)) {
3292
3359
  continue;
3293
3360
  }
3294
3361
  } else {
@@ -3509,8 +3576,8 @@ function iterationDefaultBody(statement) {
3509
3576
  const reduction = statement.type === "ForStatement" && statement.reduction;
3510
3577
  function fillBlock(expression) {
3511
3578
  let ref15;
3512
- let m3;
3513
- if (m3 = (ref15 = block.expressions)[ref15.length - 1], Array.isArray(m3) && m3.length >= 2 && typeof m3[1] === "object" && m3[1] != null && "type" in m3[1] && m3[1].type === "EmptyStatement" && "implicit" in m3[1] && m3[1].implicit === true) {
3579
+ let m5;
3580
+ if (m5 = (ref15 = block.expressions)[ref15.length - 1], Array.isArray(m5) && m5.length >= 2 && typeof m5[1] === "object" && m5[1] != null && "type" in m5[1] && m5[1].type === "EmptyStatement" && "implicit" in m5[1] && m5[1].implicit === true) {
3514
3581
  block.expressions.pop();
3515
3582
  }
3516
3583
  block.expressions.push(expression);
@@ -3638,7 +3705,8 @@ function processParams(f) {
3638
3705
  parameters.names.push(...rest.names || []);
3639
3706
  rest.children.pop();
3640
3707
  if (after.length) {
3641
- if (rest.binding.type === "ArrayBindingPattern" || rest.binding.type === "ObjectBindingPattern") {
3708
+ let m6;
3709
+ if (m6 = rest.binding.type, m6 === "ArrayBindingPattern" || m6 === "ObjectBindingPattern" || m6 === "NamedBindingPattern") {
3642
3710
  parameters.parameters.push({
3643
3711
  type: "Error",
3644
3712
  message: "Non-end rest parameter cannot be binding pattern"
@@ -3770,6 +3838,9 @@ function processParams(f) {
3770
3838
  injectParamProps: isConstructor,
3771
3839
  assignPins: true
3772
3840
  });
3841
+ const subbindings = gatherSubbindings(parameters.parameters);
3842
+ simplifyBindingProperties(parameters.parameters);
3843
+ simplifyBindingProperties(subbindings);
3773
3844
  if (isConstructor) {
3774
3845
  const { ancestor } = findAncestor(f, ($10) => $10.type === "ClassExpression");
3775
3846
  if (ancestor != null) {
@@ -3777,8 +3848,8 @@ function processParams(f) {
3777
3848
  const classExpressions = ancestor.body.expressions;
3778
3849
  let index2 = findChildIndex(classExpressions, f);
3779
3850
  assert.notEqual(index2, -1, "Could not find constructor in class");
3780
- let m4;
3781
- while (m4 = classExpressions[index2 - 1]?.[1], typeof m4 === "object" && m4 != null && "type" in m4 && m4.type === "MethodDefinition" && "name" in m4 && m4.name === "constructor") {
3851
+ let m7;
3852
+ while (m7 = classExpressions[index2 - 1]?.[1], typeof m7 === "object" && m7 != null && "type" in m7 && m7.type === "MethodDefinition" && "name" in m7 && m7.name === "constructor") {
3782
3853
  index2--;
3783
3854
  }
3784
3855
  const fStatement = classExpressions[index2];
@@ -3818,6 +3889,15 @@ function processParams(f) {
3818
3889
  children: [";"]
3819
3890
  };
3820
3891
  let prefix = [];
3892
+ if (subbindings.length) {
3893
+ prefix.push(makeNode({
3894
+ type: "Declaration",
3895
+ children: ["const ", subbindings.slice(1)],
3896
+ names: subbindings.flatMap(($16) => $16.names ?? []),
3897
+ bindings: [],
3898
+ decl: "const"
3899
+ }));
3900
+ }
3821
3901
  for (let ref20 = splices, i11 = 0, len10 = ref20.length; i11 < len10; i11++) {
3822
3902
  const binding = ref20[i11];
3823
3903
  assert.equal(binding.type, "PostRestBindingElements", "splice should be of type Binding");
@@ -3871,7 +3951,7 @@ function processSignature(f) {
3871
3951
  f.async.push("async ");
3872
3952
  signature.modifier.async = true;
3873
3953
  } else {
3874
- for (let ref21 = gatherRecursiveWithinFunction(block, ($16) => $16.type === "Await"), i12 = 0, len11 = ref21.length; i12 < len11; i12++) {
3954
+ for (let ref21 = gatherRecursiveWithinFunction(block, ($17) => $17.type === "Await"), i12 = 0, len11 = ref21.length; i12 < len11; i12++) {
3875
3955
  const a = ref21[i12];
3876
3956
  const i = findChildIndex(a.parent, a);
3877
3957
  a.parent.children.splice(i + 1, 0, {
@@ -3886,9 +3966,9 @@ function processSignature(f) {
3886
3966
  f.generator.push("*");
3887
3967
  signature.modifier.generator = true;
3888
3968
  } else {
3889
- for (let ref22 = gatherRecursiveWithinFunction(block, ($17) => $17.type === "YieldExpression"), i13 = 0, len12 = ref22.length; i13 < len12; i13++) {
3969
+ for (let ref22 = gatherRecursiveWithinFunction(block, ($18) => $18.type === "YieldExpression"), i13 = 0, len12 = ref22.length; i13 < len12; i13++) {
3890
3970
  const y = ref22[i13];
3891
- const i = y.children.findIndex(($18) => $18.type === "Yield");
3971
+ const i = y.children.findIndex(($19) => $19.type === "Yield");
3892
3972
  y.children.splice(i + 1, 0, {
3893
3973
  type: "Error",
3894
3974
  message: `yield invalid in ${f.type === "ArrowFunction" ? "=> arrow function" : signature.modifier.get ? "getter" : signature.modifier.set ? "setter" : signature.name}`
@@ -3901,7 +3981,7 @@ function processSignature(f) {
3901
3981
  }
3902
3982
  }
3903
3983
  function processFunctions(statements, config2) {
3904
- for (let ref23 = gatherRecursiveAll(statements, ($19) => $19.type === "FunctionExpression" || $19.type === "ArrowFunction" || $19.type === "MethodDefinition"), i14 = 0, len13 = ref23.length; i14 < len13; i14++) {
3984
+ for (let ref23 = gatherRecursiveAll(statements, ($20) => $20.type === "FunctionExpression" || $20.type === "ArrowFunction" || $20.type === "MethodDefinition"), i14 = 0, len13 = ref23.length; i14 < len13; i14++) {
3905
3985
  const f = ref23[i14];
3906
3986
  if (f.type === "FunctionExpression" || f.type === "MethodDefinition") {
3907
3987
  implicitFunctionBlock(f);
@@ -3971,7 +4051,7 @@ function expressionizeIteration(exp) {
3971
4051
  }
3972
4052
  }
3973
4053
  function processIterationExpressions(statements) {
3974
- for (let ref25 = gatherRecursiveAll(statements, ($20) => $20.type === "IterationExpression"), i15 = 0, len14 = ref25.length; i15 < len14; i15++) {
4054
+ for (let ref25 = gatherRecursiveAll(statements, ($21) => $21.type === "IterationExpression"), i15 = 0, len14 = ref25.length; i15 < len14; i15++) {
3975
4055
  const s = ref25[i15];
3976
4056
  expressionizeIteration(s);
3977
4057
  }
@@ -4021,12 +4101,12 @@ function processCoffeeDo(ws, expression) {
4021
4101
  const newParameters = {
4022
4102
  ...parameters,
4023
4103
  parameters: newParameterList,
4024
- children: parameters.children.map(($21) => $21 === parameterList ? newParameterList : $21)
4104
+ children: parameters.children.map(($22) => $22 === parameterList ? newParameterList : $22)
4025
4105
  };
4026
4106
  expression = {
4027
4107
  ...expression,
4028
4108
  parameters: newParameters,
4029
- children: expression.children.map(($22) => $22 === parameters ? newParameters : $22)
4109
+ children: expression.children.map(($23) => $23 === parameters ? newParameters : $23)
4030
4110
  };
4031
4111
  }
4032
4112
  return {
@@ -4048,7 +4128,7 @@ function makeAmpersandFunction(rhs) {
4048
4128
  ref = makeRef("$");
4049
4129
  inplacePrepend(ref, body);
4050
4130
  }
4051
- if (startsWithPredicate(body, ($23) => $23.type === "ObjectExpression")) {
4131
+ if (startsWithPredicate(body, ($24) => $24.type === "ObjectExpression")) {
4052
4132
  body = makeLeftHandSideExpression(body);
4053
4133
  }
4054
4134
  const parameterList = [
@@ -4844,17 +4924,15 @@ function getPatternConditions(pattern, ref, conditions = []) {
4844
4924
  break;
4845
4925
  }
4846
4926
  case "ConditionFragment": {
4847
- let { children } = pattern;
4848
- if (children.length) {
4849
- let [first, ...rest] = children;
4927
+ let { rhs } = pattern;
4928
+ if (rhs.length) {
4929
+ let [first, ...rest] = rhs;
4850
4930
  let [ws, ...op] = first;
4851
4931
  ws = [" "].concat(ws);
4852
4932
  first = [ws, ...op];
4853
- children = [first, ...rest];
4933
+ rhs = [first, ...rest];
4854
4934
  }
4855
- conditions.push(
4856
- processBinaryOpExpression([ref, children])
4857
- );
4935
+ conditions.push(processBinaryOpExpression([ref, rhs]));
4858
4936
  break;
4859
4937
  }
4860
4938
  case "RegularExpressionLiteral": {
@@ -4872,6 +4950,10 @@ function getPatternConditions(pattern, ref, conditions = []) {
4872
4950
  ]);
4873
4951
  break;
4874
4952
  }
4953
+ case "NamedBindingPattern": {
4954
+ getPatternConditions(pattern.pattern, ref, conditions);
4955
+ break;
4956
+ }
4875
4957
  case "Literal": {
4876
4958
  conditions.push([
4877
4959
  ref,
@@ -4901,43 +4983,60 @@ function getPatternBlockPrefix(pattern, ref, decl = "const ", typeSuffix) {
4901
4983
  }
4902
4984
  case "Literal":
4903
4985
  case "RegularExpressionLiteral":
4904
- case "PinPattern":
4905
- case "ConditionFragment": {
4986
+ case "PinPattern": {
4906
4987
  return;
4907
4988
  }
4989
+ case "ConditionFragment": {
4990
+ if (!pattern.binding) {
4991
+ return;
4992
+ }
4993
+ ;
4994
+ break;
4995
+ }
4908
4996
  }
4909
4997
  let [splices, thisAssignments] = gatherBindingCode(pattern);
4910
4998
  const patternBindings2 = nonMatcherBindings(pattern);
4911
- const results = [];
4912
- for (let ref2 = gatherRecursiveAll(patternBindings2, ($7) => $7.subbinding != null), i5 = 0, len4 = ref2.length; i5 < len4; i5++) {
4913
- const p = ref2[i5];
4914
- results.push(prepend(", ", p.subbinding));
4915
- }
4916
- ;
4917
- const subbindings = results;
4918
- splices = splices.map((s) => [", ", nonMatcherBindings(s)]);
4919
- thisAssignments = thisAssignments.map(($8) => ["", $8, ";"]);
4920
- const duplicateDeclarations = aggregateDuplicateBindings([patternBindings2, splices]);
4921
- return [
4922
- ["", {
4999
+ const subbindings = gatherSubbindings(patternBindings2);
5000
+ simplifyBindingProperties(patternBindings2);
5001
+ simplifyBindingProperties(subbindings);
5002
+ splices = splices.flatMap((s) => [", ", nonMatcherBindings(s)]);
5003
+ thisAssignments = thisAssignments.map(($7) => ["", $7, ";"]);
5004
+ const duplicateDeclarations = aggregateDuplicateBindings([patternBindings2, splices, subbindings]);
5005
+ const blockPrefix = [];
5006
+ if (ref || subbindings.length || splices.length) {
5007
+ const children = [decl];
5008
+ if (ref) {
5009
+ children.push(patternBindings2, typeSuffix, " = ", ref);
5010
+ }
5011
+ children.push(...subbindings);
5012
+ children.push(...splices);
5013
+ if (!ref) {
5014
+ children.splice(1, 1);
5015
+ }
5016
+ blockPrefix.push(["", {
4923
5017
  type: "Declaration",
4924
- children: [decl, patternBindings2, typeSuffix, " = ", ref, ...subbindings, ...splices],
5018
+ children,
5019
+ decl,
4925
5020
  names: [],
4926
5021
  bindings: []
4927
5022
  // avoid implicit return of any bindings
4928
- }, ";"],
4929
- ...thisAssignments,
4930
- ...duplicateDeclarations.map(($9) => ["", $9, ";"])
4931
- ];
5023
+ }, ";"]);
5024
+ }
5025
+ blockPrefix.push(...thisAssignments);
5026
+ blockPrefix.push(...duplicateDeclarations.map(($8) => ["", $8, ";"]));
5027
+ if (!blockPrefix.length) {
5028
+ return;
5029
+ }
5030
+ return blockPrefix;
4932
5031
  }
4933
5032
  function elideMatchersFromArrayBindings(elements) {
4934
- const results1 = [];
4935
- for (let i6 = 0, len5 = elements.length; i6 < len5; i6++) {
4936
- const element = elements[i6];
5033
+ const results = [];
5034
+ for (let i5 = 0, len4 = elements.length; i5 < len4; i5++) {
5035
+ const element = elements[i5];
4937
5036
  switch (element.type) {
4938
5037
  case "BindingRestElement":
4939
5038
  case "ElisionElement": {
4940
- results1.push(element);
5039
+ results.push(element);
4941
5040
  break;
4942
5041
  }
4943
5042
  case "BindingElement": {
@@ -4946,12 +5045,12 @@ function elideMatchersFromArrayBindings(elements) {
4946
5045
  case "RegularExpressionLiteral":
4947
5046
  case "StringLiteral":
4948
5047
  case "PinPattern": {
4949
- results1.push(element.delim);
5048
+ results.push(element.delim);
4950
5049
  break;
4951
5050
  }
4952
5051
  default: {
4953
5052
  const binding = nonMatcherBindings(element.binding);
4954
- results1.push(makeNode({
5053
+ results.push(makeNode({
4955
5054
  ...element,
4956
5055
  binding,
4957
5056
  children: element.children.map((c) => {
@@ -4966,29 +5065,23 @@ function elideMatchersFromArrayBindings(elements) {
4966
5065
  }
4967
5066
  }
4968
5067
  ;
4969
- return results1;
5068
+ return results;
4970
5069
  }
4971
5070
  function elideMatchersFromPropertyBindings(properties) {
4972
- const results2 = [];
4973
- for (let i7 = 0, len6 = properties.length; i7 < len6; i7++) {
4974
- const p = properties[i7];
5071
+ const results1 = [];
5072
+ for (let i6 = 0, len5 = properties.length; i6 < len5; i6++) {
5073
+ const p = properties[i6];
4975
5074
  switch (p.type) {
4976
5075
  case "BindingProperty":
4977
5076
  case "PinProperty": {
4978
- const { children, name, value, bind } = p;
5077
+ const { children, name, value } = p;
4979
5078
  const [ws] = children;
4980
5079
  const shouldElide = name.type === "NumericLiteral" && !value?.name || name.type === "ComputedPropertyName" && value?.subtype === "NumericLiteral";
4981
5080
  if (shouldElide) {
4982
- if (bind) {
4983
- results2.push({
4984
- type: "Error",
4985
- message: `Cannot bind ${name.type}`
4986
- });
4987
- } else {
4988
- continue;
4989
- }
5081
+ continue;
4990
5082
  } else {
4991
5083
  let contents;
5084
+ let m1;
4992
5085
  switch (value?.type) {
4993
5086
  case "ArrayBindingPattern":
4994
5087
  case "ObjectBindingPattern": {
@@ -5005,22 +5098,28 @@ function elideMatchersFromPropertyBindings(properties) {
5005
5098
  contents = p;
5006
5099
  break;
5007
5100
  }
5101
+ case "NamedBindingPattern": {
5102
+ const bindings = nonMatcherBindings(value.pattern);
5103
+ contents = {
5104
+ ...p,
5105
+ subbinding: (m1 = bindings?.type, m1 === "ArrayBindingPattern" || m1 === "ObjectBindingPattern" || m1 === "Identifier") ? [
5106
+ bindings,
5107
+ " = ",
5108
+ name
5109
+ ] : void 0
5110
+ };
5111
+ if (p.name === value.binding) {
5112
+ contents.children = [ws, name, p.delim];
5113
+ }
5114
+ ;
5115
+ break;
5116
+ }
5008
5117
  default: {
5009
5118
  contents = void 0;
5010
5119
  }
5011
5120
  }
5012
- if (bind) {
5013
- results2.push({
5014
- ...p,
5015
- children: [ws, name, p.delim],
5016
- subbinding: contents?.value ? [
5017
- contents.value,
5018
- " = ",
5019
- name
5020
- ] : void 0
5021
- });
5022
- } else if (contents) {
5023
- results2.push(contents);
5121
+ if (contents) {
5122
+ results1.push(contents);
5024
5123
  } else {
5025
5124
  continue;
5026
5125
  }
@@ -5029,14 +5128,15 @@ function elideMatchersFromPropertyBindings(properties) {
5029
5128
  break;
5030
5129
  }
5031
5130
  default: {
5032
- results2.push(p);
5131
+ results1.push(p);
5033
5132
  }
5034
5133
  }
5035
5134
  }
5036
5135
  ;
5037
- return results2;
5136
+ return results1;
5038
5137
  }
5039
5138
  function nonMatcherBindings(pattern) {
5139
+ let m2;
5040
5140
  switch (pattern.type) {
5041
5141
  case "ArrayBindingPattern":
5042
5142
  case "PostRestBindingElements": {
@@ -5044,7 +5144,7 @@ function nonMatcherBindings(pattern) {
5044
5144
  return makeNode({
5045
5145
  ...pattern,
5046
5146
  elements,
5047
- children: pattern.children.map(($10) => $10 === pattern.elements ? elements : $10)
5147
+ children: pattern.children.map(($9) => $9 === pattern.elements ? elements : $9)
5048
5148
  });
5049
5149
  }
5050
5150
  case "ObjectBindingPattern": {
@@ -5052,9 +5152,19 @@ function nonMatcherBindings(pattern) {
5052
5152
  return makeNode({
5053
5153
  ...pattern,
5054
5154
  properties,
5055
- children: pattern.children.map(($11) => $11 === pattern.properties ? properties : $11)
5155
+ children: pattern.children.map(($10) => $10 === pattern.properties ? properties : $10)
5056
5156
  });
5057
5157
  }
5158
+ case "NamedBindingPattern": {
5159
+ const bindings = nonMatcherBindings(pattern.pattern);
5160
+ return makeNode({
5161
+ ...pattern,
5162
+ subbinding: (m2 = bindings?.type, m2 === "ArrayBindingPattern" || m2 === "ObjectBindingPattern" || m2 === "Identifier") ? [bindings, " = ", pattern.binding] : void 0
5163
+ });
5164
+ }
5165
+ case "ConditionFragment": {
5166
+ return pattern.binding;
5167
+ }
5058
5168
  default: {
5059
5169
  return pattern;
5060
5170
  }
@@ -5070,11 +5180,11 @@ function aggregateDuplicateBindings(bindings) {
5070
5180
  );
5071
5181
  const declarations = [];
5072
5182
  const propsGroupedByName = /* @__PURE__ */ new Map();
5073
- for (let i8 = 0, len7 = props.length; i8 < len7; i8++) {
5074
- const p = props[i8];
5183
+ for (let i7 = 0, len6 = props.length; i7 < len6; i7++) {
5184
+ const p = props[i7];
5075
5185
  const { name, value } = p;
5076
- let m1;
5077
- if (m1 = value?.type, m1 === "ArrayBindingPattern" || m1 === "ObjectBindingPattern") {
5186
+ let m3;
5187
+ if (m3 = value?.type, m3 === "ArrayBindingPattern" || m3 === "ObjectBindingPattern") {
5078
5188
  continue;
5079
5189
  }
5080
5190
  const key = value?.name || name?.name || name;
@@ -5096,8 +5206,8 @@ function aggregateDuplicateBindings(bindings) {
5096
5206
  pos: 0,
5097
5207
  input: key
5098
5208
  })) {
5099
- for (let i9 = 0, len8 = shared.length; i9 < len8; i9++) {
5100
- const p = shared[i9];
5209
+ for (let i8 = 0, len7 = shared.length; i8 < len7; i8++) {
5210
+ const p = shared[i8];
5101
5211
  aliasBinding(p, makeRef(`_${key}`, key));
5102
5212
  }
5103
5213
  return;
@@ -5189,8 +5299,18 @@ function processDeclarations(statements) {
5189
5299
  if (!(bindings != null)) {
5190
5300
  continue;
5191
5301
  }
5192
- for (let i2 = 0, len22 = bindings.length; i2 < len22; i2++) {
5193
- const binding = bindings[i2];
5302
+ for (let i2 = bindings.length + -1; i2 >= 0; --i2) {
5303
+ const i = i2;
5304
+ const binding = bindings[i];
5305
+ const subbindings = gatherSubbindings(binding);
5306
+ if (subbindings.length) {
5307
+ simplifyBindingProperties(binding);
5308
+ simplifyBindingProperties(subbindings);
5309
+ spliceChild(declaration, binding, 1, binding, subbindings);
5310
+ }
5311
+ }
5312
+ for (let i3 = 0, len22 = bindings.length; i3 < len22; i3++) {
5313
+ const binding = bindings[i3];
5194
5314
  let { typeSuffix, initializer } = binding;
5195
5315
  if (typeSuffix && typeSuffix.optional) {
5196
5316
  if (initializer && !typeSuffix.t) {
@@ -5228,6 +5348,25 @@ function processDeclarations(statements) {
5228
5348
  }
5229
5349
  }
5230
5350
  }
5351
+ for (let ref2 = gatherRecursiveAll(statements, ($1) => $1.type === "ForStatement"), i4 = 0, len3 = ref2.length; i4 < len3; i4++) {
5352
+ const statement = ref2[i4];
5353
+ const { declaration } = statement;
5354
+ if (!(declaration?.type === "ForDeclaration")) {
5355
+ continue;
5356
+ }
5357
+ const { binding } = declaration;
5358
+ const blockPrefix = getPatternBlockPrefix(
5359
+ binding.pattern,
5360
+ void 0,
5361
+ append(declaration.decl, " "),
5362
+ binding.typeSuffix
5363
+ );
5364
+ simplifyBindingProperties(binding);
5365
+ if (blockPrefix != null) {
5366
+ statement.block.expressions.unshift(...blockPrefix);
5367
+ braceBlock(statement.block);
5368
+ }
5369
+ }
5231
5370
  }
5232
5371
  function prependStatementExpressionBlock(initializer, statement) {
5233
5372
  let { expression: exp } = initializer;
@@ -5371,8 +5510,7 @@ function processDeclarationConditionStatement(s) {
5371
5510
  }
5372
5511
  let { expression } = condition;
5373
5512
  if (expression && typeof expression === "object" && "type" in expression && expression.type === "UnaryExpression" && "children" in expression && Array.isArray(expression.children) && len2(expression.children, 2) && Array.isArray(expression.children[0]) && len2(expression.children[0], 1) && expression.children[0][0] === "!" && typeof expression.children[1] === "object" && expression.children[1] != null && "type" in expression.children[1] && expression.children[1].type === "ParenthesizedExpression" && "expression" in expression.children[1]) {
5374
- const { type: type1, children: [[], { type: type2, expression: expression2 }] } = expression;
5375
- const type = [type1, type2];
5513
+ const { children: [[], { expression: expression2 }] } = expression;
5376
5514
  expression = expression2;
5377
5515
  }
5378
5516
  processDeclarationCondition(expression, condition.expression, s);
@@ -5397,8 +5535,8 @@ function processDeclarationConditionStatement(s) {
5397
5535
  ({ children } = condition.expression.children[1]);
5398
5536
  }
5399
5537
  children.unshift("(");
5400
- for (let i3 = 0, len3 = conditions.length; i3 < len3; i3++) {
5401
- const c = conditions[i3];
5538
+ for (let i5 = 0, len4 = conditions.length; i5 < len4; i5++) {
5539
+ const c = conditions[i5];
5402
5540
  children.push(" && ", c);
5403
5541
  }
5404
5542
  children.push(")");
@@ -5420,11 +5558,11 @@ function processDeclarationConditionStatement(s) {
5420
5558
  ancestor.expressions.splice(index + 1, 0, ...blockPrefix);
5421
5559
  updateParentPointers(ancestor);
5422
5560
  braceBlock(ancestor);
5423
- let ref2;
5561
+ let ref3;
5424
5562
  switch (s.type) {
5425
5563
  case "IfStatement": {
5426
- if (ref2 = s.else?.block) {
5427
- const elseBlock = ref2;
5564
+ if (ref3 = s.else?.block) {
5565
+ const elseBlock = ref3;
5428
5566
  if (elseBlock.bare && !elseBlock.semicolon) {
5429
5567
  elseBlock.children.push(elseBlock.semicolon = ";");
5430
5568
  }
@@ -5448,13 +5586,13 @@ function processDeclarationConditionStatement(s) {
5448
5586
  if (s.negated) {
5449
5587
  if (e != null) {
5450
5588
  const block = blockWithPrefix(blockPrefix, e.block);
5451
- e.children = e.children.map(($1) => $1 === e.block ? block : $1);
5589
+ e.children = e.children.map(($2) => $2 === e.block ? block : $2);
5452
5590
  e.block = block;
5453
5591
  updateParentPointers(e);
5454
5592
  }
5455
5593
  } else {
5456
5594
  const block = blockWithPrefix(blockPrefix, s.then);
5457
- s.children = s.children.map(($2) => $2 === s.then ? block : $2);
5595
+ s.children = s.children.map(($3) => $3 === s.then ? block : $3);
5458
5596
  s.then = block;
5459
5597
  updateParentPointers(s);
5460
5598
  }
@@ -5467,7 +5605,7 @@ function processDeclarationConditionStatement(s) {
5467
5605
  }
5468
5606
  const { children, block } = s;
5469
5607
  const newBlock = blockWithPrefix(blockPrefix, block);
5470
- s.children = children.map(($3) => $3 === block ? newBlock : $3);
5608
+ s.children = children.map(($4) => $4 === block ? newBlock : $4);
5471
5609
  updateParentPointers(s);
5472
5610
  break;
5473
5611
  }
@@ -5495,7 +5633,7 @@ function processDeclarationConditionStatement(s) {
5495
5633
  const block = makeEmptyBlock();
5496
5634
  replaceBlockExpression(s.parent, s, block);
5497
5635
  block.expressions.push(["", s]);
5498
- s.children.splice(s.children.findIndex(($4) => $4.token === "switch"), 0, blockPrefix);
5636
+ s.children.splice(s.children.findIndex(($5) => $5.token === "switch"), 0, blockPrefix);
5499
5637
  s.parent = block;
5500
5638
  } else {
5501
5639
  const block = blockWithPrefix([["", [{
@@ -5515,12 +5653,12 @@ function processDeclarationConditionStatement(s) {
5515
5653
  function dynamizeFromClause(from) {
5516
5654
  from = from.slice(1);
5517
5655
  from = trimFirstSpace(from);
5518
- let ref3;
5519
- if (ref3 = from[from.length - 1]?.assertion) {
5520
- const assert2 = ref3;
5521
- let ref4;
5522
- ref4 = from[from.length - 1];
5523
- ref4.children = ref4.children.filter((a2) => a2 !== assert2);
5656
+ let ref4;
5657
+ if (ref4 = from[from.length - 1]?.assertion) {
5658
+ const assert2 = ref4;
5659
+ let ref5;
5660
+ ref5 = from[from.length - 1];
5661
+ ref5.children = ref5.children.filter((a2) => a2 !== assert2);
5524
5662
  from.push(", {", assert2.keyword, ":", assert2.object, "}");
5525
5663
  }
5526
5664
  return ["(", ...from, ")"];
@@ -5529,20 +5667,20 @@ function dynamizeImportDeclaration(decl) {
5529
5667
  const { imports } = decl;
5530
5668
  let { star, binding, specifiers } = imports;
5531
5669
  const justDefault = binding && !specifiers && !star;
5532
- let ref5;
5670
+ let ref6;
5533
5671
  {
5534
5672
  if (binding) {
5535
5673
  if (specifiers) {
5536
- ref5 = makeRef();
5674
+ ref6 = makeRef();
5537
5675
  } else {
5538
- ref5 = binding;
5676
+ ref6 = binding;
5539
5677
  }
5540
5678
  } else {
5541
- ref5 = convertNamedImportsToObject(imports, true);
5679
+ ref6 = convertNamedImportsToObject(imports, true);
5542
5680
  }
5543
5681
  }
5544
5682
  ;
5545
- const pattern = ref5;
5683
+ const pattern = ref6;
5546
5684
  const c = "const";
5547
5685
  const expression = [
5548
5686
  justDefault ? "(" : void 0,
@@ -5807,7 +5945,7 @@ function processUnaryNestedExpression(pre, args, post) {
5807
5945
  children: args.children.map(
5808
5946
  (arg) => {
5809
5947
  if (typeof arg === "object" && arg != null && "type" in arg && arg.type === "ArrayElement" && "expression" in arg && "children" in arg) {
5810
- const { type, expression: exp, children } = arg;
5948
+ const { expression: exp, children } = arg;
5811
5949
  let expression = processUnaryExpression([last], trimFirstSpace(exp));
5812
5950
  expression = prepend(getTrimmingSpace(exp), expression);
5813
5951
  return {
@@ -5868,9 +6006,8 @@ function constructInvocation(fn, arg) {
5868
6006
  if (lhs.type === "NewExpression") {
5869
6007
  let { expression } = lhs;
5870
6008
  expression = {
5871
- ...expression,
5872
6009
  type: "CallExpression",
5873
- children: [...expression.children, call]
6010
+ children: [expression, call]
5874
6011
  };
5875
6012
  return {
5876
6013
  ...lhs,
@@ -5923,23 +6060,22 @@ function constructPipeStep(fn, arg, returning) {
5923
6060
  ];
5924
6061
  }
5925
6062
  function processPipelineExpressions(statements) {
5926
- gatherRecursiveAll(statements, (n) => n.type === "PipelineExpression").forEach((s) => {
6063
+ for (let ref1 = gatherRecursiveAll(statements, ($1) => $1.type === "PipelineExpression"), i1 = 0, len3 = ref1.length; i1 < len3; i1++) {
6064
+ const s = ref1[i1];
5927
6065
  const [ws, , body] = s.children;
5928
6066
  let [, arg] = s.children;
5929
- let i = 0;
5930
- const l = body.length;
5931
6067
  const children = [ws];
5932
6068
  const comma = blockContainingStatement(s) ? ";" : ",";
5933
6069
  let usingRef = null;
5934
- for (let i1 = 0, len3 = body.length; i1 < len3; i1++) {
5935
- const i2 = i1;
5936
- const step = body[i1];
6070
+ for (let i2 = 0, len1 = body.length; i2 < len1; i2++) {
6071
+ const i = i2;
6072
+ const step = body[i2];
5937
6073
  const [leadingComment, pipe, trailingComment, expr] = step;
5938
6074
  const returns = pipe.token === "||>";
5939
6075
  let ref, result, returning = returns ? arg : null;
5940
6076
  if (pipe.token === "|>=") {
5941
6077
  let initRef;
5942
- if (i2 === 0) {
6078
+ if (i === 0) {
5943
6079
  checkValidLHS(arg);
5944
6080
  outer: switch (arg.type) {
5945
6081
  case "MemberExpression": {
@@ -5988,7 +6124,7 @@ function processPipelineExpressions(statements) {
5988
6124
  });
5989
6125
  }
5990
6126
  } else {
5991
- if (i2 === 0) s.children = children;
6127
+ if (i === 0) s.children = children;
5992
6128
  }
5993
6129
  if (returns && (ref = needsRef(arg))) {
5994
6130
  usingRef = usingRef || ref;
@@ -6012,7 +6148,7 @@ function processPipelineExpressions(statements) {
6012
6148
  returning
6013
6149
  );
6014
6150
  if (result.type === "ReturnStatement") {
6015
- if (i2 < l - 1) {
6151
+ if (i < body.length - 1) {
6016
6152
  result.children.push({
6017
6153
  type: "Error",
6018
6154
  message: "Can't continue a pipeline after returning"
@@ -6040,7 +6176,7 @@ function processPipelineExpressions(statements) {
6040
6176
  };
6041
6177
  }
6042
6178
  children.push(arg);
6043
- if (!children.some(($1) => $1?.type === "ReturnStatement") && children.some(($2) => $2 === ",")) {
6179
+ if (!children.some(($2) => $2?.type === "ReturnStatement") && children.some(($3) => $3 === ",")) {
6044
6180
  const { parent } = s;
6045
6181
  const parenthesizedExpression = makeLeftHandSideExpression({ ...s });
6046
6182
  Object.assign(s, parenthesizedExpression, {
@@ -6048,17 +6184,17 @@ function processPipelineExpressions(statements) {
6048
6184
  hoistDec: void 0
6049
6185
  });
6050
6186
  }
6051
- return addParentPointers(s, s.parent);
6052
- });
6187
+ addParentPointers(s, s.parent);
6188
+ }
6053
6189
  }
6054
6190
 
6055
6191
  // unplugin-civet:C:\Users\edemaine\Projects\Civet\source\parser\for.civet.jsx
6056
- function processRangeExpression(start, ws1, range, end) {
6057
- ws1 = [ws1, range.children[0]];
6058
- const ws2 = range.children[1];
6059
- const comma = { $loc: range.$loc, token: "," };
6192
+ function processRangeExpression(start, ws1, range2, end) {
6193
+ ws1 = [ws1, range2.children[0]];
6194
+ const ws2 = range2.children[1];
6195
+ const comma = { $loc: range2.$loc, token: "," };
6060
6196
  let ref;
6061
- switch (range.increasing) {
6197
+ switch (range2.increasing) {
6062
6198
  case true: {
6063
6199
  ref = ($) => $;
6064
6200
  break;
@@ -6073,7 +6209,7 @@ function processRangeExpression(start, ws1, range, end) {
6073
6209
  }
6074
6210
  ;
6075
6211
  const abs = ref;
6076
- const lengthAdjust = 1 - Number(!range.left.inclusive) - Number(!range.right.inclusive);
6212
+ const lengthAdjust = 1 - Number(!range2.left.inclusive) - Number(!range2.right.inclusive);
6077
6213
  let children;
6078
6214
  if (typeof start === "object" && start != null && "type" in start && start.type === "Literal" && (typeof end === "object" && end != null && "type" in end && end.type === "Literal")) {
6079
6215
  let startValue = literalValue(start);
@@ -6086,7 +6222,7 @@ function processRangeExpression(start, ws1, range, end) {
6086
6222
  let endCode = endValue.charCodeAt(0);
6087
6223
  const step = startCode <= endCode ? 1 : -1;
6088
6224
  const length = abs(endCode - startCode) + lengthAdjust;
6089
- if (!range.left.inclusive) {
6225
+ if (!range2.left.inclusive) {
6090
6226
  startCode += step;
6091
6227
  }
6092
6228
  if (length <= 26) {
@@ -6107,13 +6243,13 @@ function processRangeExpression(start, ws1, range, end) {
6107
6243
  ")"
6108
6244
  ];
6109
6245
  }
6110
- if (range.error != null) {
6111
- children.unshift(range.error);
6246
+ if (range2.error != null) {
6247
+ children.unshift(range2.error);
6112
6248
  }
6113
6249
  } else if (typeof startValue === "number" && typeof endValue === "number") {
6114
6250
  const step = startValue <= endValue ? 1 : -1;
6115
6251
  const length = abs(endValue - startValue) + lengthAdjust;
6116
- if (!range.left.inclusive) {
6252
+ if (!range2.left.inclusive) {
6117
6253
  startValue += step;
6118
6254
  }
6119
6255
  if (length <= 20) {
@@ -6122,22 +6258,22 @@ function processRangeExpression(start, ws1, range, end) {
6122
6258
  Array.from({ length }, (_2, i) => startValue + i * step).join(", "),
6123
6259
  "]"
6124
6260
  ];
6125
- if (range.error != null) {
6126
- children.unshift(range.error);
6261
+ if (range2.error != null) {
6262
+ children.unshift(range2.error);
6127
6263
  }
6128
6264
  }
6129
6265
  }
6130
6266
  }
6131
6267
  if (!(children != null)) {
6132
- if (range.increasing != null) {
6133
- const sign = range.increasing ? "+" : "-";
6268
+ if (range2.increasing != null) {
6269
+ const sign = range2.increasing ? "+" : "-";
6134
6270
  end = makeLeftHandSideExpression(end);
6135
6271
  children = [
6136
- getHelperRef(range.increasing ? "range" : "revRange"),
6272
+ getHelperRef(range2.increasing ? "range" : "revRange"),
6137
6273
  "(",
6138
- range.left.inclusive ? start : [makeLeftHandSideExpression(start), ` ${sign} 1`],
6274
+ range2.left.inclusive ? start : [makeLeftHandSideExpression(start), ` ${sign} 1`],
6139
6275
  ",",
6140
- range.right.inclusive ? [makeLeftHandSideExpression(end), ` ${sign} 1`] : end,
6276
+ range2.right.inclusive ? [makeLeftHandSideExpression(end), ` ${sign} 1`] : end,
6141
6277
  ...ws1,
6142
6278
  ")"
6143
6279
  ];
@@ -6146,11 +6282,11 @@ function processRangeExpression(start, ws1, range, end) {
6146
6282
  "((s, e) => s > e ? ",
6147
6283
  getHelperRef("revRange"),
6148
6284
  "(s, e",
6149
- range.right.inclusive ? " - 1" : void 0,
6285
+ range2.right.inclusive ? " - 1" : void 0,
6150
6286
  ") : ",
6151
6287
  getHelperRef("range"),
6152
6288
  "(s, e",
6153
- range.right.inclusive ? " + 1" : void 0,
6289
+ range2.right.inclusive ? " + 1" : void 0,
6154
6290
  "))",
6155
6291
  "(",
6156
6292
  start,
@@ -6167,14 +6303,14 @@ function processRangeExpression(start, ws1, range, end) {
6167
6303
  children,
6168
6304
  start,
6169
6305
  end,
6170
- error: range.error,
6171
- left: range.left,
6172
- right: range.right,
6173
- increasing: range.increasing
6306
+ error: range2.error,
6307
+ left: range2.left,
6308
+ right: range2.right,
6309
+ increasing: range2.increasing
6174
6310
  };
6175
6311
  }
6176
- function forRange(open, forDeclaration, range, stepExp, close) {
6177
- let { start, end, left, right, increasing } = range;
6312
+ function forRange(open, forDeclaration, range2, stepExp, close) {
6313
+ let { start, end, left, right, increasing } = range2;
6178
6314
  const counterRef = makeRef("i");
6179
6315
  const infinite = typeof end === "object" && end != null && "type" in end && end.type === "Identifier" && "name" in end && end.name === "Infinity";
6180
6316
  let stepRef, asc;
@@ -6273,7 +6409,7 @@ function forRange(open, forDeclaration, range, stepExp, close) {
6273
6409
  // This declaration doesn't always appear in the output,
6274
6410
  // but it's still helpful for determining the primary loop variable
6275
6411
  declaration: forDeclaration,
6276
- children: [range.error, open, declaration, "; ", ...condition, "; ", ...increment, close],
6412
+ children: [range2.error, open, declaration, "; ", ...condition, "; ", ...increment, close],
6277
6413
  blockPrefix
6278
6414
  };
6279
6415
  }
@@ -6333,6 +6469,7 @@ function processForInOf($0) {
6333
6469
  declaration = {
6334
6470
  type: "Declaration",
6335
6471
  children: ["let ", ...expRefDec, counterRef, " = 0, ", lenRef, " = ", trimFirstSpace(expRef2), ".length"],
6472
+ decl: "let",
6336
6473
  names: []
6337
6474
  };
6338
6475
  const condition = [counterRef, " < ", lenRef, "; "];
@@ -6356,6 +6493,9 @@ function processForInOf($0) {
6356
6493
  }
6357
6494
  const { binding } = declaration;
6358
6495
  let pattern = binding?.pattern;
6496
+ if (pattern?.type === "NamedBindingPattern") {
6497
+ pattern = pattern.binding;
6498
+ }
6359
6499
  if (binding?.typeSuffix || inOf.token === "in" && declaration2 && pattern.type !== "Identifier") {
6360
6500
  const itemRef = makeRef(inOf.token === "in" ? "key" : "item");
6361
6501
  blockPrefix.push(["", {
@@ -6394,12 +6534,14 @@ function processForInOf($0) {
6394
6534
  hoistDec = {
6395
6535
  type: "Declaration",
6396
6536
  children: ["let ", counterRef, " = 0"],
6537
+ decl: "let",
6397
6538
  names: []
6398
6539
  };
6399
6540
  blockPrefix.push(["", {
6400
6541
  type: "Declaration",
6401
6542
  children: [trimFirstSpace(ws2), decl2, " = ", counterRef, "++"],
6402
- names: decl2.names
6543
+ names: decl2.names,
6544
+ decl: decl2.decl
6403
6545
  }, ";"]);
6404
6546
  break;
6405
6547
  }
@@ -6409,7 +6551,8 @@ function processForInOf($0) {
6409
6551
  hoistDec = {
6410
6552
  type: "Declaration",
6411
6553
  children: ["let ", expRef2],
6412
- names: []
6554
+ names: [],
6555
+ decl: "let"
6413
6556
  };
6414
6557
  exp = {
6415
6558
  type: "AssignmentExpression",
@@ -6421,20 +6564,58 @@ function processForInOf($0) {
6421
6564
  blockPrefix.push(["", ["if (!", hasPropRef, "(", trimFirstSpace(expRef2), ", ", trimFirstSpace(pattern), ")) continue"], ";"]);
6422
6565
  }
6423
6566
  if (decl2) {
6424
- blockPrefix.push(["", {
6425
- type: "Declaration",
6567
+ const trimmedPattern = trimFirstSpace(pattern);
6568
+ const expression = makeNode({
6569
+ type: "MemberExpression",
6426
6570
  children: [
6427
- trimFirstSpace(ws2),
6428
- decl2,
6429
- " = ",
6430
6571
  trimFirstSpace(expRef2),
6431
- "[",
6432
- trimFirstSpace(pattern),
6433
- "]"
6434
- ],
6435
- decl: decl2,
6436
- names: decl2.names
6437
- }, ";"]);
6572
+ makeNode({
6573
+ type: "Index",
6574
+ expression: trimmedPattern,
6575
+ children: ["[", trimmedPattern, "]"]
6576
+ })
6577
+ ]
6578
+ });
6579
+ blockPrefix.push([
6580
+ "",
6581
+ (() => {
6582
+ if (decl2.type === "ForDeclaration") {
6583
+ const { binding: binding2, children } = decl2;
6584
+ binding2.children.push(binding2.initializer = makeNode({
6585
+ type: "Initializer",
6586
+ expression,
6587
+ children: [" = ", expression]
6588
+ }));
6589
+ return makeNode({
6590
+ type: "Declaration",
6591
+ children: [
6592
+ trimFirstSpace(ws2),
6593
+ ...children
6594
+ ],
6595
+ bindings: [decl2.binding],
6596
+ decl: decl2.decl,
6597
+ names: decl2.names
6598
+ });
6599
+ } else {
6600
+ return makeNode({
6601
+ type: "AssignmentExpression",
6602
+ children: [
6603
+ trimFirstSpace(ws2),
6604
+ decl2,
6605
+ " = ",
6606
+ trimFirstSpace(expRef2),
6607
+ "[",
6608
+ trimFirstSpace(pattern),
6609
+ "]"
6610
+ ],
6611
+ names: decl2.names,
6612
+ lhs: decl2,
6613
+ assigned: decl2
6614
+ });
6615
+ }
6616
+ })(),
6617
+ ";"
6618
+ ]);
6438
6619
  }
6439
6620
  ;
6440
6621
  break;
@@ -6964,7 +7145,7 @@ function processTryBlock($0) {
6964
7145
  const clauses = cs.map((clause) => {
6965
7146
  let ref1;
6966
7147
  if ((ref1 = clause.binding?.parameter) && typeof ref1 === "object" && "type" in ref1 && ref1.type === "CatchPattern" && "patterns" in ref1) {
6967
- const { type, patterns } = ref1;
7148
+ const { patterns } = ref1;
6968
7149
  return {
6969
7150
  type: "PatternClause",
6970
7151
  patterns,
@@ -7155,14 +7336,21 @@ function processCallMemberExpression(node) {
7155
7336
  }
7156
7337
  }
7157
7338
  if (args.length) {
7158
- children.splice(
7159
- 0,
7160
- 2,
7161
- commaCount ? {
7339
+ if (commaCount) {
7340
+ children.splice(0, 2, {
7162
7341
  type: "ParenthesizedExpression",
7163
- children: ["(", ...call.children, ")"]
7164
- } : { ...call, type: "ParenthesizedExpression" }
7165
- );
7342
+ children: ["(", call.children, ")"],
7343
+ expression: call.children
7344
+ });
7345
+ } else {
7346
+ const middle = call.children.slice(0 + 1, -1);
7347
+ let ref2;
7348
+ children.splice(0, 2, {
7349
+ type: "ParenthesizedExpression",
7350
+ expression: middle,
7351
+ children: [call.children[0], middle, (ref2 = call.children)[ref2.length - 1]]
7352
+ });
7353
+ }
7166
7354
  if (children.length === 1) {
7167
7355
  return children[0];
7168
7356
  }
@@ -7245,14 +7433,14 @@ function processCallMemberExpression(node) {
7245
7433
  });
7246
7434
  }
7247
7435
  }
7248
- let ref2;
7436
+ let ref3;
7249
7437
  const object = {
7250
7438
  type: "ObjectExpression",
7251
7439
  children: [
7252
7440
  glob.object.children[0],
7253
7441
  // {
7254
7442
  ...parts,
7255
- (ref2 = glob.object.children)[ref2.length - 1]
7443
+ (ref3 = glob.object.children)[ref3.length - 1]
7256
7444
  // whitespace and }
7257
7445
  ],
7258
7446
  properties: parts
@@ -7313,7 +7501,7 @@ function processCallMemberExpression(node) {
7313
7501
  })
7314
7502
  ]
7315
7503
  });
7316
- let ref3;
7504
+ let ref4;
7317
7505
  return processCallMemberExpression({
7318
7506
  // in case there are more
7319
7507
  ...node,
@@ -7327,7 +7515,7 @@ function processCallMemberExpression(node) {
7327
7515
  glob.children[0],
7328
7516
  // "[" token
7329
7517
  call,
7330
- (ref3 = glob.children)[ref3.length - 1]
7518
+ (ref4 = glob.children)[ref4.length - 1]
7331
7519
  // "]" token
7332
7520
  ]
7333
7521
  }),
@@ -7340,7 +7528,7 @@ function processCallMemberExpression(node) {
7340
7528
  { ...glob.children[0], token: ", " },
7341
7529
  ...glob.children.slice(1, -1)
7342
7530
  ];
7343
- let ref4;
7531
+ let ref5;
7344
7532
  const rsliceCall = makeNode({
7345
7533
  type: "CallExpression",
7346
7534
  implicit: true,
@@ -7352,7 +7540,7 @@ function processCallMemberExpression(node) {
7352
7540
  children: [
7353
7541
  "(",
7354
7542
  args,
7355
- (ref4 = glob.children)[ref4.length - 1]
7543
+ (ref5 = glob.children)[ref5.length - 1]
7356
7544
  ]
7357
7545
  })
7358
7546
  ]
@@ -7437,8 +7625,8 @@ function convertNamedImportsToObject(node, pattern) {
7437
7625
  return { type: "Error", message: "cannot use `type` in dynamic import" };
7438
7626
  } else {
7439
7627
  const { source, binding } = specifier;
7440
- let ref5;
7441
- const delim = (ref5 = specifier.children)[ref5.length - 1];
7628
+ let ref6;
7629
+ const delim = (ref6 = specifier.children)[ref6.length - 1];
7442
7630
  return {
7443
7631
  type: pattern ? "BindingProperty" : "Property",
7444
7632
  name: source,
@@ -7448,7 +7636,7 @@ function convertNamedImportsToObject(node, pattern) {
7448
7636
  };
7449
7637
  }
7450
7638
  });
7451
- let ref6;
7639
+ let ref7;
7452
7640
  return {
7453
7641
  type: pattern ? "ObjectBindingPattern" : "ObjectExpression",
7454
7642
  names: node.names,
@@ -7457,7 +7645,7 @@ function convertNamedImportsToObject(node, pattern) {
7457
7645
  node.children[0],
7458
7646
  // {
7459
7647
  properties,
7460
- (ref6 = node.children)[ref6.length - 1]
7648
+ (ref7 = node.children)[ref7.length - 1]
7461
7649
  // }
7462
7650
  ]
7463
7651
  };
@@ -7568,10 +7756,17 @@ function makeGetterMethod(name, ws, value, returnType, block, kind = { token: "g
7568
7756
  function processBindingPatternLHS(lhs, tail) {
7569
7757
  adjustAtBindings(lhs, true);
7570
7758
  const [splices, thisAssignments] = gatherBindingCode(lhs);
7571
- tail.push(...splices.map((s) => [", ", s]), ...thisAssignments.map((a) => [", ", a]));
7759
+ const subbindings = gatherSubbindings(lhs);
7760
+ simplifyBindingProperties(lhs);
7761
+ simplifyBindingProperties(subbindings);
7762
+ tail.push(
7763
+ ...splices.map((s) => [", ", s]),
7764
+ ...thisAssignments.map((a) => [", ", a]),
7765
+ ...subbindings
7766
+ );
7572
7767
  }
7573
7768
  function processAssignments(statements) {
7574
- for (let ref7 = gatherRecursiveAll(statements, ($4) => $4.type === "AssignmentExpression" || $4.type === "UpdateExpression"), i5 = 0, len3 = ref7.length; i5 < len3; i5++) {
7769
+ for (let ref8 = gatherRecursiveAll(statements, ($4) => $4.type === "AssignmentExpression" || $4.type === "UpdateExpression"), i5 = 0, len3 = ref8.length; i5 < len3; i5++) {
7575
7770
  let extractAssignment = function(lhs) {
7576
7771
  let expr = lhs;
7577
7772
  while (expr.type === "ParenthesizedExpression") {
@@ -7591,20 +7786,20 @@ function processAssignments(statements) {
7591
7786
  ;
7592
7787
  return;
7593
7788
  };
7594
- const exp = ref7[i5];
7789
+ const exp = ref8[i5];
7595
7790
  checkValidLHS(exp.assigned);
7596
7791
  const pre = [], post = [];
7597
- let ref8;
7792
+ let ref9;
7598
7793
  switch (exp.type) {
7599
7794
  case "AssignmentExpression": {
7600
7795
  if (!exp.lhs) {
7601
7796
  continue;
7602
7797
  }
7603
- for (let ref9 = exp.lhs, i6 = 0, len4 = ref9.length; i6 < len4; i6++) {
7604
- const lhsPart = ref9[i6];
7605
- let ref10;
7606
- if (ref10 = extractAssignment(lhsPart[1])) {
7607
- const newLhs = ref10;
7798
+ for (let ref10 = exp.lhs, i6 = 0, len4 = ref10.length; i6 < len4; i6++) {
7799
+ const lhsPart = ref10[i6];
7800
+ let ref11;
7801
+ if (ref11 = extractAssignment(lhsPart[1])) {
7802
+ const newLhs = ref11;
7608
7803
  lhsPart[1] = newLhs;
7609
7804
  }
7610
7805
  }
@@ -7612,8 +7807,8 @@ function processAssignments(statements) {
7612
7807
  break;
7613
7808
  }
7614
7809
  case "UpdateExpression": {
7615
- if (ref8 = extractAssignment(exp.assigned)) {
7616
- const newLhs = ref8;
7810
+ if (ref9 = extractAssignment(exp.assigned)) {
7811
+ const newLhs = ref9;
7617
7812
  const i = exp.children.indexOf(exp.assigned);
7618
7813
  exp.assigned = exp.children[i] = newLhs;
7619
7814
  }
@@ -7645,22 +7840,22 @@ function processAssignments(statements) {
7645
7840
  }
7646
7841
  }
7647
7842
  }
7648
- for (let ref11 = gatherRecursiveAll(statements, ($6) => $6.type === "AssignmentExpression"), i7 = 0, len5 = ref11.length; i7 < len5; i7++) {
7649
- const exp = ref11[i7];
7843
+ for (let ref12 = gatherRecursiveAll(statements, ($6) => $6.type === "AssignmentExpression"), i7 = 0, len5 = ref12.length; i7 < len5; i7++) {
7844
+ const exp = ref12[i7];
7650
7845
  if (!(exp.names === null)) {
7651
7846
  continue;
7652
7847
  }
7653
7848
  let { lhs: $1, expression: $2 } = exp, tail = [], len3 = $1.length;
7654
7849
  let block;
7655
- let ref12;
7656
- if (blockContainingStatement(exp) && !(ref12 = $1[$1.length - 1])?.[ref12.length - 1]?.special) {
7850
+ let ref13;
7851
+ if (blockContainingStatement(exp) && !(ref13 = $1[$1.length - 1])?.[ref13.length - 1]?.special) {
7657
7852
  block = makeBlockFragment();
7658
- let ref13;
7659
- if (ref13 = prependStatementExpressionBlock(
7853
+ let ref14;
7854
+ if (ref14 = prependStatementExpressionBlock(
7660
7855
  { type: "Initializer", expression: $2, children: [void 0, void 0, $2] },
7661
7856
  block
7662
7857
  )) {
7663
- const ref = ref13;
7858
+ const ref = ref14;
7664
7859
  exp.children = exp.children.map(($7) => $7 === $2 ? ref : $7);
7665
7860
  $2 = ref;
7666
7861
  } else {
@@ -7737,7 +7932,7 @@ function processAssignments(statements) {
7737
7932
  message: "Slice range cannot be decreasing in assignment"
7738
7933
  });
7739
7934
  break;
7740
- } else if (m3 = lhs.type, m3 === "ObjectBindingPattern" || m3 === "ArrayBindingPattern") {
7935
+ } else if (m3 = lhs.type, m3 === "ObjectBindingPattern" || m3 === "ArrayBindingPattern" || m3 === "NamedBindingPattern") {
7741
7936
  processBindingPatternLHS(lhs, tail);
7742
7937
  gatherRecursiveAll(lhs, ($9) => $9.type === "Ref").forEach(refsToDeclare.add.bind(refsToDeclare));
7743
7938
  }
@@ -7841,9 +8036,9 @@ function unchainOptionalMemberExpression(exp, ref, innerExp) {
7841
8036
  }
7842
8037
  j++;
7843
8038
  }
7844
- let ref14;
7845
- if (ref14 = conditions.length) {
7846
- const l = ref14;
8039
+ let ref15;
8040
+ if (ref15 = conditions.length) {
8041
+ const l = ref15;
7847
8042
  const cs = flatJoin(conditions, " && ");
7848
8043
  return {
7849
8044
  ...exp,
@@ -7879,14 +8074,14 @@ function attachPostfixStatementAsExpression(exp, post) {
7879
8074
  }
7880
8075
  function processTypes(node) {
7881
8076
  const results1 = [];
7882
- for (let ref15 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len6 = ref15.length; i8 < len6; i8++) {
7883
- const unary = ref15[i8];
8077
+ for (let ref16 = gatherRecursiveAll(node, ($11) => $11.type === "TypeUnary"), i8 = 0, len6 = ref16.length; i8 < len6; i8++) {
8078
+ const unary = ref16[i8];
7884
8079
  let suffixIndex = unary.suffix.length - 1;
7885
8080
  const results2 = [];
7886
8081
  while (suffixIndex >= 0) {
7887
8082
  const suffix = unary.suffix[suffixIndex];
7888
8083
  if (typeof suffix === "object" && suffix != null && "token" in suffix && suffix.token === "?") {
7889
- const { token } = suffix;
8084
+ const {} = suffix;
7890
8085
  let count = 0;
7891
8086
  let m4;
7892
8087
  while (m4 = unary.suffix[suffixIndex], typeof m4 === "object" && m4 != null && "token" in m4 && m4.token === "?") {
@@ -7944,7 +8139,7 @@ function processTypes(node) {
7944
8139
  }
7945
8140
  results2.push(replaceNode(unary, replace, parent));
7946
8141
  } else if (typeof suffix === "object" && suffix != null && "type" in suffix && suffix.type === "NonNullAssertion") {
7947
- const { type } = suffix;
8142
+ const {} = suffix;
7948
8143
  let m6;
7949
8144
  while (m6 = unary.suffix[suffixIndex], typeof m6 === "object" && m6 != null && "type" in m6 && m6.type === "NonNullAssertion") {
7950
8145
  unary.suffix.splice(suffixIndex--, 1);
@@ -7959,10 +8154,10 @@ function processTypes(node) {
7959
8154
  const outer = unary.suffix.splice(suffixIndex + 1, Infinity);
7960
8155
  const space = getTrimmingSpace(unary);
7961
8156
  inplaceInsertTrimmingSpace(unary, "");
7962
- let ref16;
7963
- if (unary.suffix.length) ref16 = unary;
7964
- else ref16 = unary.t;
7965
- const t = ref16;
8157
+ let ref17;
8158
+ if (unary.suffix.length) ref17 = unary;
8159
+ else ref17 = unary.t;
8160
+ const t = ref17;
7966
8161
  const arg = makeNode({
7967
8162
  type: "TypeArgument",
7968
8163
  ts: true,
@@ -8007,18 +8202,18 @@ function processTypes(node) {
8007
8202
  return results1;
8008
8203
  }
8009
8204
  function processStatementExpressions(statements) {
8010
- for (let ref17 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len7 = ref17.length; i9 < len7; i9++) {
8011
- const exp = ref17[i9];
8205
+ for (let ref18 = gatherRecursiveAll(statements, ($12) => $12.type === "StatementExpression"), i9 = 0, len7 = ref18.length; i9 < len7; i9++) {
8206
+ const exp = ref18[i9];
8012
8207
  const { maybe, statement } = exp;
8013
8208
  if ((maybe || statement.type === "ThrowStatement") && blockContainingStatement(exp)) {
8014
8209
  replaceNode(exp, statement);
8015
8210
  continue;
8016
8211
  }
8017
- let ref18;
8212
+ let ref19;
8018
8213
  switch (statement.type) {
8019
8214
  case "IfStatement": {
8020
- if (ref18 = expressionizeIfStatement(statement)) {
8021
- const expression = ref18;
8215
+ if (ref19 = expressionizeIfStatement(statement)) {
8216
+ const expression = ref19;
8022
8217
  replaceNode(statement, expression, exp);
8023
8218
  } else {
8024
8219
  replaceNode(statement, wrapIIFE([["", statement]]), exp);
@@ -8077,13 +8272,13 @@ function processNegativeIndexAccess(statements) {
8077
8272
  });
8078
8273
  }
8079
8274
  function processFinallyClauses(statements) {
8080
- for (let ref19 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len8 = ref19.length; i10 < len8; i10++) {
8081
- let f = ref19[i10];
8082
- let ref20;
8083
- if (!((ref20 = blockContainingStatement(f)) && typeof ref20 === "object" && "block" in ref20 && "index" in ref20)) {
8275
+ for (let ref20 = gatherRecursiveAll(statements, ($) => $.type === "FinallyClause" && $.parent?.type !== "TryStatement"), i10 = 0, len8 = ref20.length; i10 < len8; i10++) {
8276
+ let f = ref20[i10];
8277
+ let ref21;
8278
+ if (!((ref21 = blockContainingStatement(f)) && typeof ref21 === "object" && "block" in ref21 && "index" in ref21)) {
8084
8279
  throw new Error("finally clause must be inside try statement or block");
8085
8280
  }
8086
- const { block, index } = ref20;
8281
+ const { block, index } = ref21;
8087
8282
  const indent = block.expressions[index][0];
8088
8283
  const expressions = block.expressions.slice(index + 1);
8089
8284
  const t = makeNode({
@@ -8155,8 +8350,8 @@ function processBreaksContinues(statements) {
8155
8350
  }
8156
8351
  }
8157
8352
  function processCoffeeClasses(statements) {
8158
- for (let ref21 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len9 = ref21.length; i11 < len9; i11++) {
8159
- const ce = ref21[i11];
8353
+ for (let ref22 = gatherRecursiveAll(statements, ($13) => $13.type === "ClassExpression"), i11 = 0, len9 = ref22.length; i11 < len9; i11++) {
8354
+ const ce = ref22[i11];
8160
8355
  const { expressions } = ce.body;
8161
8356
  const indent = expressions[0]?.[0] ?? "\n";
8162
8357
  const autoBinds = expressions.filter(($14) => $14[1]?.autoBind);
@@ -8306,8 +8501,8 @@ async function processProgramAsync(root) {
8306
8501
  function processRepl(root, rootIIFE) {
8307
8502
  const topBlock = gatherRecursive(rootIIFE, ($17) => $17.type === "BlockStatement")[0];
8308
8503
  let i = 0;
8309
- for (let ref22 = gatherRecursiveWithinFunction(topBlock, ($18) => $18.type === "Declaration"), i14 = 0, len11 = ref22.length; i14 < len11; i14++) {
8310
- const decl = ref22[i14];
8504
+ for (let ref23 = gatherRecursiveWithinFunction(topBlock, ($18) => $18.type === "Declaration"), i14 = 0, len11 = ref23.length; i14 < len11; i14++) {
8505
+ const decl = ref23[i14];
8311
8506
  if (!decl.names?.length) {
8312
8507
  continue;
8313
8508
  }
@@ -8320,8 +8515,8 @@ function processRepl(root, rootIIFE) {
8320
8515
  root.expressions.splice(i++, 0, ["", `var ${decl.names.join(",")}`, ";"]);
8321
8516
  }
8322
8517
  }
8323
- for (let ref23 = gatherRecursive(topBlock, ($19) => $19.type === "FunctionExpression"), i15 = 0, len12 = ref23.length; i15 < len12; i15++) {
8324
- const func = ref23[i15];
8518
+ for (let ref24 = gatherRecursive(topBlock, ($19) => $19.type === "FunctionExpression"), i15 = 0, len12 = ref24.length; i15 < len12; i15++) {
8519
+ const func = ref24[i15];
8325
8520
  if (func.name && func.parent?.type === "BlockStatement") {
8326
8521
  if (func.parent === topBlock) {
8327
8522
  replaceNode(func, void 0);
@@ -8333,8 +8528,8 @@ function processRepl(root, rootIIFE) {
8333
8528
  }
8334
8529
  }
8335
8530
  }
8336
- for (let ref24 = gatherRecursiveWithinFunction(topBlock, ($20) => $20.type === "ClassExpression"), i16 = 0, len13 = ref24.length; i16 < len13; i16++) {
8337
- const classExp = ref24[i16];
8531
+ for (let ref25 = gatherRecursiveWithinFunction(topBlock, ($20) => $20.type === "ClassExpression"), i16 = 0, len13 = ref25.length; i16 < len13; i16++) {
8532
+ const classExp = ref25[i16];
8338
8533
  let m8;
8339
8534
  if (classExp.name && classExp.parent === topBlock || (m8 = classExp.parent, typeof m8 === "object" && m8 != null && "type" in m8 && m8.type === "ReturnStatement" && "parent" in m8 && m8.parent === topBlock)) {
8340
8535
  classExp.children.unshift(classExp.name, "=");
@@ -8342,31 +8537,11 @@ function processRepl(root, rootIIFE) {
8342
8537
  }
8343
8538
  }
8344
8539
  }
8345
- function populateRefs(statements) {
8346
- const refNodes = gatherRecursive(statements, ($21) => $21.type === "Ref");
8347
- if (refNodes.length) {
8348
- const ids = gatherRecursive(statements, (s) => s.type === "Identifier");
8349
- const names = new Set(ids.flatMap(({ names: names2 }) => names2 || []));
8350
- refNodes.forEach((ref) => {
8351
- const { type, base } = ref;
8352
- if (type !== "Ref") return;
8353
- ref.type = "Identifier";
8354
- let n = 0;
8355
- let name = base;
8356
- while (names.has(name)) {
8357
- n++;
8358
- name = `${base}${n}`;
8359
- }
8360
- names.add(name);
8361
- return ref.children = ref.names = [name];
8362
- });
8363
- }
8364
- }
8365
8540
  function processPlaceholders(statements) {
8366
8541
  const placeholderMap = /* @__PURE__ */ new Map();
8367
8542
  const liftedIfs = /* @__PURE__ */ new Set();
8368
- for (let ref25 = gatherRecursiveAll(statements, ($22) => $22.type === "Placeholder"), i17 = 0, len14 = ref25.length; i17 < len14; i17++) {
8369
- const exp = ref25[i17];
8543
+ for (let ref26 = gatherRecursiveAll(statements, ($21) => $21.type === "Placeholder"), i17 = 0, len14 = ref26.length; i17 < len14; i17++) {
8544
+ const exp = ref26[i17];
8370
8545
  let ancestor;
8371
8546
  if (exp.subtype === ".") {
8372
8547
  ({ ancestor } = findAncestor(
@@ -8478,8 +8653,8 @@ function processPlaceholders(statements) {
8478
8653
  for (let i18 = 0, len15 = placeholders.length; i18 < len15; i18++) {
8479
8654
  const placeholder = placeholders[i18];
8480
8655
  typeSuffix ??= placeholder.typeSuffix;
8481
- let ref26;
8482
- (ref26 = placeholder.children)[ref26.length - 1] = ref;
8656
+ let ref27;
8657
+ (ref27 = placeholder.children)[ref27.length - 1] = ref;
8483
8658
  }
8484
8659
  const { parent } = ancestor;
8485
8660
  const body = maybeUnwrap(ancestor);
@@ -8500,16 +8675,16 @@ function processPlaceholders(statements) {
8500
8675
  }
8501
8676
  case "PipelineExpression": {
8502
8677
  const i = findChildIndex(parent, ancestor);
8503
- let ref27;
8678
+ let ref28;
8504
8679
  if (i === 1) {
8505
- ref27 = ancestor === parent.children[i];
8680
+ ref28 = ancestor === parent.children[i];
8506
8681
  } else if (i === 2) {
8507
- ref27 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8682
+ ref28 = ancestor === parent.children[i][findChildIndex(parent.children[i], ancestor)][3];
8508
8683
  } else {
8509
- ref27 = void 0;
8684
+ ref28 = void 0;
8510
8685
  }
8511
8686
  ;
8512
- outer = ref27;
8687
+ outer = ref28;
8513
8688
  break;
8514
8689
  }
8515
8690
  case "AssignmentExpression":
@@ -8524,9 +8699,12 @@ function processPlaceholders(statements) {
8524
8699
  fnExp = makeLeftHandSideExpression(fnExp);
8525
8700
  }
8526
8701
  replaceNode(ancestor, fnExp, parent);
8527
- let ref28;
8528
- if (ref28 = getTrimmingSpace(body)) {
8529
- const ws = ref28;
8702
+ if (typeof parent === "object" && parent != null && "type" in parent && parent.type === "BlockStatement" && "parent" in parent && typeof parent.parent === "object" && parent.parent != null && "type" in parent.parent && parent.parent.type === "ArrowFunction" && "ampersandBlock" in parent.parent && parent.parent.ampersandBlock === true && "body" in parent.parent && parent.parent.body === body) {
8703
+ parent.parent.body = fnExp;
8704
+ }
8705
+ let ref29;
8706
+ if (ref29 = getTrimmingSpace(body)) {
8707
+ const ws = ref29;
8530
8708
  inplaceInsertTrimmingSpace(body, "");
8531
8709
  inplacePrepend(ws, fnExp);
8532
8710
  }
@@ -8570,8 +8748,8 @@ function reorderBindingRestProperty(props) {
8570
8748
  }
8571
8749
  ];
8572
8750
  }
8573
- let ref29;
8574
- if (Array.isArray(rest.delim) && (ref29 = rest.delim)[ref29.length - 1]?.token === ",") {
8751
+ let ref30;
8752
+ if (Array.isArray(rest.delim) && (ref30 = rest.delim)[ref30.length - 1]?.token === ",") {
8575
8753
  rest.delim = rest.delim.slice(0, -1);
8576
8754
  rest.children = [...rest.children.slice(0, -1), rest.delim];
8577
8755
  }
@@ -8808,6 +8986,7 @@ var grammar = {
8808
8986
  NWBindingIdentifier,
8809
8987
  AtIdentifierRef,
8810
8988
  PinPattern,
8989
+ NamedBindingPattern,
8811
8990
  BindingPattern,
8812
8991
  ObjectBindingPattern,
8813
8992
  ObjectBindingPatternContent,
@@ -10758,24 +10937,27 @@ var PipelineHeadItem$$ = [PipelineHeadItem$0, PipelineHeadItem$1];
10758
10937
  function PipelineHeadItem(ctx, state2) {
10759
10938
  return (0, import_lib2.$EVENT_C)(ctx, state2, "PipelineHeadItem", PipelineHeadItem$$);
10760
10939
  }
10761
- var PipelineTailItem$0 = (0, import_lib2.$T)((0, import_lib2.$S)((0, import_lib2.$C)(AwaitOp, Yield, Return, Throw), (0, import_lib2.$N)(AccessStart), (0, import_lib2.$N)(MaybeParenNestedExpression)), function(value) {
10940
+ var PipelineTailItem$0 = (0, import_lib2.$T)((0, import_lib2.$S)((0, import_lib2.$C)(AwaitOp, Return, Throw), (0, import_lib2.$N)(AccessStart), (0, import_lib2.$N)(MaybeParenNestedExpression)), function(value) {
10762
10941
  return value[0];
10763
10942
  });
10764
- var PipelineTailItem$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L15, 'PipelineTailItem "import"'), (0, import_lib2.$N)(AccessStart)), function($skip, $loc, $0, $1, $2) {
10943
+ var PipelineTailItem$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$TEXT)((0, import_lib2.$S)(Yield, (0, import_lib2.$E)((0, import_lib2.$S)((0, import_lib2.$E)(_), Star)))), (0, import_lib2.$N)(AccessStart), (0, import_lib2.$N)(MaybeParenNestedExpression)), function($skip, $loc, $0, $1, $2, $3) {
10944
+ return { $loc, token: $1, type: "Yield" };
10945
+ });
10946
+ var PipelineTailItem$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L15, 'PipelineTailItem "import"'), (0, import_lib2.$N)(AccessStart)), function($skip, $loc, $0, $1, $2) {
10765
10947
  return {
10766
10948
  type: "Identifier",
10767
10949
  children: [$1]
10768
10950
  };
10769
10951
  });
10770
- var PipelineTailItem$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(NWTypePostfix, (0, import_lib2.$Q)(TypePostfix)), function($skip, $loc, $0, $1, $2) {
10952
+ var PipelineTailItem$3 = (0, import_lib2.$TS)((0, import_lib2.$S)(NWTypePostfix, (0, import_lib2.$Q)(TypePostfix)), function($skip, $loc, $0, $1, $2) {
10771
10953
  return makeAmpersandFunction({
10772
10954
  body: [" ", $1, ...$2]
10773
10955
  });
10774
10956
  });
10775
- var PipelineTailItem$3 = (0, import_lib2.$T)((0, import_lib2.$S)(PipelineHeadItem), function(value) {
10957
+ var PipelineTailItem$4 = (0, import_lib2.$T)((0, import_lib2.$S)(PipelineHeadItem), function(value) {
10776
10958
  return value[0];
10777
10959
  });
10778
- var PipelineTailItem$$ = [PipelineTailItem$0, PipelineTailItem$1, PipelineTailItem$2, PipelineTailItem$3];
10960
+ var PipelineTailItem$$ = [PipelineTailItem$0, PipelineTailItem$1, PipelineTailItem$2, PipelineTailItem$3, PipelineTailItem$4];
10779
10961
  function PipelineTailItem(ctx, state2) {
10780
10962
  return (0, import_lib2.$EVENT_C)(ctx, state2, "PipelineTailItem", PipelineTailItem$$);
10781
10963
  }
@@ -11357,8 +11539,9 @@ var LeftHandSideExpression$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impo
11357
11539
  expression
11358
11540
  };
11359
11541
  });
11360
- var LeftHandSideExpression$1 = CallExpression;
11361
- var LeftHandSideExpression$$ = [LeftHandSideExpression$0, LeftHandSideExpression$1];
11542
+ var LeftHandSideExpression$1 = NamedBindingPattern;
11543
+ var LeftHandSideExpression$2 = CallExpression;
11544
+ var LeftHandSideExpression$$ = [LeftHandSideExpression$0, LeftHandSideExpression$1, LeftHandSideExpression$2];
11362
11545
  function LeftHandSideExpression(ctx, state2) {
11363
11546
  return (0, import_lib2.$EVENT_C)(ctx, state2, "LeftHandSideExpression", LeftHandSideExpression$$);
11364
11547
  }
@@ -11981,7 +12164,7 @@ var FunctionRestParameter$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, impor
11981
12164
  function FunctionRestParameter(ctx, state2) {
11982
12165
  return (0, import_lib2.$EVENT)(ctx, state2, "FunctionRestParameter", FunctionRestParameter$0);
11983
12166
  }
11984
- var ParameterElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_lib2.$E)(AccessModifier), (0, import_lib2.$E)(_), (0, import_lib2.$C)(NWBindingIdentifier, BindingPattern), (0, import_lib2.$E)(TypeSuffix), (0, import_lib2.$E)(Initializer), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
12167
+ var ParameterElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_lib2.$E)(AccessModifier), (0, import_lib2.$E)(_), (0, import_lib2.$C)(BindingPattern, NWBindingIdentifier), (0, import_lib2.$E)(TypeSuffix), (0, import_lib2.$E)(Initializer), ParameterElementDelimiter), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
11985
12168
  var accessModifier = $2;
11986
12169
  var binding = $4;
11987
12170
  var typeSuffix = $5;
@@ -12094,12 +12277,31 @@ var PinPattern$$ = [PinPattern$0, PinPattern$1, PinPattern$2, PinPattern$3];
12094
12277
  function PinPattern(ctx, state2) {
12095
12278
  return (0, import_lib2.$EVENT_C)(ctx, state2, "PinPattern", PinPattern$$);
12096
12279
  }
12280
+ var NamedBindingPattern$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(BindingIdentifier, Caret, (0, import_lib2.$E)(_), BindingPattern), function($skip, $loc, $0, $1, $2, $3, $4) {
12281
+ var binding = $1;
12282
+ var ws = $3;
12283
+ var pattern = $4;
12284
+ pattern = prepend(ws, pattern);
12285
+ return {
12286
+ type: "NamedBindingPattern",
12287
+ // NOTE: children just has binding, not pattern, for easy destructuring
12288
+ children: [binding],
12289
+ binding,
12290
+ pattern,
12291
+ subbinding: [pattern, " = ", binding],
12292
+ typeSuffix: pattern.typeSuffix
12293
+ };
12294
+ });
12295
+ function NamedBindingPattern(ctx, state2) {
12296
+ return (0, import_lib2.$EVENT)(ctx, state2, "NamedBindingPattern", NamedBindingPattern$0);
12297
+ }
12097
12298
  var BindingPattern$0 = ObjectBindingPattern;
12098
12299
  var BindingPattern$1 = ArrayBindingPattern;
12099
12300
  var BindingPattern$2 = PinPattern;
12100
12301
  var BindingPattern$3 = Literal;
12101
12302
  var BindingPattern$4 = RegularExpressionLiteral;
12102
- var BindingPattern$$ = [BindingPattern$0, BindingPattern$1, BindingPattern$2, BindingPattern$3, BindingPattern$4];
12303
+ var BindingPattern$5 = NamedBindingPattern;
12304
+ var BindingPattern$$ = [BindingPattern$0, BindingPattern$1, BindingPattern$2, BindingPattern$3, BindingPattern$4, BindingPattern$5];
12103
12305
  function BindingPattern(ctx, state2) {
12104
12306
  return (0, import_lib2.$EVENT_C)(ctx, state2, "BindingPattern", BindingPattern$$);
12105
12307
  }
@@ -12223,7 +12425,7 @@ function NestedBindingPropertyList(ctx, state2) {
12223
12425
  return (0, import_lib2.$EVENT)(ctx, state2, "NestedBindingPropertyList", NestedBindingPropertyList$0);
12224
12426
  }
12225
12427
  var BindingProperty$0 = BindingRestProperty;
12226
- var BindingProperty$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), PropertyName, (0, import_lib2.$E)(Caret), (0, import_lib2.$E)(_), Colon, (0, import_lib2.$E)(_), (0, import_lib2.$C)(BindingIdentifier, BindingPattern), (0, import_lib2.$E)(BindingTypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12428
+ var BindingProperty$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), PropertyName, (0, import_lib2.$E)(Caret), (0, import_lib2.$E)(_), Colon, (0, import_lib2.$E)(_), (0, import_lib2.$C)(BindingPattern, BindingIdentifier), (0, import_lib2.$E)(BindingTypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12227
12429
  var ws1 = $1;
12228
12430
  var name = $2;
12229
12431
  var bind = $3;
@@ -12233,6 +12435,19 @@ var BindingProperty$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2
12233
12435
  var value = $7;
12234
12436
  var typeSuffix = $8;
12235
12437
  var initializer = $9;
12438
+ if (bind) {
12439
+ const binding = name, pattern = value;
12440
+ value = {
12441
+ type: "NamedBindingPattern",
12442
+ // NOTE: children just has binding, not pattern, for easy destructuring
12443
+ children: [binding],
12444
+ binding,
12445
+ pattern,
12446
+ subbinding: [pattern, " = ", binding],
12447
+ typeSuffix: pattern.typeSuffix,
12448
+ names: value.names
12449
+ };
12450
+ }
12236
12451
  return {
12237
12452
  type: "BindingProperty",
12238
12453
  children: [ws1, name, ws2, colon, ws3, value, initializer],
@@ -12241,8 +12456,7 @@ var BindingProperty$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2
12241
12456
  value,
12242
12457
  typeSuffix,
12243
12458
  initializer,
12244
- names: value.names,
12245
- bind: !!bind
12459
+ names: value.names
12246
12460
  };
12247
12461
  });
12248
12462
  var BindingProperty$2 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), Caret, BindingIdentifier, (0, import_lib2.$E)(BindingTypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
@@ -12307,8 +12521,7 @@ var BindingProperty$3 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2
12307
12521
  typeSuffix,
12308
12522
  initializer,
12309
12523
  names: binding.names,
12310
- identifier: binding,
12311
- bind: !!bind
12524
+ identifier: binding
12312
12525
  };
12313
12526
  });
12314
12527
  var BindingProperty$$ = [BindingProperty$0, BindingProperty$1, BindingProperty$2, BindingProperty$3];
@@ -12366,7 +12579,7 @@ function NestedBindingElements(ctx, state2) {
12366
12579
  return (0, import_lib2.$EVENT)(ctx, state2, "NestedBindingElements", NestedBindingElements$0);
12367
12580
  }
12368
12581
  var BindingElement$0 = BindingRestElement;
12369
- var BindingElement$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_lib2.$C)(BindingIdentifier, BindingPattern), (0, import_lib2.$E)(BindingTypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4) {
12582
+ var BindingElement$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_lib2.$C)(BindingPattern, BindingIdentifier), (0, import_lib2.$E)(BindingTypeSuffix), (0, import_lib2.$E)(Initializer)), function($skip, $loc, $0, $1, $2, $3, $4) {
12370
12583
  var ws = $1;
12371
12584
  var binding = $2;
12372
12585
  var typeSuffix = $3;
@@ -12391,7 +12604,7 @@ var BindingElement$$ = [BindingElement$0, BindingElement$1, BindingElement$2];
12391
12604
  function BindingElement(ctx, state2) {
12392
12605
  return (0, import_lib2.$EVENT_C)(ctx, state2, "BindingElement", BindingElement$$);
12393
12606
  }
12394
- var BindingRestElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), DotDotDot, (0, import_lib2.$C)(BindingIdentifier, BindingPattern, EmptyBindingPattern), (0, import_lib2.$E)(BindingTypeSuffix)), function($skip, $loc, $0, $1, $2, $3, $4) {
12607
+ var BindingRestElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), DotDotDot, (0, import_lib2.$C)(BindingPattern, BindingIdentifier, EmptyBindingPattern), (0, import_lib2.$E)(BindingTypeSuffix)), function($skip, $loc, $0, $1, $2, $3, $4) {
12395
12608
  var ws = $1;
12396
12609
  var dots = $2;
12397
12610
  var binding = $3;
@@ -12407,7 +12620,7 @@ var BindingRestElement$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_l
12407
12620
  rest: true
12408
12621
  };
12409
12622
  });
12410
- var BindingRestElement$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_lib2.$C)(BindingIdentifier, BindingPattern), DotDotDot), function($skip, $loc, $0, $1, $2, $3) {
12623
+ var BindingRestElement$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_lib2.$C)(BindingPattern, BindingIdentifier), DotDotDot), function($skip, $loc, $0, $1, $2, $3) {
12411
12624
  var ws = $1;
12412
12625
  var binding = $2;
12413
12626
  var dots = $3;
@@ -12495,13 +12708,17 @@ var FunctionExpression$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(FunctionSign
12495
12708
  block
12496
12709
  };
12497
12710
  });
12498
- var FunctionExpression$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$N)(ArrowFunction), OpenParen, BinaryOp, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4) {
12711
+ var FunctionExpression$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$N)(ArrowFunction), OpenParen, __, BinaryOp, __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
12499
12712
  var open = $2;
12500
- var op = $3;
12501
- var close = $4;
12713
+ var ws1 = $3;
12714
+ var op = $4;
12715
+ var ws2 = $5;
12716
+ var close = $6;
12502
12717
  if (op.special && op.call && !op.negated) return op.call;
12718
+ if (!ws1) ws1 = op.spaced ? [" "] : [];
12719
+ if (!ws2) ws2 = op.spaced ? [" "] : [];
12503
12720
  const refA = makeRef("a"), refB = makeRef("b"), body = processBinaryOpExpression([refA, [
12504
- [[], op, [], refB]
12721
+ [ws1, op, ws2, refB]
12505
12722
  // BinaryOpRHS
12506
12723
  ]]);
12507
12724
  const parameterList = [[refA, ","], refB];
@@ -12533,6 +12750,8 @@ var FunctionExpression$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, N
12533
12750
  var op = $4;
12534
12751
  var ws2 = $5;
12535
12752
  var close = $6;
12753
+ if (!ws1) ws1 = op.spaced ? [" "] : [];
12754
+ if (!ws2) ws2 = op.spaced ? [" "] : [];
12536
12755
  const refB = makeRef("b");
12537
12756
  const fn = makeAmpersandFunction({
12538
12757
  ref: refB,
@@ -12599,6 +12818,8 @@ var FunctionExpression$5 = (0, import_lib2.$TS)((0, import_lib2.$S)(OpenParen, _
12599
12818
  var ws2 = $6;
12600
12819
  var rhs = $7;
12601
12820
  var close = $8;
12821
+ if (!ws1) ws1 = op.spaced ? [" "] : [];
12822
+ if (!ws2) ws2 = op.spaced ? [" "] : [];
12602
12823
  const refA = makeRef("a");
12603
12824
  const fn = makeAmpersandFunction({
12604
12825
  ref: refA,
@@ -12623,10 +12844,9 @@ var OperatorDeclaration$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Operator, (
12623
12844
  var w = $3;
12624
12845
  var decl = $4;
12625
12846
  decl.names.forEach((name) => state.operators.set(name, behavior));
12626
- return {
12627
- ...decl,
12628
- children: [trimFirstSpace(w), ...decl.children]
12629
- };
12847
+ if (behavior?.error) decl = prepend(behavior.error, decl);
12848
+ decl = prepend(trimFirstSpace(w), decl);
12849
+ return decl;
12630
12850
  });
12631
12851
  var OperatorDeclaration$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(OperatorSignature, BracedBlock), function($skip, $loc, $0, $1, $2) {
12632
12852
  var signature = $1;
@@ -12647,11 +12867,16 @@ var OperatorDeclaration$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(Operator, _
12647
12867
  var id = $3;
12648
12868
  var behavior = $4;
12649
12869
  var ids = $5;
12870
+ const children = [];
12650
12871
  state.operators.set(id.name, behavior);
12651
- ids.forEach(([, , id2, behavior2]) => state.operators.set(id2.name, behavior2));
12872
+ if (behavior?.error) children.push(behavior.error);
12873
+ ids.forEach(([, , id2, behavior2]) => {
12874
+ state.operators.set(id2.name, behavior2);
12875
+ if (behavior2?.error) children.push(behavior2.error);
12876
+ });
12652
12877
  return {
12653
12878
  id,
12654
- children: []
12879
+ children
12655
12880
  };
12656
12881
  });
12657
12882
  var OperatorDeclaration$$ = [OperatorDeclaration$0, OperatorDeclaration$1, OperatorDeclaration$2];
@@ -12689,7 +12914,7 @@ var OperatorSignature$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_li
12689
12914
  generator: !!generator.length
12690
12915
  },
12691
12916
  block: null,
12692
- children: [async, func, generator, w1, id, w2, parameters, returnType],
12917
+ children: [async, func, generator, w1, id, behavior?.error, w2, parameters, returnType],
12693
12918
  behavior
12694
12919
  };
12695
12920
  });
@@ -12709,16 +12934,29 @@ function OperatorBehavior(ctx, state2) {
12709
12934
  var OperatorPrecedence$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$E)(_), (0, import_lib2.$C)((0, import_lib2.$EXPECT)($L27, 'OperatorPrecedence "tighter"'), (0, import_lib2.$EXPECT)($L28, 'OperatorPrecedence "looser"'), (0, import_lib2.$EXPECT)($L29, 'OperatorPrecedence "same"')), NonIdContinue, (0, import_lib2.$E)(_), (0, import_lib2.$C)(Identifier, (0, import_lib2.$S)(OpenParen, BinaryOp, CloseParen))), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
12710
12935
  var mod = $2;
12711
12936
  var op = $5;
12712
- let prec = op.type === "Identifier" ? state.operators.get(op.name).prec : getPrecedence(op[1]);
12937
+ let prec, error;
12938
+ if (op.type === "Identifier") {
12939
+ if (state.operators.has(op.name)) {
12940
+ prec = state.operators.get(op.name).prec;
12941
+ } else {
12942
+ prec = precedenceCustomDefault;
12943
+ error = {
12944
+ type: "Error",
12945
+ message: `Precedence refers to unknown operator ${op.name}`
12946
+ };
12947
+ }
12948
+ } else {
12949
+ prec = getPrecedence(op[1]);
12950
+ }
12713
12951
  switch (mod) {
12714
12952
  case "tighter":
12715
- prec += 1 / 64;
12953
+ prec += precedenceStep;
12716
12954
  break;
12717
12955
  case "looser":
12718
- prec -= 1 / 64;
12956
+ prec -= precedenceStep;
12719
12957
  break;
12720
12958
  }
12721
- return { prec };
12959
+ return { prec, error };
12722
12960
  });
12723
12961
  function OperatorPrecedence(ctx, state2) {
12724
12962
  return (0, import_lib2.$EVENT)(ctx, state2, "OperatorPrecedence", OperatorPrecedence$0);
@@ -13416,9 +13654,9 @@ function RangeEnd(ctx, state2) {
13416
13654
  var RangeExpression$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Expression, __, RangeDots, Expression), function($skip, $loc, $0, $1, $2, $3, $4) {
13417
13655
  var start = $1;
13418
13656
  var ws = $2;
13419
- var range = $3;
13657
+ var range2 = $3;
13420
13658
  var end = $4;
13421
- return processRangeExpression(start, ws, range, end);
13659
+ return processRangeExpression(start, ws, range2, end);
13422
13660
  });
13423
13661
  var RangeExpression$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(Expression, __, DotDot, (0, import_lib2.$Y)((0, import_lib2.$S)(__, CloseBracket))), function($skip, $loc, $0, $1, $2, $3, $4) {
13424
13662
  var s = $1;
@@ -14556,6 +14794,7 @@ var BinaryOpSymbol$13 = (0, import_lib2.$TV)((0, import_lib2.$EXPECT)($L23, 'Bin
14556
14794
  return {
14557
14795
  $loc,
14558
14796
  token: "instanceof",
14797
+ spaced: true,
14559
14798
  relational: true,
14560
14799
  special: true
14561
14800
  };
@@ -14564,6 +14803,7 @@ var BinaryOpSymbol$14 = (0, import_lib2.$TV)((0, import_lib2.$EXPECT)($L84, 'Bin
14564
14803
  return {
14565
14804
  $loc,
14566
14805
  token: "instanceof",
14806
+ spaced: true,
14567
14807
  relational: true,
14568
14808
  special: true,
14569
14809
  negated: true
@@ -14639,6 +14879,7 @@ var BinaryOpSymbol$40 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2
14639
14879
  return {
14640
14880
  $loc,
14641
14881
  token: $1,
14882
+ spaced: true,
14642
14883
  relational: true,
14643
14884
  special: true
14644
14885
  // for typeof shorthand
@@ -14741,6 +14982,7 @@ var CoffeeOfOp$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(OmittedNegation, __,
14741
14982
  return {
14742
14983
  $loc,
14743
14984
  token: "in",
14985
+ spaced: true,
14744
14986
  special: true,
14745
14987
  negated: true
14746
14988
  };
@@ -14762,6 +15004,7 @@ var NotOp$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)(
14762
15004
  return {
14763
15005
  $loc,
14764
15006
  token: "instanceof",
15007
+ spaced: true,
14765
15008
  relational: true,
14766
15009
  special: true,
14767
15010
  negated: true
@@ -14771,6 +15014,7 @@ var NotOp$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(In), function($skip, $loc
14771
15014
  return {
14772
15015
  $loc,
14773
15016
  token: "in",
15017
+ spaced: true,
14774
15018
  special: true,
14775
15019
  negated: true
14776
15020
  };
@@ -15556,10 +15800,13 @@ var ForDeclaration$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(LetOrConstOrVar,
15556
15800
  var ForDeclaration$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(InsertConst, (0, import_lib2.$N)(ActualMemberExpression), ForBinding), function($skip, $loc, $0, $1, $2, $3) {
15557
15801
  var c = $1;
15558
15802
  var binding = $3;
15803
+ if (gatherRecursive(binding, ($) => $.type === "PinPattern").length) {
15804
+ return $skip;
15805
+ }
15559
15806
  return {
15560
15807
  type: "ForDeclaration",
15561
15808
  children: [c, binding],
15562
- decl: c.token,
15809
+ decl: c.token.trimEnd(),
15563
15810
  binding,
15564
15811
  names: binding.names
15565
15812
  };
@@ -15729,12 +15976,17 @@ function PatternExpressionList(ctx, state2) {
15729
15976
  return (0, import_lib2.$EVENT)(ctx, state2, "PatternExpressionList", PatternExpressionList$0);
15730
15977
  }
15731
15978
  var PatternExpression$0 = BindingPattern;
15732
- var PatternExpression$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(ForbidIndentedApplication, (0, import_lib2.$E)((0, import_lib2.$P)(SingleLineBinaryOpRHS)), RestoreIndentedApplication), function($skip, $loc, $0, $1, $2, $3) {
15733
- var pattern = $2;
15734
- if (!pattern) return $skip;
15979
+ var PatternExpression$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(ForbidIndentedApplication, (0, import_lib2.$E)((0, import_lib2.$S)((0, import_lib2.$E)((0, import_lib2.$S)(BindingIdentifier, (0, import_lib2.$E)(Caret))), (0, import_lib2.$P)(SingleLineBinaryOpRHS))), RestoreIndentedApplication), function($skip, $loc, $0, $1, $2, $3) {
15980
+ var body = $2;
15981
+ if (!body) return $skip;
15982
+ const [named, rhs] = body;
15983
+ let binding;
15984
+ if (named) [binding] = named;
15735
15985
  return {
15736
15986
  type: "ConditionFragment",
15737
- children: pattern
15987
+ children: [binding, rhs],
15988
+ binding,
15989
+ rhs
15738
15990
  };
15739
15991
  });
15740
15992
  var PatternExpression$$ = [PatternExpression$0, PatternExpression$1];
@@ -15846,31 +16098,31 @@ var FinallyClause$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(Finally, (0, impo
15846
16098
  function FinallyClause(ctx, state2) {
15847
16099
  return (0, import_lib2.$EVENT)(ctx, state2, "FinallyClause", FinallyClause$0);
15848
16100
  }
15849
- var CatchParameter$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(BindingIdentifier, (0, import_lib2.$E)(TypeSuffix)), function($skip, $loc, $0, $1, $2) {
16101
+ var CatchParameter$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)(ObjectBindingPattern, ArrayBindingPattern), TypeSuffix), function($skip, $loc, $0, $1, $2) {
15850
16102
  var binding = $1;
15851
16103
  var typeSuffix = $2;
15852
16104
  return {
15853
16105
  type: "CatchParameter",
15854
16106
  binding,
15855
16107
  typeSuffix,
15856
- children: $0
16108
+ children: [binding, typeSuffix]
15857
16109
  };
15858
16110
  });
15859
- var CatchParameter$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$C)(ObjectBindingPattern, ArrayBindingPattern), TypeSuffix), function($skip, $loc, $0, $1, $2) {
16111
+ var CatchParameter$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(PatternExpressionList), function($skip, $loc, $0, $1) {
16112
+ return {
16113
+ type: "CatchPattern",
16114
+ children: $0,
16115
+ patterns: $1
16116
+ };
16117
+ });
16118
+ var CatchParameter$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(BindingIdentifier, (0, import_lib2.$E)(TypeSuffix)), function($skip, $loc, $0, $1, $2) {
15860
16119
  var binding = $1;
15861
16120
  var typeSuffix = $2;
15862
16121
  return {
15863
16122
  type: "CatchParameter",
15864
16123
  binding,
15865
16124
  typeSuffix,
15866
- children: [binding, typeSuffix]
15867
- };
15868
- });
15869
- var CatchParameter$2 = (0, import_lib2.$TS)((0, import_lib2.$S)(PatternExpressionList), function($skip, $loc, $0, $1) {
15870
- return {
15871
- type: "CatchPattern",
15872
- children: $0,
15873
- patterns: $1
16125
+ children: $0
15874
16126
  };
15875
16127
  });
15876
16128
  var CatchParameter$$ = [CatchParameter$0, CatchParameter$1, CatchParameter$2];
@@ -16364,12 +16616,15 @@ var ImportDeclaration$1 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_li
16364
16616
  var imports = $5;
16365
16617
  var ws2 = $6;
16366
16618
  var from = $7;
16619
+ const errors = [];
16620
+ if (behavior?.error) errors.push(behavior.error);
16367
16621
  imports.specifiers.forEach((spec) => {
16368
16622
  state.operators.set(spec.binding.name, spec.behavior ?? behavior);
16623
+ if (spec.behavior?.error) errors.push(spec.behavior.error);
16369
16624
  });
16370
16625
  return {
16371
16626
  type: "ImportDeclaration",
16372
- children: [i, trimFirstSpace(ws1), imports, ws2, from],
16627
+ children: [i, ...errors, trimFirstSpace(ws1), imports, ws2, from],
16373
16628
  // omit $2 = Operator and $3 = OperatorBehavior
16374
16629
  imports,
16375
16630
  from
@@ -16412,12 +16667,15 @@ var ImportDeclaration$5 = (0, import_lib2.$TS)((0, import_lib2.$S)(ImpliedFromCl
16412
16667
  var behavior = $6;
16413
16668
  var ows = $7;
16414
16669
  var imports = $8;
16670
+ const errors = [];
16671
+ if (behavior?.error) errors.push(behavior.error);
16415
16672
  imports.specifiers.forEach((spec) => {
16416
16673
  state.operators.set(spec.binding.name, spec.behavior ?? behavior);
16674
+ if (spec.behavior?.error) errors.push(spec.behavior.error);
16417
16675
  });
16418
16676
  return {
16419
16677
  type: "ImportDeclaration",
16420
- children: [i, iws, trimFirstSpace(ows), imports, fws, from],
16678
+ children: [i, iws, ...errors, trimFirstSpace(ows), imports, fws, from],
16421
16679
  // omit Operator and OperatorBehavior
16422
16680
  imports,
16423
16681
  from
@@ -16599,7 +16857,7 @@ var OperatorImportSpecifier$0 = (0, import_lib2.$TS)((0, import_lib2.$S)(__, Mod
16599
16857
  return {
16600
16858
  binding,
16601
16859
  behavior,
16602
- children: [$1, $2, $4, $5, $6, $7]
16860
+ children: [$1, $2, $3?.error, $4, $5, $6, $7]
16603
16861
  };
16604
16862
  });
16605
16863
  var OperatorImportSpecifier$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(__, ImportedBinding, (0, import_lib2.$E)(OperatorBehavior), ObjectPropertyDelimiter), function($skip, $loc, $0, $1, $2, $3, $4) {
@@ -16608,7 +16866,7 @@ var OperatorImportSpecifier$1 = (0, import_lib2.$TS)((0, import_lib2.$S)(__, Imp
16608
16866
  return {
16609
16867
  binding,
16610
16868
  behavior,
16611
- children: [$1, $2, $4]
16869
+ children: [$1, $2, $3?.error, $4]
16612
16870
  };
16613
16871
  });
16614
16872
  var OperatorImportSpecifier$$ = [OperatorImportSpecifier$0, OperatorImportSpecifier$1];
@@ -17486,7 +17744,7 @@ var By$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L1
17486
17744
  function By(ctx, state2) {
17487
17745
  return (0, import_lib2.$EVENT)(ctx, state2, "By", By$0);
17488
17746
  }
17489
- var Caret$0 = (0, import_lib2.$TV)((0, import_lib2.$EXPECT)($L22, 'Caret "^"'), function($skip, $loc, $0, $1) {
17747
+ var Caret$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L22, 'Caret "^"'), (0, import_lib2.$N)((0, import_lib2.$EXPECT)($L22, 'Caret "^"'))), function($skip, $loc, $0, $1, $2) {
17490
17748
  return { $loc, token: $1 };
17491
17749
  });
17492
17750
  function Caret(ctx, state2) {
@@ -17731,7 +17989,7 @@ function Import(ctx, state2) {
17731
17989
  return (0, import_lib2.$EVENT)(ctx, state2, "Import", Import$0);
17732
17990
  }
17733
17991
  var In$0 = (0, import_lib2.$TS)((0, import_lib2.$S)((0, import_lib2.$EXPECT)($L180, 'In "in"'), NonIdContinue), function($skip, $loc, $0, $1, $2) {
17734
- return { $loc, token: $1 };
17992
+ return { $loc, token: $1, spaced: true };
17735
17993
  });
17736
17994
  function In(ctx, state2) {
17737
17995
  return (0, import_lib2.$EVENT)(ctx, state2, "In", In$0);