fix(template-engine): resolve TemplateEngine-015,016 — cascade-rename nested derived templates, correct composed-script ParentPath

This commit is contained in:
Joseph Doherty
2026-05-17 03:18:41 -04:00
parent 0135a6b2a6
commit d6221419c6
5 changed files with 177 additions and 14 deletions
@@ -714,7 +714,7 @@ public class FlatteningService
foreach (var composition in compositions)
ResolveComposedScriptsRecursive(
composition, composition.InstanceName,
composition, composition.InstanceName, parentPath: "",
compositionMap, composedTemplateChains, scripts, scriptCanonicalById,
new HashSet<int>());
}
@@ -723,11 +723,17 @@ public class FlatteningService
/// <summary>
/// Recursively resolves the scripts of a composed module and every module
/// nested inside it, path-qualifying each canonical name with the
/// accumulated <paramref name="prefix"/>.
/// accumulated <paramref name="prefix"/>. <paramref name="parentPath"/> is
/// the path of the enclosing module — empty for a depth-1 composition
/// (parent is the root template) and the enclosing module's
/// <c>prefix</c> for deeper nesting — and is carried into each script's
/// <see cref="ScriptScope"/> so a nested script's <c>Parent.X</c>
/// resolves against its real parent module.
/// </summary>
private static void ResolveComposedScriptsRecursive(
TemplateComposition composition,
string prefix,
string parentPath,
IReadOnlyDictionary<int, IReadOnlyList<TemplateComposition>> compositionMap,
IReadOnlyDictionary<int, IReadOnlyList<Template>> composedTemplateChains,
Dictionary<string, ResolvedScript> scripts,
@@ -747,7 +753,7 @@ public class FlatteningService
{
CanonicalName = canonicalName,
Source = "Composed",
Scope = new Commons.Types.Scripts.ScriptScope(SelfPath: prefix, ParentPath: "")
Scope = new Commons.Types.Scripts.ScriptScope(SelfPath: prefix, ParentPath: parentPath)
};
}
}
@@ -762,7 +768,7 @@ public class FlatteningService
foreach (var nested in nestedCompositions)
ResolveComposedScriptsRecursive(
nested, $"{prefix}.{nested.InstanceName}",
nested, $"{prefix}.{nested.InstanceName}", parentPath: prefix,
compositionMap, composedTemplateChains, scripts, scriptCanonicalById, visited);
}
}