@torpor/view 0.4.4 → 0.4.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/CHANGELOG.md +17 -0
- package/dist/compile.cjs +89 -65
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +89 -65
- package/dist/compile.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/compile/build/client/buildAwaitNode.ts +3 -2
- package/src/compile/build/client/buildCode.ts +14 -11
- package/src/compile/build/client/buildComponentNode.ts +15 -13
- package/src/compile/build/client/buildElementNode.ts +5 -4
- package/src/compile/build/client/buildForNode.ts +22 -12
- package/src/compile/build/client/buildHtmlNode.ts +14 -2
- package/src/compile/build/client/buildIfNode.ts +3 -2
- package/src/compile/build/client/buildSwitchNode.ts +3 -2
- package/src/compile/parse/parseCode.ts +5 -2
- package/src/compile/parse/parseTag.ts +4 -0
- package/src/compile/parse/scopeStyles.ts +13 -12
- package/src/render/runControl.ts +1 -1
- package/test/bind/components/output/BindComponent-client.ts +3 -1
- package/test/bind/components/temp/{BindComponent-client-9da323149e29bbb0d7eaf5a86ed541357f1219f8.ts → BindComponent-client-59dbb5565268702ed2935e7e8cc7609b0f956bdc.ts} +3 -1
- package/test/child-component/components/output/ChildComponent-client.ts +3 -1
- package/test/child-component/components/temp/{ChildComponent-client-6033ce1f59fe1ce3f3dfb3d7845807e7f047b18d.ts → ChildComponent-client-a0ac41e8516d1584b2318770b6a5fc791e07b53b.ts} +3 -1
- package/test/class/components/output/Class-client.ts +3 -1
- package/test/class/components/temp/{Class-client-a5e3f4dd7b0272d69b856f3ef4aa43b83bc2d849.ts → Class-client-28a59ce1bd5ccd2c6cc48d803216a5346fcf2329.ts} +3 -1
- package/test/component/components/output/Component-client.ts +3 -1
- package/test/component/components/temp/{Component-client-ff200ee2a7a5f08d0473fddffa1f3ba5eb641d2a.ts → Component-client-475c9724b22ebc18149075860326ffd395c4caa0.ts} +3 -1
- package/test/effects/components/output/ForEffect-client.ts +3 -1
- package/test/effects/components/temp/{ForEffect-client-b1cff64d6b44a881a4bcf4b1a3dee3fa64c9ec7b.ts → ForEffect-client-841255d13e0691d88345d9ea89c5fb021ca4db02.ts} +3 -1
- package/test/for/components/output/For-client.ts +3 -1
- package/test/for/components/output/ForAfterFor-client.ts +6 -2
- package/test/for/components/output/ForContainingFor-client.ts +6 -2
- package/test/for/components/output/ForContainingFunction-client.ts +3 -1
- package/test/for/components/output/ForContainingIf-client.ts +3 -1
- package/test/for/components/output/ForEscape-client.ts +3 -1
- package/test/for/components/output/ForIn-client.ts +3 -1
- package/test/for/components/output/ForOf-client.ts +3 -1
- package/test/for/components/temp/{For-client-8fd92bf0c26cb8e97006a302104ebb2fdcd2e818.ts → For-client-69c16449ab9b63fd8ace8cb1364105a80e6e1c40.ts} +3 -1
- package/test/for/components/temp/{ForAfterFor-client-509955ddc13396ede05c9986a6dcc8bbebd00cf3.ts → ForAfterFor-client-b57ee13c70d8504456dbb5f75efd9defecab8cd1.ts} +6 -2
- package/test/for/components/temp/{ForContainingFor-client-4f600c73a6583c84d981a82fae42332f983f0b36.ts → ForContainingFor-client-bc5cc8b51b248bebc28fdba5e69d56af4148a66a.ts} +6 -2
- package/test/for/components/temp/{ForContainingFunction-client-9bacc4a7214f2385d98b358d29443363f8b9e78d.ts → ForContainingFunction-client-f29a23d27f5458760406127c58520d6abf924409.ts} +3 -1
- package/test/for/components/temp/{ForContainingIf-client-92b3c13b0fbe3d7900c05dd2e833d8e51d1bc66c.ts → ForContainingIf-client-da96adc2e61301142e0728b55665ef241c19f9a4.ts} +3 -1
- package/test/for/components/temp/{ForEscape-client-29cdd1ae0528a32f5737295287489e9bbd42889d.ts → ForEscape-client-f2b7590f8e93981bc0cd0c0845ad22df1dc050b6.ts} +3 -1
- package/test/for/components/temp/{ForIn-client-fffaa596adb40e4067931af81cc13fc971dd1813.ts → ForIn-client-8754824447479fba5ba3676b5c1dcb1e3591575f.ts} +3 -1
- package/test/for/components/temp/{ForOf-client-e6d0948fbd00bfbcbc7099f84331bc3d493abc28.ts → ForOf-client-852d13b24329f89bd864313bc376f73174b9965e.ts} +3 -1
- package/test/html/components/output/Html-client.ts +1 -1
- package/test/html/components/temp/{Html-client-14bf031fae1c40ea86913ca71aee00b947d88b4d.ts → Html-client-2e1b6cfd24f6114f3e9b0fb0adc0022841c2196b.ts} +1 -1
- package/test/if/components/output/IfContainingFor-client.ts +3 -1
- package/test/if/components/temp/{IfContainingFor-client-a1246616d908018a77caa27aca6f9fa63e325960.ts → IfContainingFor-client-dc70bb4ae31c2320b4e22f4f26d87d5650667713.ts} +3 -1
- package/test/party/components/output/EmitToParent-client.ts +4 -1
- package/test/party/components/output/InputSelect-client.ts +3 -1
- package/test/party/components/output/Loop-client.ts +4 -1
- package/test/party/components/output/Props-client.ts +6 -1
- package/test/party/components/temp/{EmitToParent-client-02c78412e4cacc27cbc857d68d5a064474ccc882.ts → EmitToParent-client-3666116e65f3e8d4dbb0782d93f631a855b094ec.ts} +4 -1
- package/test/party/components/temp/{InputSelect-client-49f9978ab5f32d13ada9d1c3d7522cbafa4c3cc7.ts → InputSelect-client-6827b541b2a0569745e21823bc3420bdfff746b2.ts} +3 -1
- package/test/party/components/temp/{Loop-client-d8be7f7caf99d17b048d915d2dbe1db97c44aecf.ts → Loop-client-79bc3b13d7f6a733694cb5f3ee4b91667ea5c5b5.ts} +4 -1
- package/test/party/components/temp/{Props-client-c126fe2030c202b8371f72d8395d0a210a0d67c2.ts → Props-client-7dbf4a9aecc5b1890492db1d30904341bfd0e9eb.ts} +6 -1
- package/test/props/components/output/Reactive-client.ts +3 -1
- package/test/props/components/temp/{Reactive-client-626575b72eeb6e7eafe7352f0acda1502b0c3d37.ts → Reactive-client-dc9aadcdcb4a950141942769806a1017c9076b20.ts} +3 -1
- package/test/slots/components/output/LetSlot-client.ts +6 -2
- package/test/slots/components/temp/{LetSlot-client-2cd77fd4f84810a55926f0265a9b780516982d5b.ts → LetSlot-client-328fd8a9fcfc6b68c0380f99d3f09ede33babc2f.ts} +6 -2
- package/test/special-component/components/output/SpecialComponent-client.ts +2 -1
- package/test/special-component/components/temp/{SpecialComponent-client-1955ef6a59b67e29ea076ed28758625922ff7d7b.ts → SpecialComponent-client-4a9face6c61d943cd94c995b174877f08a6af9f4.ts} +2 -1
- package/test/special-self/components/output/SpecialSelf-client.ts +3 -1
- package/test/special-self/components/temp/{SpecialSelf-client-126d3318d9aee9b2e6309c0ae5b91b2e56e9e647.ts → SpecialSelf-client-baf46bd8104e26f37e699a1a0918ea2d8f1a8e8a.ts} +3 -1
- package/test/watch-array/components/output/ArrayAllFunctions-client.ts +4 -1
- package/test/watch-array/components/output/ArrayAllFunctionsUnkeyed-client.ts +3 -1
- package/test/watch-array/components/output/ArrayEmpty-client.ts +4 -1
- package/test/watch-array/components/output/ArrayEntries-client.ts +4 -2
- package/test/watch-array/components/output/ArrayIndexes-client.ts +4 -1
- package/test/watch-array/components/output/ArrayPop-client.ts +4 -1
- package/test/watch-array/components/output/ArrayPush-client.ts +4 -1
- package/test/watch-array/components/output/ArrayReassign-client.ts +4 -1
- package/test/watch-array/components/output/ArrayReverse-client.ts +4 -1
- package/test/watch-array/components/output/ArraySetObject-client.ts +4 -1
- package/test/watch-array/components/output/ArraySetProperty-client.ts +4 -1
- package/test/watch-array/components/output/ArrayShift-client.ts +4 -1
- package/test/watch-array/components/output/ArraySort-client.ts +4 -1
- package/test/watch-array/components/output/ArraySpliceAdd-client.ts +4 -1
- package/test/watch-array/components/output/ArraySpliceDelete-client.ts +4 -1
- package/test/watch-array/components/output/ArraySpliceDeleteAll-client.ts +4 -1
- package/test/watch-array/components/output/ArraySpliceDeleteAndAdd-client.ts +4 -1
- package/test/watch-array/components/output/ArraySpliceDeleteEnd-client.ts +4 -1
- package/test/watch-array/components/output/ArraySwap-client.ts +4 -1
- package/test/watch-array/components/output/ArrayUnshift-client.ts +4 -1
- package/test/watch-array/components/output/ArrayUpdateAssignment-client.ts +4 -1
- package/test/watch-array/components/temp/{ArrayPush-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayAllFunctions-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
- package/test/watch-array/components/temp/{ArrayAllFunctionsUnkeyed-client-9d10d33225715295edde4c036977dfbc57e3fda9.ts → ArrayAllFunctionsUnkeyed-client-f60e58a2cf8361b50f0598aa021576b320716897.ts} +3 -1
- package/test/watch-array/components/temp/{ArrayEmpty-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayEmpty-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
- package/test/watch-array/components/temp/{ArrayEntries-client-ef539f1f3238595af775cdcdf0fe43608e9e9162.ts → ArrayEntries-client-2d9b2fcda6b7706ef82b8d4bb590f5fab77fdcdd.ts} +4 -2
- package/test/watch-array/components/temp/{ArrayIndexes-client-e57339b7f87549f78154ccbaaf1a9b35d5844a5e.ts → ArrayIndexes-client-b30b5caaf0f9a559730dce0ab966da6de84abbc9.ts} +4 -1
- package/test/watch-array/components/temp/{ArrayAllFunctions-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayPop-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
- package/test/watch-array/components/temp/{ArrayPop-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayPush-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
- package/test/watch-array/components/temp/ArrayReassign-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArrayReverse-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySetObject-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySetProperty-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArrayShift-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySort-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySpliceAdd-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySpliceDelete-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySpliceDeleteAll-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySpliceDeleteAndAdd-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySpliceDeleteEnd-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArraySwap-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArrayUnshift-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArrayUpdateAssignment-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
- package/test/watch-array/components/temp/ArrayReassign-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArrayReverse-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySetObject-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySetProperty-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArrayShift-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySort-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySpliceAdd-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySpliceDelete-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySpliceDeleteAll-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySpliceDeleteAndAdd-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySpliceDeleteEnd-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArraySwap-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArrayUnshift-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
- package/test/watch-array/components/temp/ArrayUpdateAssignment-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @torpor/view
|
|
2
2
|
|
|
3
|
+
## 0.4.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ebef5ae: Fix: map head element attributes
|
|
8
|
+
- f4a85c3: Fix: type errors in control statements
|
|
9
|
+
- 986ea9e: Fix: map @html params
|
|
10
|
+
- b2ae05b: Fix: map component attributes => props
|
|
11
|
+
- b8c8122: Fix: assignment assertions in shortcut attributes
|
|
12
|
+
- 4c80139: Fix: map user-supplied $props
|
|
13
|
+
|
|
14
|
+
## 0.4.5
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 39a4b1f: Fix: scoping class attributes with multiple values
|
|
19
|
+
|
|
3
20
|
## 0.4.4
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/compile.cjs
CHANGED
|
@@ -710,11 +710,12 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
710
710
|
let props = [];
|
|
711
711
|
let runs = [];
|
|
712
712
|
let bindingRuns = [];
|
|
713
|
-
for (let { name, value, reactive, fullyReactive } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (name.startsWith("&") && value != null && fullyReactive) {
|
|
713
|
+
for (let { name, value, reactive, fullyReactive, span } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (name.startsWith("&") && value != null && fullyReactive) {
|
|
714
714
|
name = name.substring(1);
|
|
715
715
|
props.push({
|
|
716
716
|
name,
|
|
717
|
-
value
|
|
717
|
+
value,
|
|
718
|
+
span
|
|
718
719
|
});
|
|
719
720
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
720
721
|
bindingRuns.push(`${value} = ${propsName}["${name}"];`);
|
|
@@ -725,7 +726,8 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
725
726
|
value = `t_class(${params.join(", ")})`;
|
|
726
727
|
props.push({
|
|
727
728
|
name,
|
|
728
|
-
value
|
|
729
|
+
value,
|
|
730
|
+
span
|
|
729
731
|
});
|
|
730
732
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
731
733
|
} else if (name === "style" && value != null) {
|
|
@@ -733,20 +735,28 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
733
735
|
value = `t_style(${value})`;
|
|
734
736
|
props.push({
|
|
735
737
|
name,
|
|
736
|
-
value
|
|
738
|
+
value,
|
|
739
|
+
span
|
|
737
740
|
});
|
|
738
741
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
739
742
|
} else if (value != null) {
|
|
740
743
|
props.push({
|
|
741
744
|
name,
|
|
742
|
-
value
|
|
745
|
+
value,
|
|
746
|
+
span
|
|
743
747
|
});
|
|
744
748
|
if (reactive) runs.push(`${propsName}["${name}"] = ${value};`);
|
|
745
749
|
} else props.push({
|
|
746
750
|
name,
|
|
747
|
-
value: "true"
|
|
751
|
+
value: "true",
|
|
752
|
+
span
|
|
748
753
|
});
|
|
749
|
-
b.append(`const ${propsName} = $watch({
|
|
754
|
+
b.append(`const ${propsName} = $watch({`);
|
|
755
|
+
for (let p of props) {
|
|
756
|
+
let value = replaceForVarNames(p.value, status);
|
|
757
|
+
addMappedText(`${p.name}: `, value, ",", p.span, status, b);
|
|
758
|
+
}
|
|
759
|
+
b.append("});");
|
|
750
760
|
if (runs.length) buildRun("setProps", replaceForVarNames(runs.join("\n"), status), status, b);
|
|
751
761
|
if (bindingRuns.length) buildRun("setBindings", replaceForVarNames(bindingRuns.join("\n"), status), status, b);
|
|
752
762
|
if (root) {
|
|
@@ -820,7 +830,7 @@ function trimMatched(text, startChar, endChar) {
|
|
|
820
830
|
//#endregion
|
|
821
831
|
//#region src/compile/build/client/buildAwaitNode.ts
|
|
822
832
|
function buildAwaitNode(node, status, b) {
|
|
823
|
-
const anchorName = node.varName;
|
|
833
|
+
const anchorName = node.varName ?? "null";
|
|
824
834
|
const parentName = node.parentName;
|
|
825
835
|
const regionName = nextVarName("await_region", status);
|
|
826
836
|
const stateName = "$" + nextVarName("await_state", status);
|
|
@@ -900,7 +910,8 @@ function buildAwaitNode(node, status, b) {
|
|
|
900
910
|
}
|
|
901
911
|
function buildAwaitBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
902
912
|
if (node.children.length > 0) {
|
|
903
|
-
|
|
913
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
914
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
904
915
|
buildFragment(node, status, b, parentName, "t_before");
|
|
905
916
|
status.fragmentStack.push({
|
|
906
917
|
fragment: node.fragment,
|
|
@@ -914,22 +925,6 @@ function buildAwaitBranch(node, status, b, parentName, stateName, creatorsName,
|
|
|
914
925
|
b.append(`${stateName}.index = ${index};`);
|
|
915
926
|
}
|
|
916
927
|
|
|
917
|
-
//#endregion
|
|
918
|
-
//#region src/compile/utils/trimEnd.ts
|
|
919
|
-
/**
|
|
920
|
-
* Trims a char from the end of the supplied text
|
|
921
|
-
*
|
|
922
|
-
* @param text The text to trim
|
|
923
|
-
* @param char The char to remove from the end of the text
|
|
924
|
-
*
|
|
925
|
-
* @returns The text without the char on the end
|
|
926
|
-
*/
|
|
927
|
-
function trimEnd(text, char) {
|
|
928
|
-
let end = text.length;
|
|
929
|
-
while (text[end - 1] === char) end -= 1;
|
|
930
|
-
return text.substring(0, end);
|
|
931
|
-
}
|
|
932
|
-
|
|
933
928
|
//#endregion
|
|
934
929
|
//#region src/compile/build/client/buildForNode.ts
|
|
935
930
|
const forLoopRegex = /for\s*\((.+?);.*?;.*?\)/;
|
|
@@ -937,12 +932,12 @@ const forLoopVarsRegex = /(?:let\s+|var\s+){0,1}([^\s,;+=]+)(?:\s*=\s*[^,;]+){0,
|
|
|
937
932
|
const forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
|
|
938
933
|
function buildForNode(node, status, b) {
|
|
939
934
|
const parentName = node.parentName;
|
|
940
|
-
const anchorName = node.varName;
|
|
935
|
+
const anchorName = node.varName ?? "null";
|
|
941
936
|
node = node.children[0];
|
|
942
937
|
const forVarNames = [];
|
|
943
|
-
const
|
|
944
|
-
if (
|
|
945
|
-
const forVarMatches =
|
|
938
|
+
const forLoopMatch = node.statement.match(forLoopRegex);
|
|
939
|
+
if (forLoopMatch) {
|
|
940
|
+
const forVarMatches = forLoopMatch[1].matchAll(forLoopVarsRegex);
|
|
946
941
|
for (let match of forVarMatches) forVarNames.push(match[1]);
|
|
947
942
|
} else {
|
|
948
943
|
const forOfMatch = node.statement.match(forOfRegex);
|
|
@@ -959,9 +954,15 @@ function buildForNode(node, status, b) {
|
|
|
959
954
|
const newItemName = nextVarName("new_item", status);
|
|
960
955
|
const itemName = nextVarName("item", status);
|
|
961
956
|
const beforeName = nextVarName("before", status);
|
|
957
|
+
let keyStatement = "";
|
|
962
958
|
const key = node.children.find((n) => n.type === "control" && n.operation === "@key");
|
|
963
|
-
|
|
964
|
-
|
|
959
|
+
if (key !== void 0) {
|
|
960
|
+
let matches = key.statement.match(/^(\s*@*key\s*=\s*)(.+?)\s*;*\s*$/);
|
|
961
|
+
if (matches) {
|
|
962
|
+
key.span.start += matches[1].length;
|
|
963
|
+
keyStatement = matches[2];
|
|
964
|
+
}
|
|
965
|
+
}
|
|
965
966
|
status.imports.add("t_region");
|
|
966
967
|
status.imports.add("t_run_list");
|
|
967
968
|
status.imports.add("t_list_item");
|
|
@@ -980,10 +981,12 @@ function buildForNode(node, status, b) {
|
|
|
980
981
|
let ${previousItemName} = ${regionName};
|
|
981
982
|
let ${nextItemName} = ${regionName}.nextRegion;`);
|
|
982
983
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
983
|
-
let
|
|
984
|
-
|
|
984
|
+
b.append(`let ${newItemName} = t_list_item(`);
|
|
985
|
+
b.append(`{ ${forVarNames.join(", ")} },`);
|
|
986
|
+
if (key !== void 0) addMappedText("", `${keyStatement || "undefined"}`, ",", key.span, status, b);
|
|
987
|
+
if (status.options.dev === true) b.append(`"for item"`);
|
|
988
|
+
b.append(");");
|
|
985
989
|
b.append(`
|
|
986
|
-
let ${newItemName} = t_list_item(${params.join(", ")});
|
|
987
990
|
${newItemName}.previousRegion = ${previousItemName};
|
|
988
991
|
${previousItemName}.nextRegion = ${newItemName};
|
|
989
992
|
${previousItemName} = ${newItemName};
|
|
@@ -1048,8 +1051,10 @@ function buildHtmlBranch(node, status, b, parentName, regionName) {
|
|
|
1048
1051
|
b.append(`t_run_branch(${regionName}, () => {`);
|
|
1049
1052
|
const templateName = nextVarName("template", status);
|
|
1050
1053
|
const fragmentName = `t_fragment_${node.fragment.number}`;
|
|
1051
|
-
b.append(`
|
|
1052
|
-
|
|
1054
|
+
b.append(`let ${templateName} = document.createElement("template");`);
|
|
1055
|
+
node.span.start += 5;
|
|
1056
|
+
node.span.end -= 2;
|
|
1057
|
+
addMappedText("", `${templateName}.innerHTML = ${replaceForVarNames(node.statement, status)};`, "", node.span, status, b);
|
|
1053
1058
|
b.append(`let ${fragmentName} = ${templateName}.content.cloneNode(true) as DocumentFragment;`);
|
|
1054
1059
|
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1055
1060
|
b.append(`}${status.options.dev === true ? ", \"html\"" : ""});`);
|
|
@@ -1058,7 +1063,7 @@ function buildHtmlBranch(node, status, b, parentName, regionName) {
|
|
|
1058
1063
|
//#endregion
|
|
1059
1064
|
//#region src/compile/build/client/buildIfNode.ts
|
|
1060
1065
|
function buildIfNode(node, status, b) {
|
|
1061
|
-
const anchorName = node.varName;
|
|
1066
|
+
const anchorName = node.varName ?? "null";
|
|
1062
1067
|
const parentName = node.parentName || anchorName + ".parentNode";
|
|
1063
1068
|
const regionName = nextVarName("if_region", status);
|
|
1064
1069
|
const stateName = "$" + nextVarName("if_state", status);
|
|
@@ -1102,7 +1107,8 @@ function buildIfNode(node, status, b) {
|
|
|
1102
1107
|
function buildIfBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
1103
1108
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
1104
1109
|
if (node.children.length > 0) {
|
|
1105
|
-
|
|
1110
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
1111
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
1106
1112
|
buildFragment(node, status, b, parentName, "t_before");
|
|
1107
1113
|
status.fragmentStack.push({
|
|
1108
1114
|
fragment: node.fragment,
|
|
@@ -1164,7 +1170,7 @@ function maybeAppend$1(text, end) {
|
|
|
1164
1170
|
//#endregion
|
|
1165
1171
|
//#region src/compile/build/client/buildSwitchNode.ts
|
|
1166
1172
|
function buildSwitchNode(node, status, b) {
|
|
1167
|
-
const anchorName = node.varName;
|
|
1173
|
+
const anchorName = node.varName ?? "null";
|
|
1168
1174
|
const parentName = node.parentName;
|
|
1169
1175
|
const regionName = nextVarName("switch_region", status);
|
|
1170
1176
|
const stateName = "$" + nextVarName("switch_state", status);
|
|
@@ -1211,7 +1217,8 @@ function buildSwitchNode(node, status, b) {
|
|
|
1211
1217
|
function buildSwitchBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
1212
1218
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
1213
1219
|
if (node.children.length > 0) {
|
|
1214
|
-
|
|
1220
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
1221
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
1215
1222
|
buildFragment(node, status, b, parentName, "t_before");
|
|
1216
1223
|
status.fragmentStack.push({
|
|
1217
1224
|
fragment: node.fragment,
|
|
@@ -1277,6 +1284,22 @@ function buildControlNode(node, status, b) {
|
|
|
1277
1284
|
}
|
|
1278
1285
|
}
|
|
1279
1286
|
|
|
1287
|
+
//#endregion
|
|
1288
|
+
//#region src/compile/utils/trimEnd.ts
|
|
1289
|
+
/**
|
|
1290
|
+
* Trims a char from the end of the supplied text
|
|
1291
|
+
*
|
|
1292
|
+
* @param text The text to trim
|
|
1293
|
+
* @param char The char to remove from the end of the text
|
|
1294
|
+
*
|
|
1295
|
+
* @returns The text without the char on the end
|
|
1296
|
+
*/
|
|
1297
|
+
function trimEnd(text, char) {
|
|
1298
|
+
let end = text.length;
|
|
1299
|
+
while (text[end - 1] === char) end -= 1;
|
|
1300
|
+
return text.substring(0, end);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1280
1303
|
//#endregion
|
|
1281
1304
|
//#region src/compile/build/client/buildMount.ts
|
|
1282
1305
|
function buildMount(functionName, functionBody, status, b) {
|
|
@@ -1372,11 +1395,12 @@ function buildHeadNode(node, status, b) {
|
|
|
1372
1395
|
status.imports.add("$run");
|
|
1373
1396
|
b.append("$run(() => {");
|
|
1374
1397
|
b.append(`
|
|
1375
|
-
const
|
|
1376
|
-
document.getElementsByTagName("head")[0].appendChild(
|
|
1377
|
-
for (let { name, value } of node.attributes) if (value != null) {
|
|
1398
|
+
const t_head_el = document.createElement("${node.tagName}");
|
|
1399
|
+
document.getElementsByTagName("head")[0].appendChild(t_head_el);`);
|
|
1400
|
+
for (let { name, value, span } of node.attributes) if (value != null) {
|
|
1378
1401
|
status.imports.add("t_attribute");
|
|
1379
|
-
|
|
1402
|
+
value = replaceForVarNames(value, status);
|
|
1403
|
+
addMappedText(`t_attribute(t_head_el, "${name}", `, value, ");", span, status, b);
|
|
1380
1404
|
}
|
|
1381
1405
|
b.append(`}${status.options.dev === true ? `, "runHead"` : ""});`);
|
|
1382
1406
|
}
|
|
@@ -1770,14 +1794,14 @@ function buildTemplate(template, map, imports, b, options) {
|
|
|
1770
1794
|
for (let chunk of template.script) if (chunk.script === "/* @params */") {
|
|
1771
1795
|
if (!first) status = makeStatus(imports, map, current, options);
|
|
1772
1796
|
first = false;
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1797
|
+
b.append(`
|
|
1798
|
+
${current.markup ? "$parent" : "_$parent"}: ParentNode,
|
|
1799
|
+
${current.markup ? "$anchor" : "_$anchor"}: Node | null,`);
|
|
1800
|
+
if (current.params !== void 0) addMappedText("", current.params, ",", chunk.span, status, b);
|
|
1801
|
+
else b.append(`${current.props?.length ? "$props: Record<PropertyKey, any>" : "// @ts-ignore\n$props: Record<PropertyKey, any> | undefined"},`);
|
|
1802
|
+
b.append(`
|
|
1803
|
+
${current.contextProps?.length ? "$context" : "// @ts-ignore\n$context"}: Record<PropertyKey, any>,
|
|
1804
|
+
${current.slotProps?.length ? "$slots" : "// @ts-ignore\n$slots"}?: Record<string, SlotRender>`);
|
|
1781
1805
|
} else if (chunk.script === ") /* @return_type */ {") b.append("): void {");
|
|
1782
1806
|
else if (chunk.script === "/* @start */") {
|
|
1783
1807
|
addPushDevBoundary("component", current.name || "Anon Component", status, b);
|
|
@@ -2727,6 +2751,7 @@ function parseAttribute(status) {
|
|
|
2727
2751
|
valueStart++;
|
|
2728
2752
|
valueEnd = valueStart + name.length;
|
|
2729
2753
|
name = value.split(".").at(-1);
|
|
2754
|
+
if (name.endsWith("!")) name = name.substring(0, name.length - 1);
|
|
2730
2755
|
reactive = fullyReactive = true;
|
|
2731
2756
|
}
|
|
2732
2757
|
return {
|
|
@@ -3363,16 +3388,14 @@ function scopeStyles(status) {
|
|
|
3363
3388
|
}
|
|
3364
3389
|
}
|
|
3365
3390
|
function scopeStylesOnNode(node, selectors) {
|
|
3366
|
-
if (isElementNode(node) || isComponentNode(node)) {
|
|
3367
|
-
|
|
3368
|
-
if (
|
|
3369
|
-
if (
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
node.scopeStyles = scopeStyles$1;
|
|
3375
|
-
}
|
|
3391
|
+
if (isElementNode(node) || isComponentNode(node)) node.scopeStyles = selectors.includes(node.tagName) || node.attributes.find((a) => {
|
|
3392
|
+
if (a.name === "class" && a.reactive) return true;
|
|
3393
|
+
else if (a.name === "id" && a.value) {
|
|
3394
|
+
if (selectors.includes(`#${trimQuotes(a.value)}`)) return true;
|
|
3395
|
+
} else if (a.name === "class" && a.value) {
|
|
3396
|
+
for (let classname of trimQuotes(a.value).split(/\s+/)) if (selectors.includes(`.${classname}`)) return true;
|
|
3397
|
+
}
|
|
3398
|
+
}) !== void 0;
|
|
3376
3399
|
if (isParentNode(node)) for (let child of node.children) scopeStylesOnNode(child, selectors);
|
|
3377
3400
|
}
|
|
3378
3401
|
function collectStyleSelectors(block, selectors) {
|
|
@@ -3490,11 +3513,12 @@ function parseComponentStart(status) {
|
|
|
3490
3513
|
status.script.push({
|
|
3491
3514
|
script: "/* @params */",
|
|
3492
3515
|
span: {
|
|
3493
|
-
start
|
|
3494
|
-
end
|
|
3516
|
+
start,
|
|
3517
|
+
end
|
|
3495
3518
|
}
|
|
3496
3519
|
});
|
|
3497
|
-
current.params = status.source.substring(start, end)
|
|
3520
|
+
current.params = status.source.substring(start, end);
|
|
3521
|
+
if (current.params.trim().length === 0) current.params = void 0;
|
|
3498
3522
|
const paramsMatch = current.params?.match(/\$props:\s*([$A-Za-z0-9]+)/);
|
|
3499
3523
|
if (paramsMatch) {
|
|
3500
3524
|
let propsTypeName = paramsMatch[1];
|