htmv 0.0.34 → 0.0.35

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.
@@ -18,8 +18,11 @@ export function render(node, context) {
18
18
  return String(resolvePropertyPath(node.value));
19
19
  }
20
20
  if (node.type === "isset") {
21
- if (context[node.itemName] !== undefined &&
22
- context[node.itemName] !== null) {
21
+ const isNegated = node.itemName.startsWith("!");
22
+ const propName = isNegated ? node.itemName.slice(1) : node.itemName;
23
+ const prop = resolvePropertyPath(propName);
24
+ const exists = isset(prop);
25
+ if (isNegated ? !exists : exists) {
23
26
  return node.children.map((node) => render(node, context)).join("");
24
27
  }
25
28
  return "";
@@ -39,3 +42,9 @@ export function render(node, context) {
39
42
  return result;
40
43
  }
41
44
  }
45
+ function isset(prop) {
46
+ if (Array.isArray(prop)) {
47
+ return prop.length > 0;
48
+ }
49
+ return prop !== undefined && prop !== null && prop !== false;
50
+ }
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.34",
5
+ "version": "0.0.35",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "2.3.3",
8
8
  "@types/bun": "latest"
@@ -55,10 +55,11 @@ export function render(node: Node, context: Record<string, unknown>): string {
55
55
  return String(resolvePropertyPath(node.value));
56
56
  }
57
57
  if (node.type === "isset") {
58
- if (
59
- context[node.itemName] !== undefined &&
60
- context[node.itemName] !== null
61
- ) {
58
+ const isNegated = node.itemName.startsWith("!");
59
+ const propName = isNegated ? node.itemName.slice(1) : node.itemName;
60
+ const prop = resolvePropertyPath(propName);
61
+ const exists = isset(prop);
62
+ if (isNegated ? !exists : exists) {
62
63
  return node.children.map((node) => render(node, context)).join("");
63
64
  }
64
65
  return "";
@@ -79,3 +80,11 @@ export function render(node: Node, context: Record<string, unknown>): string {
79
80
  return result;
80
81
  }
81
82
  }
83
+
84
+ function isset(prop: unknown) {
85
+ if (Array.isArray(prop)) {
86
+ return prop.length > 0;
87
+ }
88
+
89
+ return prop !== undefined && prop !== null && prop !== false;
90
+ }