@kithinji/pod 1.0.15 → 1.0.17

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.js CHANGED
@@ -1438,6 +1438,38 @@ var ASTUtilities = class {
1438
1438
  body.push(...statements);
1439
1439
  }
1440
1440
  }
1441
+ addEffectCleanup(scope, effectCall) {
1442
+ const cleanupId = scope.generateUidIdentifier("cleanup");
1443
+ return [
1444
+ // const _cleanup1 = $effect(...)
1445
+ this.t.variableDeclaration("const", [
1446
+ this.t.variableDeclarator(cleanupId, effectCall)
1447
+ ]),
1448
+ // self.__cleanup = [...(self.__cleanup || []), _cleanup1]
1449
+ this.t.expressionStatement(
1450
+ this.t.assignmentExpression(
1451
+ "=",
1452
+ this.t.memberExpression(
1453
+ this.t.identifier("self"),
1454
+ this.t.identifier("__cleanup")
1455
+ ),
1456
+ this.t.arrayExpression([
1457
+ this.t.spreadElement(
1458
+ this.t.logicalExpression(
1459
+ "||",
1460
+ this.t.memberExpression(
1461
+ this.t.identifier("self"),
1462
+ this.t.identifier("__cleanup")
1463
+ ),
1464
+ this.t.arrayExpression([])
1465
+ )
1466
+ ),
1467
+ cleanupId
1468
+ ])
1469
+ )
1470
+ )
1471
+ ];
1472
+ }
1441
1473
  };
1442
1474
  var JSXUtilities = class {
1443
1475
  constructor(t) {
@@ -1629,6 +1661,7 @@ var ElementTransformer = class {
1629
1661
  jsxElement.openingElement.attributes,
1630
1662
  elId,
1631
1663
  statements,
1664
+ scope,
1632
1665
  context2
1633
1666
  );
1634
1667
  if (hasRef && refValue) {
@@ -1639,8 +1672,9 @@ var ElementTransformer = class {
1639
1672
  );
1640
1673
  }
1641
1674
  if (hasDangerousHTML && dangerousHTMLValue) {
1642
- statements.push(
1643
- this.t.expressionStatement(
1675
+ const effectCall = this.t.callExpression(this.t.identifier("$effect"), [
1676
+ this.t.arrowFunctionExpression(
1677
+ [],
1644
1678
  this.t.assignmentExpression(
1645
1679
  "=",
1646
1680
  this.t.memberExpression(elId, this.t.identifier("innerHTML")),
@@ -1650,7 +1684,12 @@ var ElementTransformer = class {
1650
1684
  )
1651
1685
  )
1652
1686
  )
1687
+ ]);
1688
+ const cleanupStatements = this.astUtils.addEffectCleanup(
1689
+ scope,
1690
+ effectCall
1653
1691
  );
1692
+ statements.push(...cleanupStatements);
1654
1693
  }
1655
1694
  if (!hasDangerousHTML) {
1656
1695
  this.processDOMChildren(
@@ -1758,7 +1797,7 @@ var ElementTransformer = class {
1758
1797
  }
1759
1798
  }
1760
1799
  }
1761
- processDOMAttributes(attributes, elId, statements, context2) {
1800
+ processDOMAttributes(attributes, elId, statements, scope, context2) {
1762
1801
  let hasRef = false;
1763
1802
  let refValue = null;
1764
1803
  let hasDangerousHTML = false;
@@ -1775,14 +1814,20 @@ var ElementTransformer = class {
1775
1814
  context2.observableSignals,
1776
1815
  this.astUtils
1777
1816
  );
1778
- statements.push(
1779
- this.t.expressionStatement(
1817
+ const effectCall = this.t.callExpression(this.t.identifier("$effect"), [
1818
+ this.t.arrowFunctionExpression(
1819
+ [],
1780
1820
  this.t.callExpression(this.t.identifier("$spread"), [
1781
1821
  elId,
1782
1822
  this.astUtils.replaceThisWithSelf(replaced)
1783
1823
  ])
1784
1824
  )
1825
+ ]);
1826
+ const cleanupStatements = this.astUtils.addEffectCleanup(
1827
+ scope,
1828
+ effectCall
1785
1829
  );
1830
+ statements.push(...cleanupStatements);
1786
1831
  continue;
1787
1832
  }
1788
1833
  const key = attr.name.name;
@@ -1825,7 +1870,7 @@ var ElementTransformer = class {
1825
1870
  continue;
1826
1871
  }
1827
1872
  if (key === "style" && this.t.isJSXExpressionContainer(attr.value)) {
1828
- this.processStyleAttribute(attr, elId, statements, context2);
1873
+ this.processStyleAttribute(attr, elId, statements, scope, context2);
1829
1874
  continue;
1830
1875
  }
1831
1876
  this.processRegularAttribute(key, attr, elId, statements, context2);
@@ -1857,7 +1902,7 @@ var ElementTransformer = class {
1857
1902
  )
1858
1903
  );
1859
1904
  }
1860
- processStyleAttribute(attr, elId, statements, context2) {
1905
+ processStyleAttribute(attr, elId, statements, scope, context2) {
1861
1906
  if (!this.t.isJSXExpressionContainer(attr.value)) return;
1862
1907
  this.observableManager.collectObservables(
1863
1908
  attr.value.expression,
@@ -1869,17 +1914,17 @@ var ElementTransformer = class {
1869
1914
  context2.observableSignals,
1870
1915
  this.astUtils
1871
1916
  );
1872
- statements.push(
1873
- this.t.expressionStatement(
1917
+ const effectCall = this.t.callExpression(this.t.identifier("$effect"), [
1918
+ this.t.arrowFunctionExpression(
1919
+ [],
1874
1920
  this.t.callExpression(this.t.identifier("$style"), [
1875
1921
  elId,
1876
- this.t.arrowFunctionExpression(
1877
- [],
1878
- this.astUtils.replaceThisWithSelf(replaced)
1879
- )
1922
+ this.astUtils.replaceThisWithSelf(replaced)
1880
1923
  ])
1881
1924
  )
1882
- );
1925
+ ]);
1926
+ const cleanupStatements = this.astUtils.addEffectCleanup(scope, effectCall);
1927
+ statements.push(...cleanupStatements);
1883
1928
  }
1884
1929
  processRegularAttribute(key, attr, elId, statements, context2) {
1885
1930
  const attrName = key === "className" ? "class" : key;
@@ -2027,7 +2072,8 @@ function j2d({ types: t }) {
2027
2072
  { local: "$createComponent", imported: "createComponent" },
2028
2073
  { local: "$style", imported: "style" },
2029
2074
  { local: "$spread", imported: "spread" },
2030
- { local: "$toSignal", imported: "toSignal" }
2075
+ { local: "$toSignal", imported: "toSignal" },
2076
+ { local: "$effect", imported: "effect" }
2031
2077
  ];
2032
2078
  for (const helper of helpers) {
2033
2079
  path14.unshiftContainer(
@@ -4670,7 +4716,7 @@ function printNextSteps(projectName, env, services) {
4670
4716
 
4671
4717
  // src/main.ts
4672
4718
  var program = new Command();
4673
- program.name("pod").description("Pod cli tool").version("1.0.15");
4719
+ program.name("pod").description("Pod cli tool").version("1.0.17");
4674
4720
  program.command("new <name>").description("Start a new Pod Project").action(async (name) => {
4675
4721
  await addNew(name);
4676
4722
  const appDir = path13.resolve(process.cwd(), name);