Skip to content

Commit 1a18bfe

Browse files
authored
Merge pull request #459 from ako/claude/banking-app-feedback-do04dy
Widget describe reads concatenated hide lists; check refuses a container property written as a value
2 parents 337b232 + f0488ce commit 1a18bfe

8 files changed

Lines changed: 565 additions & 23 deletions

File tree

‎.claude/skills/fix-issue/findings/mdl-executor.jsonl‎

Lines changed: 3 additions & 0 deletions
Large diffs are not rendered by default.

‎.claude/skills/mendix/custom-widgets/SKILL.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ vanished from storage, while the multi-key shape died as `missing ')' at ','`.
7171
The error now names the container keyword and rewrites your entry into the form
7272
that works.
7373

74+
The same rule covers the two spellings that carry no entry to key on
75+
(`mendixlabs/mxcli#1056`):
76+
77+
```sql
78+
selectionhelper sh (renderStyle: 'custom', customAllSelected: []) -- MDL-WIDGET27
79+
selectionhelper sh (renderStyle: 'custom', customAllSelected: 'something') -- MDL-WIDGET27
80+
```
81+
82+
A **widgets**-typed property such as `customAllSelected` holds child widgets, so
83+
it is written as a block with widgets in it rather than entries:
84+
85+
```sql
86+
selectionhelper sh (renderStyle: 'custom') {
87+
customallselected s1 { dynamictext d1 (Content: 'All') }
88+
}
89+
```
90+
91+
The empty form is reported from its shape, with no project needed. The scalar
92+
form is reported only when the widget resolves, because without a definition
93+
`p: 'x'` is the ordinary property form and flagging it would be a guess. Both
94+
matter because a required slot left empty is not a silent no-op at build time —
95+
it is `CE0642 "Property '…' is required."`, one per slot.
96+
7497
`describe widget <name> -p <project.mpr>` lists a widget's container keywords
7598
under **Body containers**, and — for an object list — the widgets-typed **slots
7699
inside one item**, with the widget types that route into each:

‎docs-site/src/reference/query/describe-widget.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ widget hides under the configuration the example picked is left out, so what you
103103
see is what that configuration actually supports. The footer reports how many of
104104
the widget's hide-rules were recognised; an unrecognised rule never prunes.
105105

106+
The count is of **hide-calls whose condition was read**, which is not the same
107+
as every property being accounted for. A widget editor often builds one call's
108+
property list by concatenating shared arrays onto a literal one — Combo box
109+
hides ten database properties that way in a single call. Those are resolved, so
110+
the rules appear; but where the concatenated argument is computed at runtime
111+
(`.concat(n(b.static))`) it cannot be resolved statically, and only the literal
112+
names are reported. Nothing is guessed: an unresolvable list contributes its
113+
literal members and no more.
114+
106115
A rule can carry several conditions, joined with `and`:
107116

