fix(form-compile): companion наследовал DisplayImportance владельца (PowerShell dynamic scope)

Emit-Companion / Emit-CompanionPanel вызывали DI-Attr $el, но $el НЕ их параметр —
PowerShell брал его из родительского скоупа (эмитируемого элемента). Поэтому
авто-генерируемые companion (ExtendedTooltip/ContextMenu/AutoCommandBar с name="@")
наследовали DisplayImportance владельца (CheckBoxField/UsualGroup/Table), которого
в оригинале у них нет → ложный ADDED. Корпус: ExtendedTooltip/ContextMenu НИКОГДА не
несут DisplayImportance, AutoCommandBar — только element-level (11), не companion.

Фикс: DI-Attr от СОБСТВЕННОГО объекта компаньона ($content / $panel), не от ambient
$el. Python не имел dynamic-scope-бага (di_attr на companion не эмитил вовсе), но для
паритета добавлен di_attr(content/panel) — оба рантайма теперь идентичны (companion
без собственного DI → пусто).

Выборка 19 форм (СостоянияОригиналовПервичныхДокументов acc+erp, + формы с
DisplayImportance-владельцами): match 18, ADDED DisplayImportance исчез. ps1==py
байт-в-байт. Регресс 43/43.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-06-13 15:04:33 +03:00
parent e1fb40189c
commit 90d2649a5f
2 changed files with 9 additions and 6 deletions
@@ -1,4 +1,4 @@
# form-compile v1.159 — Compile 1C managed form from JSON or object metadata
# form-compile v1.160 — Compile 1C managed form from JSON or object metadata
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
param(
[string]$JsonPath,
@@ -2606,7 +2606,9 @@ function Emit-Companion {
return
}
$inner = "$indent`t"
X "$indent<$tag name=`"$name`" id=`"$id`"$(DI-Attr $el)>"
# DI-Attr берём от СОБСТВЕННОГО объекта компаньона ($content), НЕ от ambient $el родителя
# (PowerShell dynamic scope — иначе companion наследует DisplayImportance владельца: баг).
X "$indent<$tag name=`"$name`" id=`"$id`"$(DI-Attr $content)>"
if (Test-CompanionStructured $content) {
# структурированная форма (own-content). Порядок как у платформы: own-content (флаги/hyperlink/
# layout/оформление) ПЕРЕД Title (в корпусе layout-first 582 vs 10).
@@ -2649,7 +2651,7 @@ function Emit-CompanionPanel {
X "$indent<$tag name=`"$name`" id=`"$id`"/>"
return
}
X "$indent<$tag name=`"$name`" id=`"$id`"$(DI-Attr $el)>"
X "$indent<$tag name=`"$name`" id=`"$id`"$(DI-Attr $panel)>"
if ($halign) { X "$indent`t<HorizontalAlign>$halign</HorizontalAlign>" }
if ($emitAfFalse) { X "$indent`t<Autofill>false</Autofill>" }
if ($hasChildren) {
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# form-compile v1.159 — Compile 1C managed form from JSON or object metadata
# form-compile v1.160 — Compile 1C managed form from JSON or object metadata
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
import argparse
import copy
@@ -2628,7 +2628,8 @@ def emit_companion(lines, tag, name, indent, content=None):
lines.append(f'{indent}<{tag} name="{name}" id="{cid}"/>')
return
inner = f'{indent}\t'
lines.append(f'{indent}<{tag} name="{name}" id="{cid}">')
# DI-Attr от собственного объекта компаньона (не от владельца) — зеркало ps1
lines.append(f'{indent}<{tag} name="{name}" id="{cid}"{di_attr(content if isinstance(content, dict) else None)}>')
if isinstance(content, dict) and any(k in content for k in COMPANION_STRUCT_KEYS):
# own-content ПЕРЕД Title (в корпусе layout-first 582 vs 10).
emit_common_flags(lines, content, inner)
@@ -2669,7 +2670,7 @@ def emit_companion_panel(lines, tag, name, indent, panel):
if not emit_af_false and not has_children and not halign:
lines.append(f'{indent}<{tag} name="{name}" id="{cid}"/>')
return
lines.append(f'{indent}<{tag} name="{name}" id="{cid}">')
lines.append(f'{indent}<{tag} name="{name}" id="{cid}"{di_attr(panel if isinstance(panel, dict) else None)}>')
if halign:
lines.append(f'{indent}\t<HorizontalAlign>{halign}</HorizontalAlign>')
if emit_af_false: