Skip to content

Commit

Permalink
fix(ByRole): Ensure valid query selectors in all transpilation targets (
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Oct 14, 2021
1 parent 8edfad0 commit b569a1b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/queries/role.js
Expand Up @@ -187,11 +187,17 @@ function makeRoleSelector(role, exact, customNormalizer) {
const explicitRoleSelector =
exact && !customNormalizer ? `*[role~="${role}"]` : '*[role]'

const roleRelations = roleElements.get(role)
const implicitRoleSelectors =
roleRelations && new Set(Array.from(roleRelations).map(({name}) => name))
const roleRelations = roleElements.get(role) ?? new Set()
const implicitRoleSelectors = new Set(
Array.from(roleRelations).map(({name}) => name),
)

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

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

0 comments on commit b569a1b

Please sign in to comment.