Skip to content

Commit b569a1b

Browse files
authored
fix(ByRole): Ensure valid query selectors in all transpilation targets (#1055)
1 parent 8edfad0 commit b569a1b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/queries/role.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,17 @@ function makeRoleSelector(role, exact, customNormalizer) {
187187
const explicitRoleSelector =
188188
exact && !customNormalizer ? `*[role~="${role}"]` : '*[role]'
189189

190-
const roleRelations = roleElements.get(role)
191-
const implicitRoleSelectors =
192-
roleRelations && new Set(Array.from(roleRelations).map(({name}) => name))
190+
const roleRelations = roleElements.get(role) ?? new Set()
191+
const implicitRoleSelectors = new Set(
192+
Array.from(roleRelations).map(({name}) => name),
193+
)
193194

194-
return [explicitRoleSelector, ...(implicitRoleSelectors ?? [])].join(',')
195+
// Current transpilation config sometimes assumes `...` is always applied to arrays.
196+
// `...` is equivalent to `Array.prototype.concat` for arrays.
197+
// If you replace this code with `[explicitRoleSelector, ...implicitRoleSelectors]`, make sure every transpilation target retains the `...` in favor of `Array.prototype.concat`.
198+
return [explicitRoleSelector]
199+
.concat(Array.from(implicitRoleSelectors))
200+
.join(',')
195201
}
196202

197203
const getMultipleError = (c, role, {name} = {}) => {

0 commit comments

Comments
 (0)