@torpor/view 0.0.3 → 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 +13 -0
- package/dist/compile.cjs +21 -20
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +21 -20
- package/dist/compile.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +1 -1
- package/src/compile/build/client/buildElementNode.ts +8 -8
- package/src/compile/build/client/buildMount.ts +4 -9
- package/src/compile/build/client/buildRun.ts +3 -8
- package/src/compile/build/client/replaceForVarNames.ts +16 -0
- package/src/compile/parse/parseStyles.ts +2 -0
- package/test/for/components/ForEscape.torp +1 -0
- package/test/for/components/output/ForEscape-client.ts +11 -2
- package/test/for/components/output/ForEscape-server.ts +1 -1
- package/test/for/components/temp/{ForEscape-client-2c881b16a6382edf074e1f151a209d60ca9b2b66.ts → ForEscape-client-80d3078cf15001f2ab37b0ec63cfce7267a8a166.ts} +11 -2
- package/test/for/components/temp/{ForEscape-server-94a1bceabed006e15326a7f635724d88c3daa8fe.ts → ForEscape-server-375744ca1e10e5c8ed7dd6420beef72107e55568.ts} +1 -1
- package/test/for/for-escape.test.ts +13 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.0.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 76dd6ea: Fix: return on invalid style
|
|
14
|
+
- 8f0a0a1: Fix: replace @for vars in more places
|
|
15
|
+
|
|
3
16
|
## 0.0.3
|
|
4
17
|
|
|
5
18
|
### 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/
|
|
842
|
-
function
|
|
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
|
-
|
|
847
|
-
new RegExp(`(
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|