Commit 56bf191
committed
fix(#6250 round-6): tokenize attribute selectors; apply attributeMatchers on parsed tokens only
PerishCode round-6 CHANGES_REQUESTED on PR #6250 (commit 7ea2570):
The round-5 implementation removed `selectorMatchers` from the
classification path but kept `attributeMatchers` running against the
raw selector string. PerishCode reproduced three cross-attribution
violations:
1. `:not([type=submit])` was admitted into Buttons.selectors because
the `[type=submit]` text appears in the raw selector and
`/\[type=...(button|submit|reset)/` matched it — even though
`:not()` is component-erasing and the predicate sits inside an
opaque pseudo-class.
2. `[data-label="[type=submit]"]` was admitted into Buttons because
the attribute VALUE spells `[type=submit]` and the un-anchored
matcher regex matched the substring inside the value text. The
selector target's actual attribute is `data-label`, not `type`.
3. `:not([aria-hidden="true"])` was admitted into Icons for the same
reason as (1) — `[aria-hidden="true"]` text inside `:not()`
matched the unanchored Icons matcher.
Round-6 fix:
- `tokenizeCompound` now also collects attribute-selector tokens from
each compound. Quoted strings inside the attribute value are
respected, so `[data-label="[type=submit]"]` is captured as ONE
token (the inner `[type=submit]` is hidden inside the quoted
value, not split out).
- `:is()` / `:where()` recursion now unions the inner compounds'
attribute tokens into the parent compound's attribute list, so
`:is(input[type="submit"])` still admits to Buttons.
- `:not()` / `:has()` remain opaque (their argument compounds are
never tokenized), so `[type="submit"]` inside `:not(...)` never
enters the parsed attribute list, and the matcher pipeline never
sees it.
- `attributeMatchers` regexes are now anchored at token start
(`^\[...`) and require the closing `]`, so a long attribute token
whose value merely *contains* attribute-looking text can no longer
match (substring search is no longer possible once the regex is
bound to the full token).
- `selectorMatchesTokens` runs `attributeMatchers` against the
parsed attribute tokens (per compound) instead of the raw
selector string. The early-return path that bypassed the opacity
rule is gone.
Round-6 fixture matrix
(`tests/components-manifest-6250-not-and-attribute-opacity.test.ts`):
Negative cases (all newly added — none of these passed before):
- `:not(.btn)` does NOT admit to Buttons (round-5, still passes)
- `[data-label=".card"]` does NOT admit to Cards (round-5, still passes)
- `:not([type="submit"])` does NOT admit to Buttons — NEW
- `:not([aria-hidden="true"])` does NOT admit to Icons — NEW
- `[data-label="[type=submit]"]` does NOT admit to Buttons — NEW
Positive controls (must keep working):
- `[type="submit"]` admits to Buttons and contributes
`--tone-button-attr` to `Buttons.tokenReferences`
- `[aria-hidden="true"]` admits to Icons and contributes
`--tone-icon` to `Icons.tokenReferences`
Negative token assertions are now written as
`r === 'X' || r === '--X'` so the assertion fires regardless of which
form the manifest stores (the previous round-5 assertions compared
against the unprefixed token name, which silently passed even when
the manifest stored the prefixed form).
Validation on this head:
pnpm --filter @open-design/contracts test
-> 295 passed (44 files), was 290 before this round (5 new fixtures)
Signed-off-by: xxiaoxiong <2482929840@qq.com>1 parent 7ea2570 commit 56bf191
2 files changed
Lines changed: 119 additions & 18 deletions
File tree
- packages/contracts
- src/design-systems
- tests
Lines changed: 59 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| |||
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
353 | 364 | | |
354 | 365 | | |
355 | 366 | | |
| |||
374 | 385 | | |
375 | 386 | | |
376 | 387 | | |
| 388 | + | |
377 | 389 | | |
378 | 390 | | |
379 | 391 | | |
| |||
390 | 402 | | |
391 | 403 | | |
392 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
393 | 429 | | |
394 | 430 | | |
395 | 431 | | |
| |||
432 | 468 | | |
433 | 469 | | |
434 | 470 | | |
| 471 | + | |
435 | 472 | | |
436 | 473 | | |
437 | 474 | | |
| |||
446 | 483 | | |
447 | 484 | | |
448 | 485 | | |
449 | | - | |
| 486 | + | |
450 | 487 | | |
451 | 488 | | |
452 | 489 | | |
| |||
457 | 494 | | |
458 | 495 | | |
459 | 496 | | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
464 | 503 | | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | 504 | | |
472 | 505 | | |
473 | | - | |
| 506 | + | |
474 | 507 | | |
475 | 508 | | |
476 | 509 | | |
| |||
480 | 513 | | |
481 | 514 | | |
482 | 515 | | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
483 | 528 | | |
484 | 529 | | |
485 | 530 | | |
| |||
Lines changed: 60 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
31 | 49 | | |
32 | 50 | | |
33 | 51 | | |
| |||
36 | 54 | | |
37 | 55 | | |
38 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
39 | 60 | | |
40 | 61 | | |
41 | 62 | | |
| |||
55 | 76 | | |
56 | 77 | | |
57 | 78 | | |
58 | | - | |
| 79 | + | |
59 | 80 | | |
60 | 81 | | |
61 | 82 | | |
| |||
68 | 89 | | |
69 | 90 | | |
70 | 91 | | |
71 | | - | |
| 92 | + | |
72 | 93 | | |
73 | 94 | | |
74 | 95 | | |
| |||
82 | 103 | | |
83 | 104 | | |
84 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
85 | 141 | | |
0 commit comments