fix(skd-decompile): сворачивать дефолтные auto selection/order группы в shorthand

После 6781bb3 компилятор кладёт в каждую группу структуры авто-поле выбора и
авто-порядок (SelectedItemAuto/OrderItemAuto), как делает платформа. decompile
сохранял их как selection:["Auto"]/order:["Auto"], из-за чего Try-StructureShorthand
не сворачивал цепочку и выдавал громоздкую объектную модель вместо строки
"A > B > details".

Теперь selection/order, состоящие ровно из одного "Auto" (предикат Is-AutoOnly /
is_auto_only), считаются дефолтом и не мешают свёртке. Round-trip снова bit-perfect:
shorthand перекомпилируется в идентичный XML (Parse-StructureShorthand сам добавляет
эти auto-поля). Отключённый auto ({auto,use}), смешанные списки и явные поля свёртку
не проходят и остаются в объектной форме.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-06-01 16:12:50 +03:00
co-authored by Claude Opus 4.8
parent 3d6a09e90a
commit e03ba3b509
14 changed files with 43 additions and 22 deletions
@@ -1,4 +1,4 @@
# skd-decompile v0.89 — Decompile 1C DCS Template.xml to JSON DSL (draft)
# skd-decompile v0.90 — Decompile 1C DCS Template.xml to JSON DSL (draft)
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
param(
[Parameter(Mandatory)]
@@ -2494,9 +2494,22 @@ function Build-Structure {
return ,$items
}
# True when selection/order is just the single auto element ("Auto") that the
# compiler adds by default to every shorthand group — folding such a group back
# to shorthand is bit-perfect (Parse-StructureShorthand re-adds it on compile).
# Disabled auto ({auto,use}), mixed lists ("Поле","Auto") and explicit fields
# are objects / non-singleton lists and won't match → those keep object form.
function Is-AutoOnly($val) {
if ($null -eq $val) { return $false }
$arr = @($val)
if ($arr.Count -ne 1) { return $false }
return ($arr[0] -is [string]) -and ($arr[0] -eq 'Auto')
}
# Try to fold a structure tree into string shorthand "A > B > details".
# Conditions: linear chain (each level has exactly one child), each level is
# a plain group with single groupField and no local selection/order/filter.
# a plain group with single groupField and no local filter; selection/order are
# allowed only when they are the default single "Auto" element (see Is-AutoOnly).
function Try-StructureShorthand {
param($items)
if ($items.Count -ne 1) { return $null }
@@ -2506,8 +2519,8 @@ function Try-StructureShorthand {
# Disallow extras
if ($cur.Contains('type') -and $cur['type'] -ne 'group') { return $null }
if ($cur.Contains('name')) { return $null }
if ($cur.Contains('selection')) { return $null }
if ($cur.Contains('order')) { return $null }
if ($cur.Contains('selection') -and -not (Is-AutoOnly $cur['selection'])) { return $null }
if ($cur.Contains('order') -and -not (Is-AutoOnly $cur['order'])) { return $null }
if ($cur.Contains('filter')) { return $null }
if ($cur.Contains('viewMode')) { return $null }
if ($cur.Contains('itemsViewMode')) { return $null }
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# skd-decompile v0.89 — Decompile 1C DCS Template.xml to JSON DSL (draft)
# skd-decompile v0.90 — Decompile 1C DCS Template.xml to JSON DSL (draft)
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
import argparse
import os
@@ -2600,6 +2600,17 @@ def build_structure(node, loc):
return items
def is_auto_only(val):
# True when selection/order is just the single auto element ("Auto") that the
# compiler adds by default to every shorthand group — folding such a group back
# to shorthand is bit-perfect (parse re-adds it on compile). Disabled auto
# ({auto,use}), mixed lists and explicit fields won't match → keep object form.
if val is None:
return False
arr = val if isinstance(val, list) else [val]
return len(arr) == 1 and isinstance(arr[0], str) and arr[0] == 'Auto'
def try_structure_shorthand(items):
if len(items) != 1:
return None
@@ -2610,9 +2621,9 @@ def try_structure_shorthand(items):
return None
if 'name' in cur:
return None
if 'selection' in cur:
if 'selection' in cur and not is_auto_only(cur['selection']):
return None
if 'order' in cur:
if 'order' in cur and not is_auto_only(cur['order']):
return None
if 'filter' in cur:
return None