@torpor/view 0.0.4 → 0.0.5

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/compile.js CHANGED
@@ -812,16 +812,22 @@ function getFragmentVarPathPart(path, varPath, status, root = false) {
812
812
  return varPath;
813
813
  }
814
814
 
815
- // src/compile/build/client/buildRun.ts
816
- function buildRun(functionName, functionBody, status, b) {
817
- status.imports.add("$run");
818
- b.append(`$run(function ${functionName}() {`);
815
+ // src/compile/build/client/replaceForVarNames.ts
816
+ function replaceForVarNames(value, status) {
819
817
  for (let varName of status.forVarNames) {
820
- functionBody = functionBody.replaceAll(
821
- new RegExp(`([\\s\\(\\[\\{])${varName}([\\s\\.\\(\\)\\[\\]\\};])`, "g"),
818
+ value = value.replaceAll(
819
+ new RegExp(`(^|\\s|\\(|\\[|\\{)${varName}($|\\s|\\.|\\(|\\)|\\[|\\]|\\}|;)`, "g"),
822
820
  `$1t_item.data.${varName}$2`
823
821
  );
824
822
  }
823
+ return value;
824
+ }
825
+
826
+ // src/compile/build/client/buildRun.ts
827
+ function buildRun(functionName, functionBody, status, b) {
828
+ functionBody = replaceForVarNames(functionBody, status);
829
+ status.imports.add("$run");
830
+ b.append(`$run(function ${functionName}() {`);
825
831
  b.append(functionBody);
826
832
  b.append("});");
827
833
  }
@@ -1339,15 +1345,10 @@ function buildControlNode(node, status, b) {
1339
1345
  }
1340
1346
 
1341
1347
  // src/compile/build/client/buildMount.ts
1342
- function buildRun2(functionName, functionBody, status, b) {
1348
+ function buildMount(functionName, functionBody, status, b) {
1349
+ functionBody = replaceForVarNames(functionBody, status);
1343
1350
  status.imports.add("$mount");
1344
1351
  b.append(`$mount(function ${functionName}() {`);
1345
- for (let varName of status.forVarNames) {
1346
- functionBody = functionBody.replaceAll(
1347
- new RegExp(`([\\s\\(\\[])${varName}([\\s\\.\\(\\)\\[\\];])`, "g"),
1348
- `$1t_item.data.${varName}$2`
1349
- );
1350
- }
1351
1352
  b.append(functionBody);
1352
1353
  b.append("});");
1353
1354
  }
@@ -1480,7 +1481,7 @@ function buildElementAttributes(node, varName, status, b) {
1480
1481
  } else if (name === ":value" || name === ":checked") {
1481
1482
  buildBindAttribute(node, varName, name, value, status, b);
1482
1483
  } else if (name === ":onmount") {
1483
- buildRun2("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
1484
+ buildMount("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
1484
1485
  } else if (name.startsWith("on")) {
1485
1486
  buildEventAttribute(varName, name, value, status, b);
1486
1487
  } else if (name.startsWith(":transition")) {
@@ -1504,6 +1505,7 @@ function buildElementAttributes(node, varName, status, b) {
1504
1505
  }
1505
1506
  }
1506
1507
  function buildBindGroupAttribute(node, varName, value, status, b) {
1508
+ value = replaceForVarNames(value, status);
1507
1509
  let eventName = "change";
1508
1510
  let inputValue = node.attributes.find((a) => a.name === "value")?.value;
1509
1511
  let set = `${value} == ${inputValue}`;
@@ -1516,6 +1518,7 @@ function buildBindGroupAttribute(node, varName, value, status, b) {
1516
1518
  });`);
1517
1519
  }
1518
1520
  function buildBindAttribute(node, varName, name, value, status, b) {
1521
+ value = replaceForVarNames(value, status);
1519
1522
  let eventName = "input";
1520
1523
  let defaultValue = '""';
1521
1524
  let inputValue = "e.target.value";
@@ -1551,17 +1554,13 @@ function buildBindAttribute(node, varName, name, value, status, b) {
1551
1554
  b.append(`t_event(${varName}, "${eventName}", (e) => ${value} = ${inputValue});`);
1552
1555
  }
1553
1556
  function buildEventAttribute(varName, name, value, status, b) {
1554
- for (let varName2 of status.forVarNames) {
1555
- value = value.replaceAll(
1556
- new RegExp(`([\\s\\(\\[])${varName2}([\\s\\.\\(\\)\\[\\];])`, "g"),
1557
- `$1t_item.data.${varName2}$2`
1558
- );
1559
- }
1557
+ value = replaceForVarNames(value, status);
1560
1558
  const eventName = name.substring(2);
1561
1559
  status.imports.add("t_event");
1562
1560
  b.append(`t_event(${varName}, "${eventName}", ${value});`);
1563
1561
  }
1564
1562
  function buildTransitionAttribute(node, varName, name, value, status, b) {
1563
+ value = replaceForVarNames(value, status);
1565
1564
  status.imports.add("t_animate");
1566
1565
  let entryVarName = nextVarName("trans_in", status);
1567
1566
  let exitVarName = nextVarName("trans_out", status);
@@ -3514,6 +3513,8 @@ function parseStyleBlock(status) {
3514
3513
  } else {
3515
3514
  break;
3516
3515
  }
3516
+ } else {
3517
+ return block;
3517
3518
  }
3518
3519
  consumeSpace(status);
3519
3520
  }