From b569a1b82aac5d400ee63309f0cba62738922a15 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 14 Oct 2021 11:29:44 +0200 Subject: [PATCH] fix(ByRole): Ensure valid query selectors in all transpilation targets (#1055) --- src/queries/role.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/queries/role.js b/src/queries/role.js index 2457b6c0..826edd43 100644 --- a/src/queries/role.js +++ b/src/queries/role.js @@ -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} = {}) => {