@torpor/view 0.4.5 → 0.4.7
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 +18 -0
- package/dist/compile.cjs +89 -56
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +89 -56
- package/dist/compile.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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/buildFragment.ts +9 -0
- 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/render/addEvent.ts +4 -2
- package/src/render/runControl.ts +1 -1
- package/test/await/components/output/Await-client.ts +1 -1
- package/test/await/components/temp/{Await-client-8ad3f252c4550020753eea3c04cde0da435c6aae.ts → Await-client-1587441666890e0beae15f28451bcd04b90cc597.ts} +1 -1
- package/test/bind/components/output/BindComponent-client.ts +3 -1
- package/test/bind/components/output/BindText-client.ts +1 -1
- package/test/bind/components/temp/{BindComponent-client-9da323149e29bbb0d7eaf5a86ed541357f1219f8.ts → BindComponent-client-59dbb5565268702ed2935e7e8cc7609b0f956bdc.ts} +3 -1
- package/test/bind/components/temp/{BindText-client-eebe53ed8c48b5bbd046621efa6d9b5d3d753f6f.ts → BindText-client-c56c86c514eed2bcbe3f9c1bf23507a98d7d14b1.ts} +1 -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 +4 -2
- package/test/class/components/temp/{Class-client-a5e3f4dd7b0272d69b856f3ef4aa43b83bc2d849.ts → Class-client-d0f120c1171030cbe2862a26bc11965cacdd2b18.ts} +4 -2
- 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/events/components/output/Events-client.ts +2 -2
- package/test/events/components/temp/{Events-client-af611081aa6cb1567461367daf3068df86c6ff23.ts → Events-client-8708dd031fb42b980e47799e6f6c0de7a35ef7ae.ts} +2 -2
- 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 +4 -2
- 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-77ccaeea93b0a489c97113bd6bc522e62b7c914a.ts} +4 -2
- 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/function/components/output/Function-client.ts +1 -1
- package/test/function/components/temp/{Function-client-8ae7f26bcaee6b57251659efc2abcdfd9c0d30e1.ts → Function-client-5173bdb6a5e2eb86060579eb23f70fec20e9b612.ts} +1 -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/output/IfContainingFunction-client.ts +1 -1
- package/test/if/components/temp/{IfContainingFor-client-a1246616d908018a77caa27aca6f9fa63e325960.ts → IfContainingFor-client-dc70bb4ae31c2320b4e22f4f26d87d5650667713.ts} +3 -1
- package/test/if/components/temp/{IfContainingFunction-client-1d8f1ce12f4098b425be18149d9c58ea9c4e8de6.ts → IfContainingFunction-client-56c90b091921645a91d5398739cec4e6d56aa0ed.ts} +1 -1
- package/test/party/components/output/Conditional-client.ts +1 -1
- package/test/party/components/output/Context-client.ts +1 -1
- package/test/party/components/output/EmitToParent-client.ts +6 -3
- package/test/party/components/output/EventClick-client.ts +1 -1
- package/test/party/components/output/InputSelect-client.ts +5 -3
- 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/{Conditional-client-ed1ba6a97d722503560ffbb3dece1d9af5fbadd2.ts → Conditional-client-96ff11fe28ab46048761ff885b8224635244cd38.ts} +1 -1
- package/test/party/components/temp/{Context-client-fd121c4a2766ee5b41caf79f485f5f11142e43e0.ts → Context-client-73383a2149cb9198a5dfebf1e891987d261f399f.ts} +1 -1
- package/test/party/components/temp/{EmitToParent-client-02c78412e4cacc27cbc857d68d5a064474ccc882.ts → EmitToParent-client-1292c44777f86076cd7c4060deb2016b9fb7e4cd.ts} +6 -3
- package/test/party/components/temp/{EventClick-client-4344b8012e6f6310b25c6b43d9f5991dc93037e8.ts → EventClick-client-932a2a4a797aca3cb6b869daa0ba314b46505a73.ts} +1 -1
- package/test/party/components/temp/{InputSelect-client-49f9978ab5f32d13ada9d1c3d7522cbafa4c3cc7.ts → InputSelect-client-fa6d6680ce239722a0c29b754a2adc26dd2b4ab0.ts} +5 -3
- 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 +4 -2
- package/test/props/components/temp/{Reactive-client-626575b72eeb6e7eafe7352f0acda1502b0c3d37.ts → Reactive-client-8601769debe846fc809ca960f0ca4b71762912db.ts} +4 -2
- 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/{ArrayPop-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/{ArrayAllFunctions-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/{ArrayEmpty-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayPop-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
- package/test/watch-array/components/temp/{ArrayPush-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/dist/compile.js
CHANGED
|
@@ -486,7 +486,14 @@ function declareComponentFragmentVars(fragment, node, path, status, b, parentNam
|
|
|
486
486
|
function elementTypeName(node) {
|
|
487
487
|
switch (node.tagName.toLowerCase()) {
|
|
488
488
|
case "div":
|
|
489
|
-
case "
|
|
489
|
+
case "span":
|
|
490
|
+
case "input":
|
|
491
|
+
case "select":
|
|
492
|
+
case "option":
|
|
493
|
+
case "button":
|
|
494
|
+
case "form": return `HTML${node.tagName.substring(0, 1).toUpperCase() + node.tagName.substring(1)}Element`;
|
|
495
|
+
case "a": return "HTMLAnchorElement";
|
|
496
|
+
case "img": return "HTMLImageElement";
|
|
490
497
|
case "textarea": return "HTMLTextAreaElement";
|
|
491
498
|
}
|
|
492
499
|
return "HTMLElement";
|
|
@@ -709,11 +716,12 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
709
716
|
let props = [];
|
|
710
717
|
let runs = [];
|
|
711
718
|
let bindingRuns = [];
|
|
712
|
-
for (let { name, value, reactive, fullyReactive } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (name.startsWith("&") && value != null && fullyReactive) {
|
|
719
|
+
for (let { name, value, reactive, fullyReactive, span } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (name.startsWith("&") && value != null && fullyReactive) {
|
|
713
720
|
name = name.substring(1);
|
|
714
721
|
props.push({
|
|
715
722
|
name,
|
|
716
|
-
value
|
|
723
|
+
value,
|
|
724
|
+
span
|
|
717
725
|
});
|
|
718
726
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
719
727
|
bindingRuns.push(`${value} = ${propsName}["${name}"];`);
|
|
@@ -724,7 +732,8 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
724
732
|
value = `t_class(${params.join(", ")})`;
|
|
725
733
|
props.push({
|
|
726
734
|
name,
|
|
727
|
-
value
|
|
735
|
+
value,
|
|
736
|
+
span
|
|
728
737
|
});
|
|
729
738
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
730
739
|
} else if (name === "style" && value != null) {
|
|
@@ -732,20 +741,28 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
732
741
|
value = `t_style(${value})`;
|
|
733
742
|
props.push({
|
|
734
743
|
name,
|
|
735
|
-
value
|
|
744
|
+
value,
|
|
745
|
+
span
|
|
736
746
|
});
|
|
737
747
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
738
748
|
} else if (value != null) {
|
|
739
749
|
props.push({
|
|
740
750
|
name,
|
|
741
|
-
value
|
|
751
|
+
value,
|
|
752
|
+
span
|
|
742
753
|
});
|
|
743
754
|
if (reactive) runs.push(`${propsName}["${name}"] = ${value};`);
|
|
744
755
|
} else props.push({
|
|
745
756
|
name,
|
|
746
|
-
value: "true"
|
|
757
|
+
value: "true",
|
|
758
|
+
span
|
|
747
759
|
});
|
|
748
|
-
b.append(`const ${propsName} = $watch({
|
|
760
|
+
b.append(`const ${propsName} = $watch({`);
|
|
761
|
+
for (let p of props) {
|
|
762
|
+
let value = replaceForVarNames(p.value, status);
|
|
763
|
+
addMappedText(`${p.name}: `, value, ",", p.span, status, b);
|
|
764
|
+
}
|
|
765
|
+
b.append("});");
|
|
749
766
|
if (runs.length) buildRun("setProps", replaceForVarNames(runs.join("\n"), status), status, b);
|
|
750
767
|
if (bindingRuns.length) buildRun("setBindings", replaceForVarNames(bindingRuns.join("\n"), status), status, b);
|
|
751
768
|
if (root) {
|
|
@@ -819,7 +836,7 @@ function trimMatched(text, startChar, endChar) {
|
|
|
819
836
|
//#endregion
|
|
820
837
|
//#region src/compile/build/client/buildAwaitNode.ts
|
|
821
838
|
function buildAwaitNode(node, status, b) {
|
|
822
|
-
const anchorName = node.varName;
|
|
839
|
+
const anchorName = node.varName ?? "null";
|
|
823
840
|
const parentName = node.parentName;
|
|
824
841
|
const regionName = nextVarName("await_region", status);
|
|
825
842
|
const stateName = "$" + nextVarName("await_state", status);
|
|
@@ -899,7 +916,8 @@ function buildAwaitNode(node, status, b) {
|
|
|
899
916
|
}
|
|
900
917
|
function buildAwaitBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
901
918
|
if (node.children.length > 0) {
|
|
902
|
-
|
|
919
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
920
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
903
921
|
buildFragment(node, status, b, parentName, "t_before");
|
|
904
922
|
status.fragmentStack.push({
|
|
905
923
|
fragment: node.fragment,
|
|
@@ -913,22 +931,6 @@ function buildAwaitBranch(node, status, b, parentName, stateName, creatorsName,
|
|
|
913
931
|
b.append(`${stateName}.index = ${index};`);
|
|
914
932
|
}
|
|
915
933
|
|
|
916
|
-
//#endregion
|
|
917
|
-
//#region src/compile/utils/trimEnd.ts
|
|
918
|
-
/**
|
|
919
|
-
* Trims a char from the end of the supplied text
|
|
920
|
-
*
|
|
921
|
-
* @param text The text to trim
|
|
922
|
-
* @param char The char to remove from the end of the text
|
|
923
|
-
*
|
|
924
|
-
* @returns The text without the char on the end
|
|
925
|
-
*/
|
|
926
|
-
function trimEnd(text, char) {
|
|
927
|
-
let end = text.length;
|
|
928
|
-
while (text[end - 1] === char) end -= 1;
|
|
929
|
-
return text.substring(0, end);
|
|
930
|
-
}
|
|
931
|
-
|
|
932
934
|
//#endregion
|
|
933
935
|
//#region src/compile/build/client/buildForNode.ts
|
|
934
936
|
const forLoopRegex = /for\s*\((.+?);.*?;.*?\)/;
|
|
@@ -936,12 +938,12 @@ const forLoopVarsRegex = /(?:let\s+|var\s+){0,1}([^\s,;+=]+)(?:\s*=\s*[^,;]+){0,
|
|
|
936
938
|
const forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
|
|
937
939
|
function buildForNode(node, status, b) {
|
|
938
940
|
const parentName = node.parentName;
|
|
939
|
-
const anchorName = node.varName;
|
|
941
|
+
const anchorName = node.varName ?? "null";
|
|
940
942
|
node = node.children[0];
|
|
941
943
|
const forVarNames = [];
|
|
942
|
-
const
|
|
943
|
-
if (
|
|
944
|
-
const forVarMatches =
|
|
944
|
+
const forLoopMatch = node.statement.match(forLoopRegex);
|
|
945
|
+
if (forLoopMatch) {
|
|
946
|
+
const forVarMatches = forLoopMatch[1].matchAll(forLoopVarsRegex);
|
|
945
947
|
for (let match of forVarMatches) forVarNames.push(match[1]);
|
|
946
948
|
} else {
|
|
947
949
|
const forOfMatch = node.statement.match(forOfRegex);
|
|
@@ -958,9 +960,15 @@ function buildForNode(node, status, b) {
|
|
|
958
960
|
const newItemName = nextVarName("new_item", status);
|
|
959
961
|
const itemName = nextVarName("item", status);
|
|
960
962
|
const beforeName = nextVarName("before", status);
|
|
963
|
+
let keyStatement = "";
|
|
961
964
|
const key = node.children.find((n) => n.type === "control" && n.operation === "@key");
|
|
962
|
-
|
|
963
|
-
|
|
965
|
+
if (key !== void 0) {
|
|
966
|
+
let matches = key.statement.match(/^(\s*@*key\s*=\s*)(.+?)\s*;*\s*$/);
|
|
967
|
+
if (matches) {
|
|
968
|
+
key.span.start += matches[1].length;
|
|
969
|
+
keyStatement = matches[2];
|
|
970
|
+
}
|
|
971
|
+
}
|
|
964
972
|
status.imports.add("t_region");
|
|
965
973
|
status.imports.add("t_run_list");
|
|
966
974
|
status.imports.add("t_list_item");
|
|
@@ -979,10 +987,12 @@ function buildForNode(node, status, b) {
|
|
|
979
987
|
let ${previousItemName} = ${regionName};
|
|
980
988
|
let ${nextItemName} = ${regionName}.nextRegion;`);
|
|
981
989
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
982
|
-
let
|
|
983
|
-
|
|
990
|
+
b.append(`let ${newItemName} = t_list_item(`);
|
|
991
|
+
b.append(`{ ${forVarNames.join(", ")} },`);
|
|
992
|
+
if (key !== void 0) addMappedText("", `${keyStatement || "undefined"}`, ",", key.span, status, b);
|
|
993
|
+
if (status.options.dev === true) b.append(`"for item"`);
|
|
994
|
+
b.append(");");
|
|
984
995
|
b.append(`
|
|
985
|
-
let ${newItemName} = t_list_item(${params.join(", ")});
|
|
986
996
|
${newItemName}.previousRegion = ${previousItemName};
|
|
987
997
|
${previousItemName}.nextRegion = ${newItemName};
|
|
988
998
|
${previousItemName} = ${newItemName};
|
|
@@ -1047,8 +1057,10 @@ function buildHtmlBranch(node, status, b, parentName, regionName) {
|
|
|
1047
1057
|
b.append(`t_run_branch(${regionName}, () => {`);
|
|
1048
1058
|
const templateName = nextVarName("template", status);
|
|
1049
1059
|
const fragmentName = `t_fragment_${node.fragment.number}`;
|
|
1050
|
-
b.append(`
|
|
1051
|
-
|
|
1060
|
+
b.append(`let ${templateName} = document.createElement("template");`);
|
|
1061
|
+
node.span.start += 5;
|
|
1062
|
+
node.span.end -= 2;
|
|
1063
|
+
addMappedText("", `${templateName}.innerHTML = ${replaceForVarNames(node.statement, status)};`, "", node.span, status, b);
|
|
1052
1064
|
b.append(`let ${fragmentName} = ${templateName}.content.cloneNode(true) as DocumentFragment;`);
|
|
1053
1065
|
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1054
1066
|
b.append(`}${status.options.dev === true ? ", \"html\"" : ""});`);
|
|
@@ -1057,7 +1069,7 @@ function buildHtmlBranch(node, status, b, parentName, regionName) {
|
|
|
1057
1069
|
//#endregion
|
|
1058
1070
|
//#region src/compile/build/client/buildIfNode.ts
|
|
1059
1071
|
function buildIfNode(node, status, b) {
|
|
1060
|
-
const anchorName = node.varName;
|
|
1072
|
+
const anchorName = node.varName ?? "null";
|
|
1061
1073
|
const parentName = node.parentName || anchorName + ".parentNode";
|
|
1062
1074
|
const regionName = nextVarName("if_region", status);
|
|
1063
1075
|
const stateName = "$" + nextVarName("if_state", status);
|
|
@@ -1101,7 +1113,8 @@ function buildIfNode(node, status, b) {
|
|
|
1101
1113
|
function buildIfBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
1102
1114
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
1103
1115
|
if (node.children.length > 0) {
|
|
1104
|
-
|
|
1116
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
1117
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
1105
1118
|
buildFragment(node, status, b, parentName, "t_before");
|
|
1106
1119
|
status.fragmentStack.push({
|
|
1107
1120
|
fragment: node.fragment,
|
|
@@ -1163,7 +1176,7 @@ function maybeAppend$1(text, end) {
|
|
|
1163
1176
|
//#endregion
|
|
1164
1177
|
//#region src/compile/build/client/buildSwitchNode.ts
|
|
1165
1178
|
function buildSwitchNode(node, status, b) {
|
|
1166
|
-
const anchorName = node.varName;
|
|
1179
|
+
const anchorName = node.varName ?? "null";
|
|
1167
1180
|
const parentName = node.parentName;
|
|
1168
1181
|
const regionName = nextVarName("switch_region", status);
|
|
1169
1182
|
const stateName = "$" + nextVarName("switch_state", status);
|
|
@@ -1210,7 +1223,8 @@ function buildSwitchNode(node, status, b) {
|
|
|
1210
1223
|
function buildSwitchBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
1211
1224
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
1212
1225
|
if (node.children.length > 0) {
|
|
1213
|
-
|
|
1226
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
1227
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
1214
1228
|
buildFragment(node, status, b, parentName, "t_before");
|
|
1215
1229
|
status.fragmentStack.push({
|
|
1216
1230
|
fragment: node.fragment,
|
|
@@ -1276,6 +1290,22 @@ function buildControlNode(node, status, b) {
|
|
|
1276
1290
|
}
|
|
1277
1291
|
}
|
|
1278
1292
|
|
|
1293
|
+
//#endregion
|
|
1294
|
+
//#region src/compile/utils/trimEnd.ts
|
|
1295
|
+
/**
|
|
1296
|
+
* Trims a char from the end of the supplied text
|
|
1297
|
+
*
|
|
1298
|
+
* @param text The text to trim
|
|
1299
|
+
* @param char The char to remove from the end of the text
|
|
1300
|
+
*
|
|
1301
|
+
* @returns The text without the char on the end
|
|
1302
|
+
*/
|
|
1303
|
+
function trimEnd(text, char) {
|
|
1304
|
+
let end = text.length;
|
|
1305
|
+
while (text[end - 1] === char) end -= 1;
|
|
1306
|
+
return text.substring(0, end);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1279
1309
|
//#endregion
|
|
1280
1310
|
//#region src/compile/build/client/buildMount.ts
|
|
1281
1311
|
function buildMount(functionName, functionBody, status, b) {
|
|
@@ -1371,11 +1401,12 @@ function buildHeadNode(node, status, b) {
|
|
|
1371
1401
|
status.imports.add("$run");
|
|
1372
1402
|
b.append("$run(() => {");
|
|
1373
1403
|
b.append(`
|
|
1374
|
-
const
|
|
1375
|
-
document.getElementsByTagName("head")[0].appendChild(
|
|
1376
|
-
for (let { name, value } of node.attributes) if (value != null) {
|
|
1404
|
+
const t_head_el = document.createElement("${node.tagName}");
|
|
1405
|
+
document.getElementsByTagName("head")[0].appendChild(t_head_el);`);
|
|
1406
|
+
for (let { name, value, span } of node.attributes) if (value != null) {
|
|
1377
1407
|
status.imports.add("t_attribute");
|
|
1378
|
-
|
|
1408
|
+
value = replaceForVarNames(value, status);
|
|
1409
|
+
addMappedText(`t_attribute(t_head_el, "${name}", `, value, ");", span, status, b);
|
|
1379
1410
|
}
|
|
1380
1411
|
b.append(`}${status.options.dev === true ? `, "runHead"` : ""});`);
|
|
1381
1412
|
}
|
|
@@ -1769,14 +1800,14 @@ function buildTemplate(template, map, imports, b, options) {
|
|
|
1769
1800
|
for (let chunk of template.script) if (chunk.script === "/* @params */") {
|
|
1770
1801
|
if (!first) status = makeStatus(imports, map, current, options);
|
|
1771
1802
|
first = false;
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1803
|
+
b.append(`
|
|
1804
|
+
${current.markup ? "$parent" : "_$parent"}: ParentNode,
|
|
1805
|
+
${current.markup ? "$anchor" : "_$anchor"}: Node | null,`);
|
|
1806
|
+
if (current.params !== void 0) addMappedText("", current.params, ",", chunk.span, status, b);
|
|
1807
|
+
else b.append(`${current.props?.length ? "$props: Record<PropertyKey, any>" : "// @ts-ignore\n$props: Record<PropertyKey, any> | undefined"},`);
|
|
1808
|
+
b.append(`
|
|
1809
|
+
${current.contextProps?.length ? "$context" : "// @ts-ignore\n$context"}: Record<PropertyKey, any>,
|
|
1810
|
+
${current.slotProps?.length ? "$slots" : "// @ts-ignore\n$slots"}?: Record<string, SlotRender>`);
|
|
1780
1811
|
} else if (chunk.script === ") /* @return_type */ {") b.append("): void {");
|
|
1781
1812
|
else if (chunk.script === "/* @start */") {
|
|
1782
1813
|
addPushDevBoundary("component", current.name || "Anon Component", status, b);
|
|
@@ -2726,6 +2757,7 @@ function parseAttribute(status) {
|
|
|
2726
2757
|
valueStart++;
|
|
2727
2758
|
valueEnd = valueStart + name.length;
|
|
2728
2759
|
name = value.split(".").at(-1);
|
|
2760
|
+
if (name.endsWith("!")) name = name.substring(0, name.length - 1);
|
|
2729
2761
|
reactive = fullyReactive = true;
|
|
2730
2762
|
}
|
|
2731
2763
|
return {
|
|
@@ -3487,11 +3519,12 @@ function parseComponentStart(status) {
|
|
|
3487
3519
|
status.script.push({
|
|
3488
3520
|
script: "/* @params */",
|
|
3489
3521
|
span: {
|
|
3490
|
-
start
|
|
3491
|
-
end
|
|
3522
|
+
start,
|
|
3523
|
+
end
|
|
3492
3524
|
}
|
|
3493
3525
|
});
|
|
3494
|
-
current.params = status.source.substring(start, end)
|
|
3526
|
+
current.params = status.source.substring(start, end);
|
|
3527
|
+
if (current.params.trim().length === 0) current.params = void 0;
|
|
3495
3528
|
const paramsMatch = current.params?.match(/\$props:\s*([$A-Za-z0-9]+)/);
|
|
3496
3529
|
if (paramsMatch) {
|
|
3497
3530
|
let propsTypeName = paramsMatch[1];
|