@ztimson/utils 0.28.1 → 0.28.2

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/dist/index.cjs CHANGED
@@ -2297,41 +2297,40 @@ ${opts.message || this.desc}`;
2297
2297
  }
2298
2298
  function findTemplateVars(html) {
2299
2299
  const variables = /* @__PURE__ */ new Set();
2300
+ const arrays = /* @__PURE__ */ new Set();
2300
2301
  const excluded = /* @__PURE__ */ new Set(["true", "false", "null", "undefined"]);
2301
2302
  for (const loop of matchAll(html, /\{\{\s*?\*\s*?(.+?)\s+in\s+(.+?)\s*?}}/g)) {
2302
2303
  const [element, index = "index"] = loop[1].replaceAll(/[()\s]/g, "").split(",");
2303
2304
  excluded.add(element);
2304
2305
  excluded.add(index);
2305
- const arrayRef = loop[2].trim();
2306
- const arrayVar = arrayRef.split(".")[0].match(/^[a-zA-Z_$][a-zA-Z0-9_$]*/)?.[0];
2307
- if (arrayVar && !excluded.has(arrayVar)) variables.add(arrayVar);
2306
+ const arrayVar = loop[2].trim();
2307
+ const root = arrayVar.split(".")[0];
2308
+ if (!excluded.has(root)) {
2309
+ variables.add(arrayVar);
2310
+ arrays.add(arrayVar);
2311
+ }
2308
2312
  }
2309
2313
  for (const ifStmt of matchAll(html, /\{\{\s*?[!]?\?\s*?([^}]+?)\s*?}}/g)) {
2310
2314
  const code = ifStmt[1].replace(/["'`][^"'`]*["'`]/g, "");
2311
- const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2315
+ const cleaned = code.replace(/([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/g, (_, v) => {
2316
+ const parts = v.split(".");
2317
+ return parts.length > 1 ? parts.slice(0, -1).join(".") + " " : "";
2318
+ });
2319
+ const vars = cleaned.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2312
2320
  for (const v of vars) {
2313
2321
  const root = v.split(".")[0];
2314
- if (!excluded.has(root)) variables.add(root);
2315
- }
2316
- }
2317
- for (const ifBlock of matchAll(html, /\{\{\s*?\?\s*?.+?\s*?}}([\s\S]*?)\{\{\s*?\/\?\s*?}}/g)) {
2318
- const content = ifBlock[1];
2319
- const regex2 = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
2320
- let match2;
2321
- while ((match2 = regex2.exec(content)) !== null) {
2322
- const code = match2[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
2323
- const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2324
- for (const v of vars) {
2325
- const root = v.split(".")[0];
2326
- if (!excluded.has(root)) variables.add(v);
2327
- }
2322
+ if (!excluded.has(root)) variables.add(v);
2328
2323
  }
2329
2324
  }
2330
2325
  const regex = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
2331
2326
  let match;
2332
2327
  while ((match = regex.exec(html)) !== null) {
2333
2328
  const code = match[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
2334
- const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2329
+ const cleaned = code.replace(/([a-zA-Z_$][a-zA-Z0-9_$.]*)\s*\(/g, (_, v) => {
2330
+ const parts = v.split(".");
2331
+ return parts.length > 1 ? parts.slice(0, -1).join(".") + " " : "";
2332
+ });
2333
+ const vars = cleaned.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2335
2334
  for (const v of vars) {
2336
2335
  const root = v.split(".")[0];
2337
2336
  if (!excluded.has(root)) variables.add(v);
@@ -2344,7 +2343,8 @@ ${opts.message || this.desc}`;
2344
2343
  for (let i = 0; i < parts.length; i++) {
2345
2344
  const part = parts[i];
2346
2345
  if (i === parts.length - 1) {
2347
- current[part] = "";
2346
+ const fullPath = parts.slice(0, i + 1).join(".");
2347
+ current[part] = arrays.has(fullPath) ? [] : "";
2348
2348
  } else {
2349
2349
  current[part] = current[part] || {};
2350
2350
  current = current[part];