@ztimson/utils 0.28.0 → 0.28.1

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,12 +2297,45 @@ ${opts.message || this.desc}`;
2297
2297
  }
2298
2298
  function findTemplateVars(html) {
2299
2299
  const variables = /* @__PURE__ */ new Set();
2300
+ const excluded = /* @__PURE__ */ new Set(["true", "false", "null", "undefined"]);
2301
+ for (const loop of matchAll(html, /\{\{\s*?\*\s*?(.+?)\s+in\s+(.+?)\s*?}}/g)) {
2302
+ const [element, index = "index"] = loop[1].replaceAll(/[()\s]/g, "").split(",");
2303
+ excluded.add(element);
2304
+ 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);
2308
+ }
2309
+ for (const ifStmt of matchAll(html, /\{\{\s*?[!]?\?\s*?([^}]+?)\s*?}}/g)) {
2310
+ const code = ifStmt[1].replace(/["'`][^"'`]*["'`]/g, "");
2311
+ const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2312
+ for (const v of vars) {
2313
+ 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
+ }
2328
+ }
2329
+ }
2300
2330
  const regex = /\{\{\s*([^<>\*\?!/}\s][^}]*?)\s*}}/g;
2301
2331
  let match;
2302
2332
  while ((match = regex.exec(html)) !== null) {
2303
- const code = match[1].trim();
2304
- const varMatch = code.match(/^([a-zA-Z_$][a-zA-Z0-9_$.]*)/);
2305
- if (varMatch) variables.add(varMatch[1]);
2333
+ const code = match[1].trim().replace(/["'`][^"'`]*["'`]/g, "");
2334
+ const vars = code.match(/[a-zA-Z_$][a-zA-Z0-9_$.]+/g) || [];
2335
+ for (const v of vars) {
2336
+ const root = v.split(".")[0];
2337
+ if (!excluded.has(root)) variables.add(v);
2338
+ }
2306
2339
  }
2307
2340
  const result = {};
2308
2341
  for (const path of variables) {