@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.
Files changed (125) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/compile.cjs +81 -55
  3. package/dist/compile.cjs.map +1 -1
  4. package/dist/compile.js +81 -55
  5. package/dist/compile.js.map +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/package.json +7 -7
  13. package/src/compile/build/client/buildAwaitNode.ts +3 -2
  14. package/src/compile/build/client/buildCode.ts +14 -11
  15. package/src/compile/build/client/buildComponentNode.ts +15 -13
  16. package/src/compile/build/client/buildElementNode.ts +5 -4
  17. package/src/compile/build/client/buildForNode.ts +22 -12
  18. package/src/compile/build/client/buildHtmlNode.ts +14 -2
  19. package/src/compile/build/client/buildIfNode.ts +3 -2
  20. package/src/compile/build/client/buildSwitchNode.ts +3 -2
  21. package/src/compile/parse/parseCode.ts +5 -2
  22. package/src/compile/parse/parseTag.ts +4 -0
  23. package/src/render/runControl.ts +1 -1
  24. package/test/bind/components/output/BindComponent-client.ts +3 -1
  25. package/test/bind/components/temp/{BindComponent-client-9da323149e29bbb0d7eaf5a86ed541357f1219f8.ts → BindComponent-client-59dbb5565268702ed2935e7e8cc7609b0f956bdc.ts} +3 -1
  26. package/test/child-component/components/output/ChildComponent-client.ts +3 -1
  27. package/test/child-component/components/temp/{ChildComponent-client-6033ce1f59fe1ce3f3dfb3d7845807e7f047b18d.ts → ChildComponent-client-a0ac41e8516d1584b2318770b6a5fc791e07b53b.ts} +3 -1
  28. package/test/class/components/output/Class-client.ts +3 -1
  29. package/test/class/components/temp/{Class-client-a5e3f4dd7b0272d69b856f3ef4aa43b83bc2d849.ts → Class-client-28a59ce1bd5ccd2c6cc48d803216a5346fcf2329.ts} +3 -1
  30. package/test/component/components/output/Component-client.ts +3 -1
  31. package/test/component/components/temp/{Component-client-ff200ee2a7a5f08d0473fddffa1f3ba5eb641d2a.ts → Component-client-475c9724b22ebc18149075860326ffd395c4caa0.ts} +3 -1
  32. package/test/effects/components/output/ForEffect-client.ts +3 -1
  33. package/test/effects/components/temp/{ForEffect-client-b1cff64d6b44a881a4bcf4b1a3dee3fa64c9ec7b.ts → ForEffect-client-841255d13e0691d88345d9ea89c5fb021ca4db02.ts} +3 -1
  34. package/test/for/components/output/For-client.ts +3 -1
  35. package/test/for/components/output/ForAfterFor-client.ts +6 -2
  36. package/test/for/components/output/ForContainingFor-client.ts +6 -2
  37. package/test/for/components/output/ForContainingFunction-client.ts +3 -1
  38. package/test/for/components/output/ForContainingIf-client.ts +3 -1
  39. package/test/for/components/output/ForEscape-client.ts +3 -1
  40. package/test/for/components/output/ForIn-client.ts +3 -1
  41. package/test/for/components/output/ForOf-client.ts +3 -1
  42. package/test/for/components/temp/{For-client-8fd92bf0c26cb8e97006a302104ebb2fdcd2e818.ts → For-client-69c16449ab9b63fd8ace8cb1364105a80e6e1c40.ts} +3 -1
  43. package/test/for/components/temp/{ForAfterFor-client-509955ddc13396ede05c9986a6dcc8bbebd00cf3.ts → ForAfterFor-client-b57ee13c70d8504456dbb5f75efd9defecab8cd1.ts} +6 -2
  44. package/test/for/components/temp/{ForContainingFor-client-4f600c73a6583c84d981a82fae42332f983f0b36.ts → ForContainingFor-client-bc5cc8b51b248bebc28fdba5e69d56af4148a66a.ts} +6 -2
  45. package/test/for/components/temp/{ForContainingFunction-client-9bacc4a7214f2385d98b358d29443363f8b9e78d.ts → ForContainingFunction-client-f29a23d27f5458760406127c58520d6abf924409.ts} +3 -1
  46. package/test/for/components/temp/{ForContainingIf-client-92b3c13b0fbe3d7900c05dd2e833d8e51d1bc66c.ts → ForContainingIf-client-da96adc2e61301142e0728b55665ef241c19f9a4.ts} +3 -1
  47. package/test/for/components/temp/{ForEscape-client-29cdd1ae0528a32f5737295287489e9bbd42889d.ts → ForEscape-client-f2b7590f8e93981bc0cd0c0845ad22df1dc050b6.ts} +3 -1
  48. package/test/for/components/temp/{ForIn-client-fffaa596adb40e4067931af81cc13fc971dd1813.ts → ForIn-client-8754824447479fba5ba3676b5c1dcb1e3591575f.ts} +3 -1
  49. package/test/for/components/temp/{ForOf-client-e6d0948fbd00bfbcbc7099f84331bc3d493abc28.ts → ForOf-client-852d13b24329f89bd864313bc376f73174b9965e.ts} +3 -1
  50. package/test/html/components/output/Html-client.ts +1 -1
  51. package/test/html/components/temp/{Html-client-14bf031fae1c40ea86913ca71aee00b947d88b4d.ts → Html-client-2e1b6cfd24f6114f3e9b0fb0adc0022841c2196b.ts} +1 -1
  52. package/test/if/components/output/IfContainingFor-client.ts +3 -1
  53. package/test/if/components/temp/{IfContainingFor-client-a1246616d908018a77caa27aca6f9fa63e325960.ts → IfContainingFor-client-dc70bb4ae31c2320b4e22f4f26d87d5650667713.ts} +3 -1
  54. package/test/party/components/output/EmitToParent-client.ts +4 -1
  55. package/test/party/components/output/InputSelect-client.ts +3 -1
  56. package/test/party/components/output/Loop-client.ts +4 -1
  57. package/test/party/components/output/Props-client.ts +6 -1
  58. package/test/party/components/temp/{EmitToParent-client-02c78412e4cacc27cbc857d68d5a064474ccc882.ts → EmitToParent-client-3666116e65f3e8d4dbb0782d93f631a855b094ec.ts} +4 -1
  59. package/test/party/components/temp/{InputSelect-client-49f9978ab5f32d13ada9d1c3d7522cbafa4c3cc7.ts → InputSelect-client-6827b541b2a0569745e21823bc3420bdfff746b2.ts} +3 -1
  60. package/test/party/components/temp/{Loop-client-d8be7f7caf99d17b048d915d2dbe1db97c44aecf.ts → Loop-client-79bc3b13d7f6a733694cb5f3ee4b91667ea5c5b5.ts} +4 -1
  61. package/test/party/components/temp/{Props-client-c126fe2030c202b8371f72d8395d0a210a0d67c2.ts → Props-client-7dbf4a9aecc5b1890492db1d30904341bfd0e9eb.ts} +6 -1
  62. package/test/props/components/output/Reactive-client.ts +3 -1
  63. package/test/props/components/temp/{Reactive-client-626575b72eeb6e7eafe7352f0acda1502b0c3d37.ts → Reactive-client-dc9aadcdcb4a950141942769806a1017c9076b20.ts} +3 -1
  64. package/test/slots/components/output/LetSlot-client.ts +6 -2
  65. package/test/slots/components/temp/{LetSlot-client-2cd77fd4f84810a55926f0265a9b780516982d5b.ts → LetSlot-client-328fd8a9fcfc6b68c0380f99d3f09ede33babc2f.ts} +6 -2
  66. package/test/special-component/components/output/SpecialComponent-client.ts +2 -1
  67. package/test/special-component/components/temp/{SpecialComponent-client-1955ef6a59b67e29ea076ed28758625922ff7d7b.ts → SpecialComponent-client-4a9face6c61d943cd94c995b174877f08a6af9f4.ts} +2 -1
  68. package/test/special-self/components/output/SpecialSelf-client.ts +3 -1
  69. package/test/special-self/components/temp/{SpecialSelf-client-126d3318d9aee9b2e6309c0ae5b91b2e56e9e647.ts → SpecialSelf-client-baf46bd8104e26f37e699a1a0918ea2d8f1a8e8a.ts} +3 -1
  70. package/test/watch-array/components/output/ArrayAllFunctions-client.ts +4 -1
  71. package/test/watch-array/components/output/ArrayAllFunctionsUnkeyed-client.ts +3 -1
  72. package/test/watch-array/components/output/ArrayEmpty-client.ts +4 -1
  73. package/test/watch-array/components/output/ArrayEntries-client.ts +4 -2
  74. package/test/watch-array/components/output/ArrayIndexes-client.ts +4 -1
  75. package/test/watch-array/components/output/ArrayPop-client.ts +4 -1
  76. package/test/watch-array/components/output/ArrayPush-client.ts +4 -1
  77. package/test/watch-array/components/output/ArrayReassign-client.ts +4 -1
  78. package/test/watch-array/components/output/ArrayReverse-client.ts +4 -1
  79. package/test/watch-array/components/output/ArraySetObject-client.ts +4 -1
  80. package/test/watch-array/components/output/ArraySetProperty-client.ts +4 -1
  81. package/test/watch-array/components/output/ArrayShift-client.ts +4 -1
  82. package/test/watch-array/components/output/ArraySort-client.ts +4 -1
  83. package/test/watch-array/components/output/ArraySpliceAdd-client.ts +4 -1
  84. package/test/watch-array/components/output/ArraySpliceDelete-client.ts +4 -1
  85. package/test/watch-array/components/output/ArraySpliceDeleteAll-client.ts +4 -1
  86. package/test/watch-array/components/output/ArraySpliceDeleteAndAdd-client.ts +4 -1
  87. package/test/watch-array/components/output/ArraySpliceDeleteEnd-client.ts +4 -1
  88. package/test/watch-array/components/output/ArraySwap-client.ts +4 -1
  89. package/test/watch-array/components/output/ArrayUnshift-client.ts +4 -1
  90. package/test/watch-array/components/output/ArrayUpdateAssignment-client.ts +4 -1
  91. package/test/watch-array/components/temp/{ArrayPush-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayAllFunctions-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
  92. package/test/watch-array/components/temp/{ArrayAllFunctionsUnkeyed-client-9d10d33225715295edde4c036977dfbc57e3fda9.ts → ArrayAllFunctionsUnkeyed-client-f60e58a2cf8361b50f0598aa021576b320716897.ts} +3 -1
  93. package/test/watch-array/components/temp/{ArrayEmpty-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayEmpty-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
  94. package/test/watch-array/components/temp/{ArrayEntries-client-ef539f1f3238595af775cdcdf0fe43608e9e9162.ts → ArrayEntries-client-2d9b2fcda6b7706ef82b8d4bb590f5fab77fdcdd.ts} +4 -2
  95. package/test/watch-array/components/temp/{ArrayIndexes-client-e57339b7f87549f78154ccbaaf1a9b35d5844a5e.ts → ArrayIndexes-client-b30b5caaf0f9a559730dce0ab966da6de84abbc9.ts} +4 -1
  96. package/test/watch-array/components/temp/{ArrayAllFunctions-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayPop-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
  97. package/test/watch-array/components/temp/{ArrayPop-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts → ArrayPush-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts} +4 -1
  98. package/test/watch-array/components/temp/ArrayReassign-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  99. package/test/watch-array/components/temp/ArrayReverse-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  100. package/test/watch-array/components/temp/ArraySetObject-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  101. package/test/watch-array/components/temp/ArraySetProperty-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  102. package/test/watch-array/components/temp/ArrayShift-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  103. package/test/watch-array/components/temp/ArraySort-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  104. package/test/watch-array/components/temp/ArraySpliceAdd-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  105. package/test/watch-array/components/temp/ArraySpliceDelete-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  106. package/test/watch-array/components/temp/ArraySpliceDeleteAll-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  107. package/test/watch-array/components/temp/ArraySpliceDeleteAndAdd-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  108. package/test/watch-array/components/temp/ArraySpliceDeleteEnd-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  109. package/test/watch-array/components/temp/ArraySwap-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  110. package/test/watch-array/components/temp/ArrayUnshift-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  111. package/test/watch-array/components/temp/ArrayUpdateAssignment-client-fcd44b588ebc667ff1e645ac95ea9ce6511dde04.ts +83 -0
  112. package/test/watch-array/components/temp/ArrayReassign-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  113. package/test/watch-array/components/temp/ArrayReverse-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  114. package/test/watch-array/components/temp/ArraySetObject-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  115. package/test/watch-array/components/temp/ArraySetProperty-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  116. package/test/watch-array/components/temp/ArrayShift-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  117. package/test/watch-array/components/temp/ArraySort-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  118. package/test/watch-array/components/temp/ArraySpliceAdd-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  119. package/test/watch-array/components/temp/ArraySpliceDelete-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  120. package/test/watch-array/components/temp/ArraySpliceDeleteAll-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  121. package/test/watch-array/components/temp/ArraySpliceDeleteAndAdd-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  122. package/test/watch-array/components/temp/ArraySpliceDeleteEnd-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  123. package/test/watch-array/components/temp/ArraySwap-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  124. package/test/watch-array/components/temp/ArrayUnshift-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
  125. package/test/watch-array/components/temp/ArrayUpdateAssignment-client-bf2caf578a29ef32ca77f51ec2402c6034c219db.ts +0 -80
@@ -1,3 +1,4 @@
1
+ import type SourceSpan from "../../types/SourceSpan";
1
2
  import type ElementNode from "../../types/nodes/ElementNode";
2
3
  import Builder from "../../utils/Builder";
3
4
  import isSpecialNode from "../../utils/isSpecialNode";
@@ -33,11 +34,11 @@ export default function buildComponentNode(
33
34
  status.imports.add("$watch");
34
35
 
35
36
  // Gather props, runs and binding runs, and set them all at once
36
- let props: { name: string; value: string }[] = [];
37
+ let props: { name: string; value: string; span: SourceSpan }[] = [];
37
38
  let runs: string[] = [];
38
39
  let bindingRuns: string[] = [];
39
40
 
40
- for (let { name, value, reactive, fullyReactive } of node.attributes) {
41
+ for (let { name, value, reactive, fullyReactive, span } of node.attributes) {
41
42
  if (name === "self" && node.tagName === "@component") {
42
43
  // Ignore this special attribute
43
44
  } else if (name.startsWith("&") && value != null && fullyReactive) {
@@ -47,7 +48,7 @@ export default function buildComponentNode(
47
48
  // TODO: Maybe allow adding a Bindable<T> type to the $props interface??
48
49
  // e.g. Component($props: { text: Bindable<string> })
49
50
  name = name.substring(1);
50
- props.push({ name, value });
51
+ props.push({ name, value, span });
51
52
  runs.push(`${propsName}["${name}"] = ${value};`);
52
53
  bindingRuns.push(`${value} = ${propsName}["${name}"];`);
53
54
  } else if (name === "class" && value != null) {
@@ -57,30 +58,31 @@ export default function buildComponentNode(
57
58
  params.push(`"torp-${status.styleHash}"`);
58
59
  }
59
60
  value = `t_class(${params.join(", ")})`;
60
- props.push({ name, value });
61
+ props.push({ name, value, span });
61
62
  runs.push(`${propsName}["${name}"] = ${value};`);
62
63
  } else if (name === "style" && value != null) {
63
64
  status.imports.add("t_style");
64
65
  value = `t_style(${value})`;
65
- props.push({ name, value });
66
+ props.push({ name, value, span });
66
67
  runs.push(`${propsName}["${name}"] = ${value};`);
67
68
  } else if (value != null) {
68
- props.push({ name, value });
69
+ props.push({ name, value, span });
69
70
  if (reactive) {
70
71
  runs.push(`${propsName}["${name}"] = ${value};`);
71
72
  }
72
73
  } else {
73
- props.push({ name, value: "true" });
74
+ props.push({ name, value: "true", span });
74
75
  }
75
76
  }
76
77
 
77
78
  // Set the props, runs and binding runs that we gathered
78
- b.append(
79
- `const ${propsName} = $watch({ ${replaceForVarNames(
80
- props.map((p) => `${p.name}: ${p.value}`).join(", "),
81
- status,
82
- )} });`,
83
- );
79
+ b.append(`const ${propsName} = $watch({`);
80
+ for (let p of props) {
81
+ let value = replaceForVarNames(p.value, status);
82
+ addMappedText(`${p.name}: `, value, ",", p.span, status, b);
83
+ }
84
+ b.append("});");
85
+ // TODO: Map these things:
84
86
  if (runs.length) {
85
87
  buildRun("setProps", replaceForVarNames(runs.join("\n"), status), status, b);
86
88
  }
@@ -144,12 +144,13 @@ function buildHeadNode(node: ElementNode, status: BuildStatus, b: Builder) {
144
144
  // TODO: dedupe e.g. <meta name="x"> or on special key
145
145
  b.append("$run(() => {");
146
146
  b.append(`
147
- const t_headel = document.createElement("${node.tagName}");
148
- document.getElementsByTagName("head")[0].appendChild(t_headel);`);
149
- for (let { name, value } of node.attributes) {
147
+ const t_head_el = document.createElement("${node.tagName}");
148
+ document.getElementsByTagName("head")[0].appendChild(t_head_el);`);
149
+ for (let { name, value, span } of node.attributes) {
150
150
  if (value != null) {
151
151
  status.imports.add("t_attribute");
152
- b.append(`t_attribute(t_headel, "${name}", ${value});`);
152
+ value = replaceForVarNames(value, status);
153
+ addMappedText(`t_attribute(t_head_el, "${name}", `, value, ");", span, status, b);
153
154
  }
154
155
  }
155
156
  b.append(`}${status.options.dev === true ? `, "runHead"` : ""});`);
@@ -1,7 +1,6 @@
1
1
  import type ControlNode from "../../types/nodes/ControlNode";
2
2
  import Builder from "../../utils/Builder";
3
3
  import isControlNode from "../../utils/isControlNode";
4
- import trimEnd from "../../utils/trimEnd";
5
4
  import trimMatched from "../../utils/trimMatched";
6
5
  import nextVarName from "../utils/nextVarName";
7
6
  import type BuildStatus from "./BuildStatus";
@@ -19,7 +18,7 @@ const forOfRegex = /for\s*\(\s*(?:let\s*|var\s*){0,1}(.+?)\s+(?:of|in).*?\)/;
19
18
 
20
19
  export default function buildForNode(node: ControlNode, status: BuildStatus, b: Builder): void {
21
20
  const parentName = node.parentName!;
22
- const anchorName = node.varName!;
21
+ const anchorName = node.varName ?? "null";
23
22
 
24
23
  // HACK:
25
24
  node = node.children[0] as ControlNode;
@@ -27,9 +26,9 @@ export default function buildForNode(node: ControlNode, status: BuildStatus, b:
27
26
  // HACK: Need to wrangle the declaration(s) out of the for loop and put them in data
28
27
  // TODO: Handle destructuring, quotes, comments etc
29
28
  const forVarNames: string[] = [];
30
- const forIndexMatch = node.statement.match(forLoopRegex);
31
- if (forIndexMatch) {
32
- const forVarMatches = forIndexMatch[1].matchAll(forLoopVarsRegex);
29
+ const forLoopMatch = node.statement.match(forLoopRegex);
30
+ if (forLoopMatch) {
31
+ const forVarMatches = forLoopMatch[1].matchAll(forLoopVarsRegex);
33
32
  for (let match of forVarMatches) {
34
33
  forVarNames.push(match[1]);
35
34
  }
@@ -61,12 +60,16 @@ export default function buildForNode(node: ControlNode, status: BuildStatus, b:
61
60
  const beforeName = nextVarName("before", status);
62
61
 
63
62
  // Get the key node if it's been set
63
+ let keyStatement = "";
64
64
  const key = node.children.find(
65
65
  (n) => n.type === "control" && (n as ControlNode).operation === "@key",
66
- );
67
- let keyStatement = key ? (key as ControlNode).statement : "";
68
- if (keyStatement) {
69
- keyStatement = trimEnd(keyStatement.substring(keyStatement.indexOf("=") + 1).trim(), ";");
66
+ ) as ControlNode;
67
+ if (key !== undefined) {
68
+ let matches = key.statement.match(/^(\s*@*key\s*=\s*)(.+?)\s*;*\s*$/);
69
+ if (matches) {
70
+ key.span.start += matches[1].length;
71
+ keyStatement = matches[2];
72
+ }
70
73
  }
71
74
 
72
75
  status.imports.add("t_region");
@@ -91,10 +94,17 @@ export default function buildForNode(node: ControlNode, status: BuildStatus, b:
91
94
  // TODO: replaceForVarNames is going to throw mapping out
92
95
  addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
93
96
 
94
- let params = [`{ ${forVarNames.join(",\n")} }`, keyStatement || "undefined"];
95
- if (status.options.dev === true) params.push(`"for item"`);
97
+ b.append(`let ${newItemName} = t_list_item(`);
98
+ // TODO: Should map these
99
+ b.append(`{ ${forVarNames.join(", ")} },`);
100
+ if (key !== undefined) {
101
+ addMappedText("", `${keyStatement || "undefined"}`, ",", key.span, status, b);
102
+ }
103
+ if (status.options.dev === true) {
104
+ b.append(`"for item"`);
105
+ }
106
+ b.append(");");
96
107
  b.append(`
97
- let ${newItemName} = t_list_item(${params.join(", ")});
98
108
  ${newItemName}.previousRegion = ${previousItemName};
99
109
  ${previousItemName}.nextRegion = ${newItemName};
100
110
  ${previousItemName} = ${newItemName};
@@ -2,7 +2,9 @@ import type ControlNode from "../../types/nodes/ControlNode";
2
2
  import Builder from "../../utils/Builder";
3
3
  import nextVarName from "../utils/nextVarName";
4
4
  import type BuildStatus from "./BuildStatus";
5
+ import addMappedText from "./addMappedText";
5
6
  import buildAddFragment from "./buildAddFragment";
7
+ import replaceForVarNames from "./replaceForVarNames";
6
8
 
7
9
  // TODO: type checking
8
10
 
@@ -43,8 +45,18 @@ function buildHtmlBranch(
43
45
 
44
46
  const templateName = nextVarName("template", status);
45
47
  const fragmentName = `t_fragment_${node.fragment!.number}`;
46
- b.append(`const ${templateName} = document.createElement("template");`);
47
- b.append(`${templateName}.innerHTML = ${node.statement};`);
48
+ b.append(`let ${templateName} = document.createElement("template");`);
49
+ // TODO: replaceForVarNames is going to throw mapping out
50
+ node.span.start += "html(".length;
51
+ node.span.end -= 2;
52
+ addMappedText(
53
+ "",
54
+ `${templateName}.innerHTML = ${replaceForVarNames(node.statement, status)};`,
55
+ "",
56
+ node.span,
57
+ status,
58
+ b,
59
+ );
48
60
  b.append(`let ${fragmentName} = ${templateName}.content.cloneNode(true) as DocumentFragment;`);
49
61
 
50
62
  buildAddFragment(node, status, b, parentName, "t_before");
@@ -14,7 +14,7 @@ import replaceForVarNames from "./replaceForVarNames";
14
14
  // TODO: Are there too many branches for ifs etc?
15
15
 
16
16
  export default function buildIfNode(node: ControlNode, status: BuildStatus, b: Builder): void {
17
- const anchorName = node.varName!;
17
+ const anchorName = node.varName ?? "null";
18
18
  const parentName = node.parentName || anchorName + ".parentNode";
19
19
  const regionName = nextVarName("if_region", status);
20
20
  const stateName = "$" + nextVarName("if_state", status);
@@ -84,7 +84,8 @@ function buildIfBranch(
84
84
  addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
85
85
 
86
86
  if (node.children.length > 0) {
87
- b.append(`${creatorsName}[${index}] = (t_before) => {`);
87
+ let beforeParam = node.fragment !== undefined ? "t_before" : "_";
88
+ b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
88
89
 
89
90
  buildFragment(node, status, b, parentName, "t_before");
90
91
 
@@ -12,7 +12,7 @@ import buildNode from "./buildNode";
12
12
  import replaceForVarNames from "./replaceForVarNames";
13
13
 
14
14
  export default function buildSwitchNode(node: ControlNode, status: BuildStatus, b: Builder): void {
15
- const anchorName = node.varName!;
15
+ const anchorName = node.varName ?? "null";
16
16
  const parentName = node.parentName!;
17
17
  const regionName = nextVarName("switch_region", status);
18
18
  const stateName = "$" + nextVarName("switch_state", status);
@@ -87,7 +87,8 @@ function buildSwitchBranch(
87
87
  addMappedText("", `${replaceForVarNames(node.statement, status)}`, " {", node.span, status, b);
88
88
 
89
89
  if (node.children.length > 0) {
90
- b.append(`${creatorsName}[${index}] = (t_before) => {`);
90
+ let beforeParam = node.fragment !== undefined ? "t_before" : "_";
91
+ b.append(`${creatorsName}[${index}] = (${beforeParam}) => {`);
91
92
 
92
93
  buildFragment(node, status, b, parentName, "t_before");
93
94
 
@@ -171,9 +171,12 @@ function parseComponentStart(status: ParseStatus) {
171
171
  script: status.source.substring(status.marker, start),
172
172
  span: { start: status.marker, end: start },
173
173
  });
174
- status.script.push({ script: "/* @params */", span: { start: 0, end: 0 } });
174
+ status.script.push({ script: "/* @params */", span: { start, end } });
175
175
 
176
- current.params = status.source.substring(start, end).trim() || undefined;
176
+ current.params = status.source.substring(start, end);
177
+ if (current.params.trim().length === 0) {
178
+ current.params = undefined;
179
+ }
177
180
 
178
181
  // Look for a params type or interface
179
182
  // Might need to get fancier with this
@@ -123,6 +123,10 @@ function parseAttribute(status: ParseStatus): Attribute {
123
123
  valueStart++;
124
124
  valueEnd = valueStart + name.length;
125
125
  name = value.split(".").at(-1)!;
126
+ // Handle definite assignment assertions e.g. {$state.width!}
127
+ if (name.endsWith("!")) {
128
+ name = name.substring(0, name.length - 1);
129
+ }
126
130
  reactive = fullyReactive = true;
127
131
  }
128
132
  return {
@@ -5,7 +5,7 @@ import popRegion from "./popRegion";
5
5
  import pushRegion from "./pushRegion";
6
6
 
7
7
  /**
8
- * Runs an`if`, `switch` or `await` control statement
8
+ * Runs an `if`, `switch` or `await` control statement
9
9
  * @param create A function that creates the control statement's branches
10
10
  */
11
11
  export default function runControl(
@@ -33,7 +33,9 @@ export default function BindComponent(
33
33
  let t_comp_anchor_1 = t_anchor(t_next(t_root_0)) as HTMLElement;
34
34
 
35
35
  /* @component */
36
- const t_props_1 = $watch({ name: $state.name });
36
+ const t_props_1 = $watch({
37
+ name: $state.name,
38
+ });
37
39
  $run(() => {
38
40
  t_props_1["name"] = $state.name;
39
41
  });
@@ -33,7 +33,9 @@ export default function BindComponent(
33
33
  let t_comp_anchor_1 = t_anchor(t_next(t_root_0)) as HTMLElement;
34
34
 
35
35
  /* @component */
36
- const t_props_1 = $watch({ name: $state.name });
36
+ const t_props_1 = $watch({
37
+ name: $state.name,
38
+ });
37
39
  $run(() => {
38
40
  t_props_1["name"] = $state.name;
39
41
  });
@@ -30,7 +30,9 @@ export default function ParentChild(
30
30
  let t_comp_anchor_1 = t_anchor(t_next(t_root_0)) as HTMLElement;
31
31
 
32
32
  /* @component */
33
- const t_props_1 = $watch({ name: "Anna" });
33
+ const t_props_1 = $watch({
34
+ name: "Anna",
35
+ });
34
36
  Child(t_fragment_0, t_comp_anchor_1, t_props_1, $context);
35
37
 
36
38
  const t_text_1 = t_next(t_comp_anchor_1, true);
@@ -30,7 +30,9 @@ export default function ParentChild(
30
30
  let t_comp_anchor_1 = t_anchor(t_next(t_root_0)) as HTMLElement;
31
31
 
32
32
  /* @component */
33
- const t_props_1 = $watch({ name: "Anna" });
33
+ const t_props_1 = $watch({
34
+ name: "Anna",
35
+ });
34
36
  Child(t_fragment_0, t_comp_anchor_1, t_props_1, $context);
35
37
 
36
38
  const t_text_1 = t_next(t_comp_anchor_1, true);
@@ -33,7 +33,9 @@ export default function Class(
33
33
  let t_comp_anchor_1 = t_anchor(t_next(t_next(t_div_4, true))) as HTMLElement;
34
34
 
35
35
  /* @component */
36
- const t_props_1 = $watch({ class: t_class({ "child-class": true }, "torp-1ljxz83") });
36
+ const t_props_1 = $watch({
37
+ class: t_class({ "child-class": true }, "torp-1ljxz83"),
38
+ });
37
39
  $run(() => {
38
40
  t_props_1["class"] = t_class({ "child-class": true }, "torp-1ljxz83");
39
41
  });
@@ -33,7 +33,9 @@ export default function Class(
33
33
  let t_comp_anchor_1 = t_anchor(t_next(t_next(t_div_4, true))) as HTMLElement;
34
34
 
35
35
  /* @component */
36
- const t_props_1 = $watch({ class: t_class({ "child-class": true }, "torp-1ljxz83") });
36
+ const t_props_1 = $watch({
37
+ class: t_class({ "child-class": true }, "torp-1ljxz83"),
38
+ });
37
39
  $run(() => {
38
40
  t_props_1["class"] = t_class({ "child-class": true }, "torp-1ljxz83");
39
41
  });
@@ -30,7 +30,9 @@ export default function Component(
30
30
  let t_comp_anchor_1 = t_anchor(t_next(t_root_0)) as HTMLElement;
31
31
 
32
32
  /* @component */
33
- const t_props_1 = $watch({ name: "Amy" });
33
+ const t_props_1 = $watch({
34
+ name: "Amy",
35
+ });
34
36
  Header(t_fragment_0, t_comp_anchor_1, t_props_1, $context);
35
37
 
36
38
  const t_text_1 = t_next(t_comp_anchor_1, true);
@@ -30,7 +30,9 @@ export default function Component(
30
30
  let t_comp_anchor_1 = t_anchor(t_next(t_root_0)) as HTMLElement;
31
31
 
32
32
  /* @component */
33
- const t_props_1 = $watch({ name: "Amy" });
33
+ const t_props_1 = $watch({
34
+ name: "Amy",
35
+ });
34
36
  Header(t_fragment_0, t_comp_anchor_1, t_props_1, $context);
35
37
 
36
38
  const t_text_1 = t_next(t_comp_anchor_1, true);
@@ -44,7 +44,9 @@ export default function For(
44
44
  let t_previous_item_1 = t_for_region_1;
45
45
  let t_next_item_1 = t_for_region_1.nextRegion;
46
46
  for (let item of $props.items) {
47
- let t_new_item_1 = t_list_item({ item }, undefined);
47
+ let t_new_item_1 = t_list_item(
48
+ { item },
49
+ );
48
50
  t_new_item_1.previousRegion = t_previous_item_1;
49
51
  t_previous_item_1.nextRegion = t_new_item_1;
50
52
  t_previous_item_1 = t_new_item_1;
@@ -44,7 +44,9 @@ export default function For(
44
44
  let t_previous_item_1 = t_for_region_1;
45
45
  let t_next_item_1 = t_for_region_1.nextRegion;
46
46
  for (let item of $props.items) {
47
- let t_new_item_1 = t_list_item({ item }, undefined);
47
+ let t_new_item_1 = t_list_item(
48
+ { item },
49
+ );
48
50
  t_new_item_1.previousRegion = t_previous_item_1;
49
51
  t_previous_item_1.nextRegion = t_new_item_1;
50
52
  t_previous_item_1 = t_new_item_1;
@@ -46,7 +46,9 @@ export default function For(
46
46
  let t_previous_item_1 = t_for_region_1;
47
47
  let t_next_item_1 = t_for_region_1.nextRegion;
48
48
  for (let i = 0; i < 5; i++) {
49
- let t_new_item_1 = t_list_item({ i }, undefined);
49
+ let t_new_item_1 = t_list_item(
50
+ { i },
51
+ );
50
52
  t_new_item_1.previousRegion = t_previous_item_1;
51
53
  t_previous_item_1.nextRegion = t_new_item_1;
52
54
  t_previous_item_1 = t_new_item_1;
@@ -46,7 +46,9 @@ export default function ForAfterFor(
46
46
  let t_previous_item_1 = t_for_region_1;
47
47
  let t_next_item_1 = t_for_region_1.nextRegion;
48
48
  for (let i = 0; i < 5; i++) {
49
- let t_new_item_1 = t_list_item({ i }, undefined);
49
+ let t_new_item_1 = t_list_item(
50
+ { i },
51
+ );
50
52
  t_new_item_1.previousRegion = t_previous_item_1;
51
53
  t_previous_item_1.nextRegion = t_new_item_1;
52
54
  t_previous_item_1 = t_new_item_1;
@@ -87,7 +89,9 @@ export default function ForAfterFor(
87
89
  let t_previous_item_2 = t_for_region_2;
88
90
  let t_next_item_2 = t_for_region_2.nextRegion;
89
91
  for (let i = 10; i > 5; i--) {
90
- let t_new_item_2 = t_list_item({ i }, undefined);
92
+ let t_new_item_2 = t_list_item(
93
+ { i },
94
+ );
91
95
  t_new_item_2.previousRegion = t_previous_item_2;
92
96
  t_previous_item_2.nextRegion = t_new_item_2;
93
97
  t_previous_item_2 = t_new_item_2;
@@ -46,7 +46,9 @@ export default function ForContainingFor(
46
46
  let t_previous_item_1 = t_for_region_1;
47
47
  let t_next_item_1 = t_for_region_1.nextRegion;
48
48
  for (let i = 0; i < 5; i++) {
49
- let t_new_item_1 = t_list_item({ i }, undefined);
49
+ let t_new_item_1 = t_list_item(
50
+ { i },
51
+ );
50
52
  t_new_item_1.previousRegion = t_previous_item_1;
51
53
  t_previous_item_1.nextRegion = t_new_item_1;
52
54
  t_previous_item_1 = t_new_item_1;
@@ -72,7 +74,9 @@ export default function ForContainingFor(
72
74
  let t_previous_item_2 = t_for_region_2;
73
75
  let t_next_item_2 = t_for_region_2.nextRegion;
74
76
  for (let j = 0; j < 2; j++) {
75
- let t_new_item_2 = t_list_item({ j }, undefined);
77
+ let t_new_item_2 = t_list_item(
78
+ { j },
79
+ );
76
80
  t_new_item_2.previousRegion = t_previous_item_2;
77
81
  t_previous_item_2.nextRegion = t_new_item_2;
78
82
  t_previous_item_2 = t_new_item_2;
@@ -47,7 +47,9 @@ export default function ForContainingIf(
47
47
  let t_previous_item_1 = t_for_region_1;
48
48
  let t_next_item_1 = t_for_region_1.nextRegion;
49
49
  for (let i = 0; i < 5; i++) {
50
- let t_new_item_1 = t_list_item({ i }, undefined);
50
+ let t_new_item_1 = t_list_item(
51
+ { i },
52
+ );
51
53
  t_new_item_1.previousRegion = t_previous_item_1;
52
54
  t_previous_item_1.nextRegion = t_new_item_1;
53
55
  t_previous_item_1 = t_new_item_1;
@@ -49,7 +49,9 @@ export default function ForContainingIf(
49
49
  let t_previous_item_1 = t_for_region_1;
50
50
  let t_next_item_1 = t_for_region_1.nextRegion;
51
51
  for (let i = 0; i < 5; i++) {
52
- let t_new_item_1 = t_list_item({ i }, undefined);
52
+ let t_new_item_1 = t_list_item(
53
+ { i },
54
+ );
53
55
  t_new_item_1.previousRegion = t_previous_item_1;
54
56
  t_previous_item_1.nextRegion = t_new_item_1;
55
57
  t_previous_item_1 = t_new_item_1;
@@ -50,7 +50,9 @@ export default function ForEscape(
50
50
  let t_previous_item_1 = t_for_region_1;
51
51
  let t_next_item_1 = t_for_region_1.nextRegion;
52
52
  for (let i = 0; i < 5; i++) {
53
- let t_new_item_1 = t_list_item({ i }, undefined);
53
+ let t_new_item_1 = t_list_item(
54
+ { i },
55
+ );
54
56
  t_new_item_1.previousRegion = t_previous_item_1;
55
57
  t_previous_item_1.nextRegion = t_new_item_1;
56
58
  t_previous_item_1 = t_new_item_1;
@@ -45,7 +45,9 @@ export default function ForIn(
45
45
  let t_previous_item_1 = t_for_region_1;
46
46
  let t_next_item_1 = t_for_region_1.nextRegion;
47
47
  for (let key in $props.item) {
48
- let t_new_item_1 = t_list_item({ key }, undefined);
48
+ let t_new_item_1 = t_list_item(
49
+ { key },
50
+ );
49
51
  t_new_item_1.previousRegion = t_previous_item_1;
50
52
  t_previous_item_1.nextRegion = t_new_item_1;
51
53
  t_previous_item_1 = t_new_item_1;
@@ -45,7 +45,9 @@ export default function ForOf(
45
45
  let t_previous_item_1 = t_for_region_1;
46
46
  let t_next_item_1 = t_for_region_1.nextRegion;
47
47
  for (let item of $props.items) {
48
- let t_new_item_1 = t_list_item({ item }, undefined);
48
+ let t_new_item_1 = t_list_item(
49
+ { item },
50
+ );
49
51
  t_new_item_1.previousRegion = t_previous_item_1;
50
52
  t_previous_item_1.nextRegion = t_new_item_1;
51
53
  t_previous_item_1 = t_new_item_1;
@@ -46,7 +46,9 @@ export default function For(
46
46
  let t_previous_item_1 = t_for_region_1;
47
47
  let t_next_item_1 = t_for_region_1.nextRegion;
48
48
  for (let i = 0; i < 5; i++) {
49
- let t_new_item_1 = t_list_item({ i }, undefined);
49
+ let t_new_item_1 = t_list_item(
50
+ { i },
51
+ );
50
52
  t_new_item_1.previousRegion = t_previous_item_1;
51
53
  t_previous_item_1.nextRegion = t_new_item_1;
52
54
  t_previous_item_1 = t_new_item_1;
@@ -46,7 +46,9 @@ export default function ForAfterFor(
46
46
  let t_previous_item_1 = t_for_region_1;
47
47
  let t_next_item_1 = t_for_region_1.nextRegion;
48
48
  for (let i = 0; i < 5; i++) {
49
- let t_new_item_1 = t_list_item({ i }, undefined);
49
+ let t_new_item_1 = t_list_item(
50
+ { i },
51
+ );
50
52
  t_new_item_1.previousRegion = t_previous_item_1;
51
53
  t_previous_item_1.nextRegion = t_new_item_1;
52
54
  t_previous_item_1 = t_new_item_1;
@@ -87,7 +89,9 @@ export default function ForAfterFor(
87
89
  let t_previous_item_2 = t_for_region_2;
88
90
  let t_next_item_2 = t_for_region_2.nextRegion;
89
91
  for (let i = 10; i > 5; i--) {
90
- let t_new_item_2 = t_list_item({ i }, undefined);
92
+ let t_new_item_2 = t_list_item(
93
+ { i },
94
+ );
91
95
  t_new_item_2.previousRegion = t_previous_item_2;
92
96
  t_previous_item_2.nextRegion = t_new_item_2;
93
97
  t_previous_item_2 = t_new_item_2;
@@ -46,7 +46,9 @@ export default function ForContainingFor(
46
46
  let t_previous_item_1 = t_for_region_1;
47
47
  let t_next_item_1 = t_for_region_1.nextRegion;
48
48
  for (let i = 0; i < 5; i++) {
49
- let t_new_item_1 = t_list_item({ i }, undefined);
49
+ let t_new_item_1 = t_list_item(
50
+ { i },
51
+ );
50
52
  t_new_item_1.previousRegion = t_previous_item_1;
51
53
  t_previous_item_1.nextRegion = t_new_item_1;
52
54
  t_previous_item_1 = t_new_item_1;
@@ -72,7 +74,9 @@ export default function ForContainingFor(
72
74
  let t_previous_item_2 = t_for_region_2;
73
75
  let t_next_item_2 = t_for_region_2.nextRegion;
74
76
  for (let j = 0; j < 2; j++) {
75
- let t_new_item_2 = t_list_item({ j }, undefined);
77
+ let t_new_item_2 = t_list_item(
78
+ { j },
79
+ );
76
80
  t_new_item_2.previousRegion = t_previous_item_2;
77
81
  t_previous_item_2.nextRegion = t_new_item_2;
78
82
  t_previous_item_2 = t_new_item_2;
@@ -47,7 +47,9 @@ export default function ForContainingIf(
47
47
  let t_previous_item_1 = t_for_region_1;
48
48
  let t_next_item_1 = t_for_region_1.nextRegion;
49
49
  for (let i = 0; i < 5; i++) {
50
- let t_new_item_1 = t_list_item({ i }, undefined);
50
+ let t_new_item_1 = t_list_item(
51
+ { i },
52
+ );
51
53
  t_new_item_1.previousRegion = t_previous_item_1;
52
54
  t_previous_item_1.nextRegion = t_new_item_1;
53
55
  t_previous_item_1 = t_new_item_1;
@@ -49,7 +49,9 @@ export default function ForContainingIf(
49
49
  let t_previous_item_1 = t_for_region_1;
50
50
  let t_next_item_1 = t_for_region_1.nextRegion;
51
51
  for (let i = 0; i < 5; i++) {
52
- let t_new_item_1 = t_list_item({ i }, undefined);
52
+ let t_new_item_1 = t_list_item(
53
+ { i },
54
+ );
53
55
  t_new_item_1.previousRegion = t_previous_item_1;
54
56
  t_previous_item_1.nextRegion = t_new_item_1;
55
57
  t_previous_item_1 = t_new_item_1;
@@ -50,7 +50,9 @@ export default function ForEscape(
50
50
  let t_previous_item_1 = t_for_region_1;
51
51
  let t_next_item_1 = t_for_region_1.nextRegion;
52
52
  for (let i = 0; i < 5; i++) {
53
- let t_new_item_1 = t_list_item({ i }, undefined);
53
+ let t_new_item_1 = t_list_item(
54
+ { i },
55
+ );
54
56
  t_new_item_1.previousRegion = t_previous_item_1;
55
57
  t_previous_item_1.nextRegion = t_new_item_1;
56
58
  t_previous_item_1 = t_new_item_1;
@@ -45,7 +45,9 @@ export default function ForIn(
45
45
  let t_previous_item_1 = t_for_region_1;
46
46
  let t_next_item_1 = t_for_region_1.nextRegion;
47
47
  for (let key in $props.item) {
48
- let t_new_item_1 = t_list_item({ key }, undefined);
48
+ let t_new_item_1 = t_list_item(
49
+ { key },
50
+ );
49
51
  t_new_item_1.previousRegion = t_previous_item_1;
50
52
  t_previous_item_1.nextRegion = t_new_item_1;
51
53
  t_previous_item_1 = t_new_item_1;
@@ -45,7 +45,9 @@ export default function ForOf(
45
45
  let t_previous_item_1 = t_for_region_1;
46
46
  let t_next_item_1 = t_for_region_1.nextRegion;
47
47
  for (let item of $props.items) {
48
- let t_new_item_1 = t_list_item({ item }, undefined);
48
+ let t_new_item_1 = t_list_item(
49
+ { item },
50
+ );
49
51
  t_new_item_1.previousRegion = t_previous_item_1;
50
52
  t_previous_item_1.nextRegion = t_new_item_1;
51
53
  t_previous_item_1 = t_new_item_1;
@@ -34,7 +34,7 @@ export default function Html(
34
34
  t_run_control(t_html_region_1, t_html_anchor_1, (t_before) => {
35
35
  $props.html;
36
36
  t_run_branch(t_html_region_1, () => {
37
- const t_template_1 = document.createElement("template");
37
+ let t_template_1 = document.createElement("template");
38
38
  t_template_1.innerHTML = $props.html;
39
39
  let t_fragment_1 = t_template_1.content.cloneNode(true) as DocumentFragment;
40
40
  t_add_fragment(t_fragment_1, t_html_parent_1, t_before);