@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @torpor/view
2
2
 
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 44cf656: Fix: replace @for vars in even more places
8
+
3
9
  ## 0.0.4
4
10
 
5
11
  ### Patch Changes
package/dist/compile.cjs CHANGED
@@ -838,16 +838,22 @@ function getFragmentVarPathPart(path, varPath, status, root = false) {
838
838
  return varPath;
839
839
  }
840
840
 
841
- // src/compile/build/client/buildRun.ts
842
- function buildRun(functionName, functionBody, status, b) {
843
- status.imports.add("$run");
844
- b.append(`$run(function ${functionName}() {`);
841
+ // src/compile/build/client/replaceForVarNames.ts
842
+ function replaceForVarNames(value, status) {
845
843
  for (let varName of status.forVarNames) {
846
- functionBody = functionBody.replaceAll(
847
- new RegExp(`([\\s\\(\\[\\{])${varName}([\\s\\.\\(\\)\\[\\]\\};])`, "g"),
844
+ value = value.replaceAll(
845
+ new RegExp(`(^|\\s|\\(|\\[|\\{)${varName}($|\\s|\\.|\\(|\\)|\\[|\\]|\\}|;)`, "g"),
848
846
  `$1t_item.data.${varName}$2`
849
847
  );
850
848
  }
849
+ return value;
850
+ }
851
+
852
+ // src/compile/build/client/buildRun.ts
853
+ function buildRun(functionName, functionBody, status, b) {
854
+ functionBody = replaceForVarNames(functionBody, status);
855
+ status.imports.add("$run");
856
+ b.append(`$run(function ${functionName}() {`);
851
857
  b.append(functionBody);
852
858
  b.append("});");
853
859
  }
@@ -1365,15 +1371,10 @@ function buildControlNode(node, status, b) {
1365
1371
  }
1366
1372
 
1367
1373
  // src/compile/build/client/buildMount.ts
1368
- function buildRun2(functionName, functionBody, status, b) {
1374
+ function buildMount(functionName, functionBody, status, b) {
1375
+ functionBody = replaceForVarNames(functionBody, status);
1369
1376
  status.imports.add("$mount");
1370
1377
  b.append(`$mount(function ${functionName}() {`);
1371
- for (let varName of status.forVarNames) {
1372
- functionBody = functionBody.replaceAll(
1373
- new RegExp(`([\\s\\(\\[])${varName}([\\s\\.\\(\\)\\[\\];])`, "g"),
1374
- `$1t_item.data.${varName}$2`
1375
- );
1376
- }
1377
1378
  b.append(functionBody);
1378
1379
  b.append("});");
1379
1380
  }
@@ -1506,7 +1507,7 @@ function buildElementAttributes(node, varName, status, b) {
1506
1507
  } else if (name === ":value" || name === ":checked") {
1507
1508
  buildBindAttribute(node, varName, name, value, status, b);
1508
1509
  } else if (name === ":onmount") {
1509
- buildRun2("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
1510
+ buildMount("elMount", `return (${trimEnd(value.trim(), ";")})(${varName});`, status, b);
1510
1511
  } else if (name.startsWith("on")) {
1511
1512
  buildEventAttribute(varName, name, value, status, b);
1512
1513
  } else if (name.startsWith(":transition")) {
@@ -1530,6 +1531,7 @@ function buildElementAttributes(node, varName, status, b) {
1530
1531
  }
1531
1532
  }
1532
1533
  function buildBindGroupAttribute(node, varName, value, status, b) {
1534
+ value = replaceForVarNames(value, status);
1533
1535
  let eventName = "change";
1534
1536
  let inputValue = node.attributes.find((a) => a.name === "value")?.value;
1535
1537
  let set = `${value} == ${inputValue}`;
@@ -1542,6 +1544,7 @@ function buildBindGroupAttribute(node, varName, value, status, b) {
1542
1544
  });`);
1543
1545
  }
1544
1546
  function buildBindAttribute(node, varName, name, value, status, b) {
1547
+ value = replaceForVarNames(value, status);
1545
1548
  let eventName = "input";
1546
1549
  let defaultValue = '""';
1547
1550
  let inputValue = "e.target.value";
@@ -1577,17 +1580,13 @@ function buildBindAttribute(node, varName, name, value, status, b) {
1577
1580
  b.append(`t_event(${varName}, "${eventName}", (e) => ${value} = ${inputValue});`);
1578
1581
  }
1579
1582
  function buildEventAttribute(varName, name, value, status, b) {
1580
- for (let varName2 of status.forVarNames) {
1581
- value = value.replaceAll(
1582
- new RegExp(`([\\s\\(\\[])${varName2}([\\s\\.\\(\\)\\[\\];])`, "g"),
1583
- `$1t_item.data.${varName2}$2`
1584
- );
1585
- }
1583
+ value = replaceForVarNames(value, status);
1586
1584
  const eventName = name.substring(2);
1587
1585
  status.imports.add("t_event");
1588
1586
  b.append(`t_event(${varName}, "${eventName}", ${value});`);
1589
1587
  }
1590
1588
  function buildTransitionAttribute(node, varName, name, value, status, b) {
1589
+ value = replaceForVarNames(value, status);
1591
1590
  status.imports.add("t_animate");
1592
1591
  let entryVarName = nextVarName("trans_in", status);
1593
1592
  let exitVarName = nextVarName("trans_out", status);
@@ -3540,6 +3539,8 @@ function parseStyleBlock(status) {
3540
3539
  } else {
3541
3540
  break;
3542
3541
  }
3542
+ } else {
3543
+ return block;
3543
3544
  }
3544
3545
  consumeSpace(status);
3545
3546
  }