kekekeks / XamlX

General purpose pluggable XAML compiler with no runtime dependencies.
MIT License
319 stars 55 forks source link

Fix target object emit #125

Closed maxkatz6 closed 1 month ago

maxkatz6 commented 1 month ago

Reported multiple times before Fixes: https://github.com/kekekeks/XamlX/issues/7 Fixes: https://github.com/AvaloniaUI/Avalonia/issues/4601 Fixes: internal ticket 242

Old code gen:

public void PopParent()
{
    int idx = _parents.Count - 1;
    _target = _parents[idx]; // keeps reference of the old and already removed parent
    _parents.RemoveAt(idx);
}

New code gen:

public void PopParent()
{
        var idx = _parents.Count - 1;
        _parents.RemoveAt(idx);
        _target = idx != 0 ? _parents[idx - 1] : null;
}