spooder 6.2.2 → 6.2.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/api.ts +23 -2
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "spooder",
3
3
  "author": "Kruithne <kruithne@gmail.com>",
4
4
  "type": "module",
5
- "version": "6.2.2",
5
+ "version": "6.2.3",
6
6
  "module": "./src/api.ts",
7
7
  "repository": {
8
8
  "url": "https://github.com/Kruithne/spooder"
package/src/api.ts CHANGED
@@ -977,8 +977,29 @@ export async function parse_template(template: string, replacements: Replacement
977
977
  // Parse t-if tags
978
978
  const if_regex = /<t-if\s+test="([^"]+)"\s*>(.*?)<\/t-if>/gs;
979
979
  result = await replace_async(result, if_regex, async (match, condition_key, if_content) => {
980
- const condition_value = is_replacer_fn ? await replacements(condition_key) : replacements[condition_key];
981
- const key_exists = is_replacer_fn || (condition_key in replacements);
980
+ let condition_value;
981
+ let key_exists = false;
982
+
983
+ if (is_replacer_fn) {
984
+ condition_value = await replacements(condition_key);
985
+ key_exists = true;
986
+ } else {
987
+ condition_value = replacements[condition_key];
988
+ key_exists = condition_key in replacements;
989
+
990
+ // try nested property access if direct lookup fails
991
+ if (condition_value === undefined && condition_key.includes('.')) {
992
+ const dot_index = condition_key.indexOf('.');
993
+ const base_key = condition_key.substring(0, dot_index);
994
+ const prop_path = condition_key.substring(dot_index + 1);
995
+ const base_obj = replacements[base_key];
996
+
997
+ if (base_obj !== undefined && typeof base_obj === 'object' && base_obj !== null) {
998
+ condition_value = get_nested_property(base_obj, prop_path);
999
+ key_exists = base_key in replacements;
1000
+ }
1001
+ }
1002
+ }
982
1003
 
983
1004
  // preserve block for later pass if key doesn't exist and drop_missing is false
984
1005
  if (!key_exists && !drop_missing)