htmv 0.0.33 → 0.0.34

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.
@@ -15,7 +15,7 @@ export function render(node, context) {
15
15
  throw new Error("La lista pasada no es un array");
16
16
  }
17
17
  if (node.type === "interpolation") {
18
- return String(context[node.value]);
18
+ return String(resolvePropertyPath(node.value));
19
19
  }
20
20
  if (node.type === "isset") {
21
21
  if (context[node.itemName] !== undefined &&
@@ -26,4 +26,16 @@ export function render(node, context) {
26
26
  }
27
27
  const output = node.children.map((node) => render(node, context));
28
28
  return output.join("");
29
+ function resolvePropertyPath(path) {
30
+ const [variable, ...properties] = path.split(".");
31
+ if (variable === undefined)
32
+ throw new Error("Missing variable name on interpolation");
33
+ let result = context[variable];
34
+ for (const property of properties) {
35
+ if (typeof result !== "object" || result === null)
36
+ throw new Error("Property access attempt on non-object.");
37
+ result = result[property];
38
+ }
39
+ return result;
40
+ }
29
41
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "htmv",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.33",
5
+ "version": "0.0.34",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "2.3.3",
8
8
  "@types/bun": "latest"
@@ -52,7 +52,7 @@ export function render(node: Node, context: Record<string, unknown>): string {
52
52
  throw new Error("La lista pasada no es un array");
53
53
  }
54
54
  if (node.type === "interpolation") {
55
- return String(context[node.value]);
55
+ return String(resolvePropertyPath(node.value));
56
56
  }
57
57
  if (node.type === "isset") {
58
58
  if (
@@ -65,4 +65,17 @@ export function render(node: Node, context: Record<string, unknown>): string {
65
65
  }
66
66
  const output = node.children.map((node) => render(node, context));
67
67
  return output.join("");
68
+
69
+ function resolvePropertyPath(path: string) {
70
+ const [variable, ...properties] = path.split(".");
71
+ if (variable === undefined)
72
+ throw new Error("Missing variable name on interpolation");
73
+ let result = context[variable];
74
+ for (const property of properties) {
75
+ if (typeof result !== "object" || result === null)
76
+ throw new Error("Property access attempt on non-object.");
77
+ result = (result as Record<string, unknown>)[property];
78
+ }
79
+ return result;
80
+ }
68
81
  }