108117
```
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- mendixlabs/mxcli#1056 — a container-typed widget property written as a VALUE.
2+
--
3+
-- This file is expected to FAIL `mxcli check` (.fail.mdl). Every statement below
4+
-- is a spelling that used to pass check, exec successfully, and write nothing.
5+
--
6+
-- The reporter arrived here because the slot syntax their own generated widget
7+
-- docs showed was rejected by the parser. That half is fixed — the grammar takes
8+
-- generic container names since bca5466e, so `customallselected s1 { … }` now
9+
-- parses, execs, and produces the same five CustomWidgets$WidgetProperty entries
10+
-- Studio Pro writes. What remained was that the WRONG spelling stayed silent:
11+
--
12+
-- customAllSelected: [] -> check clean, exec "Created page", 0 properties
13+
-- written, then 3x CE0642 at build time because
14+
-- the slot is required.
15+
--
16+
-- #999 fixed the `[(k: v)]` shape. It keyed on there being at least one
17+
-- parenthesised entry, so the empty and scalar forms fell through the same hole.
18+
--
19+
-- Expected: MDL-WIDGET27 (error) on each of the three widgets below.
20+
21+
-- 1. Empty list on a widgets-typed CHILD SLOT — the reporter's exact form.
22+
create or replace page BugTest1056.EmptySlot (Title: 'Empty slot', Layout: Atlas_Core.Atlas_Default) {
23+
pluggablewidget 'com.mendix.widget.web.selectionhelper.SelectionHelper' sh1 (
24+
renderStyle: 'custom',
25+
customAllSelected: []
26+
)
27+
}
28+
29+
-- 2. Empty list on an OBJECT LIST. Same hole, reached from the #999 side.
30+
create or replace page BugTest1056.EmptyList (Title: 'Empty list', Layout: Atlas_Core.Atlas_Default) {
31+
htmlelement frame1 (tagName: 'div', attributes: [])
32+
}
33+
34+
-- 3. A scalar on a child slot. No value in a property list can reach a property
35+
-- that holds child widgets; this one is only knowable from the definition, so it
36+
-- is reported when the widget resolves and stays silent without a project.
37+
create or replace page BugTest1056.ScalarSlot (Title: 'Scalar slot', Layout: Atlas_Core.Atlas_Default) {
38+
pluggablewidget 'com.mendix.widget.web.selectionhelper.SelectionHelper' sh2 (
39+
renderStyle: 'custom',
40+
customAllSelected: 'something'
41+
)
42+
}

‎mdl/executor/editorconfig_extract.go‎

Lines changed: 130 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func extractVisibilityRulesFromJS(js string) ([]types.WidgetVisibilityRule, edit
138138
var stats editorConfigExtractStats
139139
var pending []ternaryThenCandidate // resolved after the loop
140140
seen := map[string]bool{} // dedupe propertyKey+condition
141+
consts := stringArrayConsts(js) // module-level arrays, for `[…].concat(N)`
141142

142143
for _, loc := range hideCallRE.FindAllStringIndex(js, -1) {
143144
stats.TotalHideCalls++
@@ -147,7 +148,7 @@ func extractVisibilityRulesFromJS(js string) ([]types.WidgetVisibilityRule, edit
147148
stats.SkippedComplex++
148149
continue
149150
}
150-
listKey, keys, condKeys, ok := hideTargetKeys(args)
151+
listKey, keys, condKeys, ok := hideTargetKeys(args, consts)
151152
if !ok || (len(keys) == 0 && len(condKeys) == 0) {
152153
stats.SkippedComplex++
153154
continue
@@ -387,15 +388,28 @@ func negate(c types.WidgetVisibilityCondition) (types.WidgetVisibilityCondition,
387388
//
388389
// ok is false for a shape it does not recognize; the caller counts it as skipped
389390
// and emits no rule, which degrades to "not hidden".
390-
func hideTargetKeys(args string) (listKey string, keys []string, condKeys []ternaryKey, ok bool) {
391+
func hideTargetKeys(args string, consts map[string][]string) (listKey string, keys []string, condKeys []ternaryKey, ok bool) {
391392
parts := splitTopLevelCommas(args)
392393
// Collect string-literal positional args and any array literal.
393394
var stringArgs []string
394395
var arrayKeys []string
395396
for _, p := range parts {
396397
p = strings.TrimSpace(p)
397398
if strings.HasPrefix(p, "[") {
398-
for _, el := range splitTopLevelCommas(strings.TrimSuffix(strings.TrimPrefix(strings.TrimSpace(p), "["), "]")) {
399+
// The argument may be `[…].concat(N, W)`, so read the literal with a
400+
// balanced scan and resolve the concatenated arrays separately —
401+
// trimming a trailing "]" would stop at the first element and drop
402+
// everything after it.
403+
body, bodyOK := balancedArgs(p, 1)
404+
if !bodyOK {
405+
body = strings.TrimSuffix(strings.TrimPrefix(p, "["), "]")
406+
}
407+
if bodyOK {
408+
if extra, extraOK := concatMembers(p[len(body)+2:], consts); extraOK {
409+
arrayKeys = append(arrayKeys, extra...)
410+
}
411+
}
412+
for _, el := range splitTopLevelCommas(body) {
399413
if tk, ok := ternaryElement(el); ok {
400414
// `cond ? "a" : "b"` as an array ELEMENT. Harvesting its string
401415
// literals would invent a key from the comparison value and mark
@@ -433,6 +447,119 @@ func hideTargetKeys(args string) (listKey string, keys []string, condKeys []tern
433447
}
434448
}
435449

450+
// arrayDeclRE finds a module-level array binding — `z=["lazyLoading",…]` in the
451+
// minified bundle. Combo box's biggest hide lists are built by concatenating
452+
// three such arrays onto a literal one, so without resolving them the call is
453+
// counted as recognized while most of its properties are silently dropped.
454+
var arrayDeclRE = regexp.MustCompile(`(?:^|[,;({=\s])([A-Za-z_$][\w$]*)\s*=\s*\[`)
455+
456+
// concatCallRE matches the `.concat(` that follows a hide call's array argument.
457+
var concatCallRE = regexp.MustCompile(`^\s*\.concat\(`)
458+
459+
// stringArrayConsts maps each identifier bound to an array of STRING LITERALS to
460+
// its members. An identifier bound more than once is dropped rather than
461+
// guessed at: the minifier reuses short names across scopes, and resolving one
462+
// to the wrong array would invent hide rules for properties the editor shows.
463+
// Arrays holding anything but string literals (an element list, a data URI
464+
// built by a call) are skipped for the same reason.
465+
func stringArrayConsts(js string) map[string][]string {
466+
out := map[string][]string{}
467+
ambiguous := map[string]bool{}
468+
for _, loc := range arrayDeclRE.FindAllStringSubmatchIndex(js, -1) {
469+
name := js[loc[2]:loc[3]]
470+
if ambiguous[name] {
471+
continue
472+
}
473+
body, ok := balancedArgs(js, loc[1]) // loc[1] is just past the '['
474+
if !ok {
475+
continue
476+
}
477+
members, ok := stringArrayMembers(body)
478+
if !ok {
479+
continue
480+
}
481+
if prev, seen := out[name]; seen && !sameStrings(prev, members) {
482+
delete(out, name)
483+
ambiguous[name] = true
484+
continue
485+
}
486+
out[name] = members
487+
}
488+
return out
489+
}
490+
491+
// stringArrayMembers reads an array literal's body as a list of string literals.
492+
// ok is false if ANY element is something else — a partial read would drop
493+
// members without saying so, which is the defect this exists to fix.
494+
func stringArrayMembers(body string) ([]string, bool) {
495+
if strings.TrimSpace(body) == "" {
496+
return nil, false
497+
}
498+
var out []string
499+
for _, el := range splitTopLevelCommas(body) {
500+
el = strings.TrimSpace(el)
501+
m := stringLitRE.FindStringSubmatch(el)
502+
if m == nil || !strings.HasPrefix(el, `"`) || len(m[0]) != len(el) {
503+
return nil, false
504+
}
505+
out = append(out, m[1])
506+
}
507+
return out, true
508+
}
509+
510+
func sameStrings(a, b []string) bool {
511+
if len(a) != len(b) {
512+
return false
513+
}
514+
for i := range a {
515+
if a[i] != b[i] {
516+
return false
517+
}
518+
}
519+
return true
520+
}
521+
522+
// concatMembers reads the `.concat(a, b)` chain trailing an array literal and
523+
// returns the members its arguments contribute. Each argument must be either an
524+
// inline string array or an identifier in consts; anything else (a call such as
525+
// `.concat(i(a))`) yields ok=false, and the caller keeps the literal keys alone
526+
// rather than emitting a list it knows to be short.
527+
func concatMembers(tail string, consts map[string][]string) ([]string, bool) {
528+
var out []string
529+
for {
530+
m := concatCallRE.FindStringIndex(tail)
531+
if m == nil {
532+
return out, true
533+
}
534+
args, ok := balancedArgs(tail, m[1])
535+
if !ok {
536+
return out, false
537+
}
538+
for _, a := range splitTopLevelCommas(args) {
539+
a = strings.TrimSpace(a)
540+
switch {
541+
case strings.HasPrefix(a, "["):
542+
body, ok := balancedArgs(a, 1)
543+
if !ok {
544+
return out, false
545+
}
546+
members, ok := stringArrayMembers(body)
547+
if !ok {
548+
return out, false
549+
}
550+
out = append(out, members...)
551+
default:
552+
members, ok := consts[a]
553+
if !ok {
554+
return out, false
555+
}
556+
out = append(out, members...)
557+
}
558+
}
559+
tail = tail[m[1]+len(args)+1:] // past the closing ')', for a chained .concat
560+
}
561+
}
562+
436563
// ternaryKey is an array element of the form `cond ? "a" : "b"` — a hide whose
437564
// TARGET depends on a condition, rather than the whole call being guarded. Each
438565
// branch becomes its own rule carrying that condition (the then-branch when the

‎mdl/executor/editorconfig_shapes_test.go‎

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,112 @@ func TestChainedTernaryBranchConditionIsLifted(t *testing.T) {
382382
}
383383
}
384384
}
385+
386+
func TestConcatenatedHideListsAreResolved(t *testing.T) {
387+
js, err := mpk.ReadEditorConfig(
388+
"../../testdata/expr-checker/widgets/com.mendix.widget.web.Combobox.mpk",
389+
"com.mendix.widget.web.combobox.Combobox")
390+
if err != nil || js == "" {
391+
t.Fatalf("read Combo box editorConfig: %v", err)
392+
}
393+
rules, _ := extractVisibilityRulesFromJS(js)
394+
395+
// Combo box builds its biggest hide lists by concatenating module-level
396+
// arrays onto the literal one:
397+
//
398+
// "context" === t.source && hidePropertiesIn(e, t, [ …3 literals… ].concat(N))
399+
//
400+
// where N is ten database properties. Reading only the literal array counts
401+
// the call as recognized and silently drops the rest, so the describe output
402+
// says nothing about them — and the generated example then offers properties
403+
// the editor does not show.
404+
want := []struct {
405+
prop, guard string
406+
}{
407+
// …].concat(N) under `"context" === t.source`
408+
{"optionsSourceDatabaseDataSource", "source"},
409+
{"optionsSourceDatabaseItemSelection", "source"},
410+
{"onChangeDatabaseEvent", "source"},
411+
{"optionsSourceDatabaseCaptionType", "source"},
412+
{"databaseAttributeString", "source"},
413+
// …].concat(W, z) under `["enumeration","boolean"].includes(optionsSourceType)`
414+
{"attributeAssociation", "optionsSourceType"},
415+
{"optionsSourceAssociationDataSource", "optionsSourceType"},
416+
{"lazyLoading", "optionsSourceType"},
417+
}
418+
for _, w := range want {
419+
var found bool
420+
for _, r := range rules {
421+
if r.PropertyKey != w.prop {
422+
continue
423+
}
424+
for _, c := range r.Conditions() {
425+
if c.PropertyKey == w.guard {
426+
found = true
427+
}
428+
}
429+
}
430+
if !found {
431+
t.Errorf("no rule lifted for %s guarded by %s — concat member dropped", w.prop, w.guard)
432+
}
433+
}
434+
}
435+
436+
func TestConcatResolverRefusesWhatItCannotRead(t *testing.T) {
437+
cases := []struct {
438+
name string
439+
js string
440+
want []string // property keys that MUST be lifted
441+
reject []string // keys that must NOT appear — inventing one is worse than missing it
442+
}{{
443+
name: "inline array literal",
444+
js: `f=function(t,e){"a"===t.mode&&hidePropertiesIn(e,t,["p"].concat(["q","r"]))}`,
445+
want: []string{"p", "q", "r"},
446+
}, {
447+
name: "chained concat of two consts",
448+
js: `A=["q"],B=["r"];f=function(t,e){"a"===t.mode&&hidePropertiesIn(e,t,["p"].concat(A).concat(B))}`,
449+
want: []string{"p", "q", "r"},
450+
}, {
451+
// `.concat(n(x))` — a call on a computed key. Resolving it would mean
452+
// evaluating the widget's own code, so the literal keys stand alone and
453+
// nothing is invented. Eight such sites exist across the fixture.
454+
name: "computed concat argument",
455+
js: `A=["q"];f=function(t,e){"a"===t.mode&&hidePropertiesIn(e,t,["p"].concat(n(A[t.kind])))}`,
456+
want: []string{"p"},
457+
reject: []string{"q"},
458+
}, {
459+
// The minifier reuses short names across scopes. A name bound to two
460+
// different arrays is dropped rather than guessed at — picking either
461+
// would hide properties the editor shows.
462+
name: "identifier bound twice to different arrays",
463+
js: `A=["q"];g=function(){A=["zzz"]};f=function(t,e){"a"===t.mode&&hidePropertiesIn(e,t,["p"].concat(A))}`,
464+
want: []string{"p"},
465+
reject: []string{"q", "zzz"},
466+
}, {
467+
// Not every array is a property list.
468+
name: "array of non-strings",
469+
js: `A=[1,2];f=function(t,e){"a"===t.mode&&hidePropertiesIn(e,t,["p"].concat(A))}`,
470+
want: []string{"p"},
471+
reject: []string{"1"},
472+
}}
473+
474+
for _, tc := range cases {
475+
t.Run(tc.name, func(t *testing.T) {
476+
rules, _ := extractVisibilityRulesFromJS(tc.js)
477+
got := map[string]bool{}
478+
for _, r := range rules {
479+
got[r.PropertyKey] = true
480+
}
481+
for _, w := range tc.want {
482+
if !got[w] {
483+
t.Errorf("missing rule for %q (got %v)", w, got)
484+
}
485+
}
486+
for _, b := range tc.reject {
487+
if got[b] {
488+
t.Errorf("invented a rule for %q — the resolver must withhold, not guess (got %v)", b, got)
489+
}
490+
}
491+
})
492+
}
493+
}

0 commit comments

Comments
 (0)