@torpor/view 0.4.5 → 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 +11 -0
- package/dist/compile.cjs +81 -55
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +81 -55
- 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/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/dist/compile.js
CHANGED
|
@@ -709,11 +709,12 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
709
709
|
let props = [];
|
|
710
710
|
let runs = [];
|
|
711
711
|
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) {
|
|
712
|
+
for (let { name, value, reactive, fullyReactive, span } of node.attributes) if (name === "self" && node.tagName === "@component") {} else if (name.startsWith("&") && value != null && fullyReactive) {
|
|
713
713
|
name = name.substring(1);
|
|
714
714
|
props.push({
|
|
715
715
|
name,
|
|
716
|
-
value
|
|
716
|
+
value,
|
|
717
|
+
span
|
|
717
718
|
});
|
|
718
719
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
719
720
|
bindingRuns.push(`${value} = ${propsName}["${name}"];`);
|
|
@@ -724,7 +725,8 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
724
725
|
value = `t_class(${params.join(", ")})`;
|
|
725
726
|
props.push({
|
|
726
727
|
name,
|
|
727
|
-
value
|
|
728
|
+
value,
|
|
729
|
+
span
|
|
728
730
|
});
|
|
729
731
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
730
732
|
} else if (name === "style" && value != null) {
|
|
@@ -732,20 +734,28 @@ function buildComponentNode(node, status, b, root = false) {
|
|
|
732
734
|
value = `t_style(${value})`;
|
|
733
735
|
props.push({
|
|
734
736
|
name,
|
|
735
|
-
value
|
|
737
|
+
value,
|
|
738
|
+
span
|
|
736
739
|
});
|
|
737
740
|
runs.push(`${propsName}["${name}"] = ${value};`);
|
|
738
741
|
} else if (value != null) {
|
|
739
742
|
props.push({
|
|
740
743
|
name,
|
|
741
|
-
value
|
|
744
|
+
value,
|
|
745
|
+
span
|
|
742
746
|
});
|
|
743
747
|
if (reactive) runs.push(`${propsName}["${name}"] = ${value};`);
|
|
744
748
|
} else props.push({
|
|
745
749
|
name,
|
|
746
|
-
value: "true"
|
|
750
|
+
value: "true",
|
|
751
|
+
span
|
|
747
752
|
});
|
|
748
|
-
b.append(`const ${propsName} = $watch({
|
|
753
|
+
b.append(`const ${propsName} = $watch({`);
|
|
754
|
+
for (let p of props) {
|
|
755
|
+
let value = replaceForVarNames(p.value, status);
|
|
756
|
+
addMappedText(`${p.name}: `, value, ",", p.span, status, b);
|
|
757
|
+
}
|
|
758
|
+
b.append("});");
|
|
749
759
|
if (runs.length) buildRun("setProps", replaceForVarNames(runs.join("\n"), status), status, b);
|
|
750
760
|
if (bindingRuns.length) buildRun("setBindings", replaceForVarNames(bindingRuns.join("\n"), status), status, b);
|
|
751
761
|
if (root) {
|
|
@@ -819,7 +829,7 @@ function trimMatched(text, startChar, endChar) {
|
|
|
819
829
|
//#endregion
|
|
820
830
|
//#region src/compile/build/client/buildAwaitNode.ts
|
|
821
831
|
function buildAwaitNode(node, status, b) {
|
|
822
|
-
const anchorName = node.varName;
|
|
832
|
+
const anchorName = node.varName ?? "null";
|
|
823
833
|
const parentName = node.parentName;
|
|
824
834
|
const regionName = nextVarName("await_region", status);
|
|
825
835
|
const stateName = "$" + nextVarName("await_state", status);
|
|
@@ -899,7 +909,8 @@ function buildAwaitNode(node, status, b) {
|
|
|
899
909
|
}
|
|
900
910
|
function buildAwaitBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
901
911
|
if (node.children.length > 0) {
|
|
902
|
-
|
|
912
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
913
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
903
914
|
buildFragment(node, status, b, parentName, "t_before");
|
|
904
915
|
status.fragmentStack.push({
|
|
905
916
|
fragment: node.fragment,
|
|
@@ -913,22 +924,6 @@ function buildAwaitBranch(node, status, b, parentName, stateName, creatorsName,
|
|
|
913
924
|
b.append(`${stateName}.index = ${index};`);
|
|
914
925
|
}
|
|
915
926
|
|
|
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
927
|
//#endregion
|
|
933
928
|
//#region src/compile/build/client/buildForNode.ts
|
|
934
929
|
const forLoopRegex = /for\s*\((.+?);.*?;.*?\)/;
|
|
@@ -936,12 +931,12 @@ const forLoopVarsRegex = /(?:let\s+|var\s+){0,1}([^\s,;+=]+)(?:\s*=\s*[^,;]+){0,
|
|
|
936
931
|
const forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
|
|
937
932
|
function buildForNode(node, status, b) {
|
|
938
933
|
const parentName = node.parentName;
|
|
939
|
-
const anchorName = node.varName;
|
|
934
|
+
const anchorName = node.varName ?? "null";
|
|
940
935
|
node = node.children[0];
|
|
941
936
|
const forVarNames = [];
|
|
942
|
-
const
|
|
943
|
-
if (
|
|
944
|
-
const forVarMatches =
|
|
937
|
+
const forLoopMatch = node.statement.match(forLoopRegex);
|
|
938
|
+
if (forLoopMatch) {
|
|
939
|
+
const forVarMatches = forLoopMatch[1].matchAll(forLoopVarsRegex);
|
|
945
940
|
for (let match of forVarMatches) forVarNames.push(match[1]);
|
|
946
941
|
} else {
|
|
947
942
|
const forOfMatch = node.statement.match(forOfRegex);
|
|
@@ -958,9 +953,15 @@ function buildForNode(node, status, b) {
|
|
|
958
953
|
const newItemName = nextVarName("new_item", status);
|
|
959
954
|
const itemName = nextVarName("item", status);
|
|
960
955
|
const beforeName = nextVarName("before", status);
|
|
956
|
+
let keyStatement = "";
|
|
961
957
|
const key = node.children.find((n) => n.type === "control" && n.operation === "@key");
|
|
962
|
-
|
|
963
|
-
|
|
958
|
+
if (key !== void 0) {
|
|
959
|
+
let matches = key.statement.match(/^(\s*@*key\s*=\s*)(.+?)\s*;*\s*$/);
|
|
960
|
+
if (matches) {
|
|
961
|
+
key.span.start += matches[1].length;
|
|
962
|
+
keyStatement = matches[2];
|
|
963
|
+
}
|
|
964
|
+
}
|
|
964
965
|
status.imports.add("t_region");
|
|
965
966
|
status.imports.add("t_run_list");
|
|
966
967
|
status.imports.add("t_list_item");
|
|
@@ -979,10 +980,12 @@ function buildForNode(node, status, b) {
|
|
|
979
980
|
let ${previousItemName} = ${regionName};
|
|
980
981
|
let ${nextItemName} = ${regionName}.nextRegion;`);
|
|
981
982
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
982
|
-
let
|
|
983
|
-
|
|
983
|
+
b.append(`let ${newItemName} = t_list_item(`);
|
|
984
|
+
b.append(`{ ${forVarNames.join(", ")} },`);
|
|
985
|
+
if (key !== void 0) addMappedText("", `${keyStatement || "undefined"}`, ",", key.span, status, b);
|
|
986
|
+
if (status.options.dev === true) b.append(`"for item"`);
|
|
987
|
+
b.append(");");
|
|
984
988
|
b.append(`
|
|
985
|
-
let ${newItemName} = t_list_item(${params.join(", ")});
|
|
986
989
|
${newItemName}.previousRegion = ${previousItemName};
|
|
987
990
|
${previousItemName}.nextRegion = ${newItemName};
|
|
988
991
|
${previousItemName} = ${newItemName};
|
|
@@ -1047,8 +1050,10 @@ function buildHtmlBranch(node, status, b, parentName, regionName) {
|
|
|
1047
1050
|
b.append(`t_run_branch(${regionName}, () => {`);
|
|
1048
1051
|
const templateName = nextVarName("template", status);
|
|
1049
1052
|
const fragmentName = `t_fragment_${node.fragment.number}`;
|
|
1050
|
-
b.append(`
|
|
1051
|
-
|
|
1053
|
+
b.append(`let ${templateName} = document.createElement("template");`);
|
|
1054
|
+
node.span.start += 5;
|
|
1055
|
+
node.span.end -= 2;
|
|
1056
|
+
addMappedText("", `${templateName}.innerHTML = ${replaceForVarNames(node.statement, status)};`, "", node.span, status, b);
|
|
1052
1057
|
b.append(`let ${fragmentName} = ${templateName}.content.cloneNode(true) as DocumentFragment;`);
|
|
1053
1058
|
buildAddFragment(node, status, b, parentName, "t_before");
|
|
1054
1059
|
b.append(`}${status.options.dev === true ? ", \"html\"" : ""});`);
|
|
@@ -1057,7 +1062,7 @@ function buildHtmlBranch(node, status, b, parentName, regionName) {
|
|
|
1057
1062
|
//#endregion
|
|
1058
1063
|
//#region src/compile/build/client/buildIfNode.ts
|
|
1059
1064
|
function buildIfNode(node, status, b) {
|
|
1060
|
-
const anchorName = node.varName;
|
|
1065
|
+
const anchorName = node.varName ?? "null";
|
|
1061
1066
|
const parentName = node.parentName || anchorName + ".parentNode";
|
|
1062
1067
|
const regionName = nextVarName("if_region", status);
|
|
1063
1068
|
const stateName = "$" + nextVarName("if_state", status);
|
|
@@ -1101,7 +1106,8 @@ function buildIfNode(node, status, b) {
|
|
|
1101
1106
|
function buildIfBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
1102
1107
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
1103
1108
|
if (node.children.length > 0) {
|
|
1104
|
-
|
|
1109
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
1110
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
1105
1111
|
buildFragment(node, status, b, parentName, "t_before");
|
|
1106
1112
|
status.fragmentStack.push({
|
|
1107
1113
|
fragment: node.fragment,
|
|
@@ -1163,7 +1169,7 @@ function maybeAppend$1(text, end) {
|
|
|
1163
1169
|
//#endregion
|
|
1164
1170
|
//#region src/compile/build/client/buildSwitchNode.ts
|
|
1165
1171
|
function buildSwitchNode(node, status, b) {
|
|
1166
|
-
const anchorName = node.varName;
|
|
1172
|
+
const anchorName = node.varName ?? "null";
|
|
1167
1173
|
const parentName = node.parentName;
|
|
1168
1174
|
const regionName = nextVarName("switch_region", status);
|
|
1169
1175
|
const stateName = "$" + nextVarName("switch_state", status);
|
|
@@ -1210,7 +1216,8 @@ function buildSwitchNode(node, status, b) {
|
|
|
1210
1216
|
function buildSwitchBranch(node, status, b, parentName, stateName, creatorsName, index) {
|
|
1211
1217
|
addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
|
|
1212
1218
|
if (node.children.length > 0) {
|
|
1213
|
-
|
|
1219
|
+
let beforeParam = node.fragment !== void 0 ? "t_before" : "_";
|
|
1220
|
+
b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
|
|
1214
1221
|
buildFragment(node, status, b, parentName, "t_before");
|
|
1215
1222
|
status.fragmentStack.push({
|
|
1216
1223
|
fragment: node.fragment,
|
|
@@ -1276,6 +1283,22 @@ function buildControlNode(node, status, b) {
|
|
|
1276
1283
|
}
|
|
1277
1284
|
}
|
|
1278
1285
|
|
|
1286
|
+
//#endregion
|
|
1287
|
+
//#region src/compile/utils/trimEnd.ts
|
|
1288
|
+
/**
|
|
1289
|
+
* Trims a char from the end of the supplied text
|
|
1290
|
+
*
|
|
1291
|
+
* @param text The text to trim
|
|
1292
|
+
* @param char The char to remove from the end of the text
|
|
1293
|
+
*
|
|
1294
|
+
* @returns The text without the char on the end
|
|
1295
|
+
*/
|
|
1296
|
+
function trimEnd(text, char) {
|
|
1297
|
+
let end = text.length;
|
|
1298
|
+
while (text[end - 1] === char) end -= 1;
|
|
1299
|
+
return text.substring(0, end);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1279
1302
|
//#endregion
|
|
1280
1303
|
//#region src/compile/build/client/buildMount.ts
|
|
1281
1304
|
function buildMount(functionName, functionBody, status, b) {
|
|
@@ -1371,11 +1394,12 @@ function buildHeadNode(node, status, b) {
|
|
|
1371
1394
|
status.imports.add("$run");
|
|
1372
1395
|
b.append("$run(() => {");
|
|
1373
1396
|
b.append(`
|
|
1374
|
-
const
|
|
1375
|
-
document.getElementsByTagName("head")[0].appendChild(
|
|
1376
|
-
for (let { name, value } of node.attributes) if (value != null) {
|
|
1397
|
+
const t_head_el = document.createElement("${node.tagName}");
|
|
1398
|
+
document.getElementsByTagName("head")[0].appendChild(t_head_el);`);
|
|
1399
|
+
for (let { name, value, span } of node.attributes) if (value != null) {
|
|
1377
1400
|
status.imports.add("t_attribute");
|
|
1378
|
-
|
|
1401
|
+
value = replaceForVarNames(value, status);
|
|
1402
|
+
addMappedText(`t_attribute(t_head_el, "${name}", `, value, ");", span, status, b);
|
|
1379
1403
|
}
|
|
1380
1404
|
b.append(`}${status.options.dev === true ? `, "runHead"` : ""});`);
|
|
1381
1405
|
}
|
|
@@ -1769,14 +1793,14 @@ function buildTemplate(template, map, imports, b, options) {
|
|
|
1769
1793
|
for (let chunk of template.script) if (chunk.script === "/* @params */") {
|
|
1770
1794
|
if (!first) status = makeStatus(imports, map, current, options);
|
|
1771
1795
|
first = false;
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1796
|
+
b.append(`
|
|
1797
|
+
${current.markup ? "$parent" : "_$parent"}: ParentNode,
|
|
1798
|
+
${current.markup ? "$anchor" : "_$anchor"}: Node | null,`);
|
|
1799
|
+
if (current.params !== void 0) addMappedText("", current.params, ",", chunk.span, status, b);
|
|
1800
|
+
else b.append(`${current.props?.length ? "$props: Record<PropertyKey, any>" : "// @ts-ignore\n$props: Record<PropertyKey, any> | undefined"},`);
|
|
1801
|
+
b.append(`
|
|
1802
|
+
${current.contextProps?.length ? "$context" : "// @ts-ignore\n$context"}: Record<PropertyKey, any>,
|
|
1803
|
+
${current.slotProps?.length ? "$slots" : "// @ts-ignore\n$slots"}?: Record<string, SlotRender>`);
|
|
1780
1804
|
} else if (chunk.script === ") /* @return_type */ {") b.append("): void {");
|
|
1781
1805
|
else if (chunk.script === "/* @start */") {
|
|
1782
1806
|
addPushDevBoundary("component", current.name || "Anon Component", status, b);
|
|
@@ -2726,6 +2750,7 @@ function parseAttribute(status) {
|
|
|
2726
2750
|
valueStart++;
|
|
2727
2751
|
valueEnd = valueStart + name.length;
|
|
2728
2752
|
name = value.split(".").at(-1);
|
|
2753
|
+
if (name.endsWith("!")) name = name.substring(0, name.length - 1);
|
|
2729
2754
|
reactive = fullyReactive = true;
|
|
2730
2755
|
}
|
|
2731
2756
|
return {
|
|
@@ -3487,11 +3512,12 @@ function parseComponentStart(status) {
|
|
|
3487
3512
|
status.script.push({
|
|
3488
3513
|
script: "/* @params */",
|
|
3489
3514
|
span: {
|
|
3490
|
-
start
|
|
3491
|
-
end
|
|
3515
|
+
start,
|
|
3516
|
+
end
|
|
3492
3517
|
}
|
|
3493
3518
|
});
|
|
3494
|
-
current.params = status.source.substring(start, end)
|
|
3519
|
+
current.params = status.source.substring(start, end);
|
|
3520
|
+
if (current.params.trim().length === 0) current.params = void 0;
|
|
3495
3521
|
const paramsMatch = current.params?.match(/\$props:\s*([$A-Za-z0-9]+)/);
|
|
3496
3522
|
if (paramsMatch) {
|
|
3497
3523
|
let propsTypeName = paramsMatch[1];
|