From 715dc6cdce668a90774a35b86dc9b0db43af0fbd Mon Sep 17 00:00:00 2001 From: Bart Veneman <1536852+bartveneman@users.noreply.github.com> Date: Sat, 30 Dec 2023 23:06:36 +0100 Subject: [PATCH] fix: vendor-prefixed selector false positives (#373) Re-fixes #348 --- src/__fixtures__/gazelle-20231008.json | 11 +++++------ src/selectors/complexity.test.js | 6 ++++-- src/selectors/utils.js | 6 +----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/__fixtures__/gazelle-20231008.json b/src/__fixtures__/gazelle-20231008.json index be1ce83..27bef14 100644 --- a/src/__fixtures__/gazelle-20231008.json +++ b/src/__fixtures__/gazelle-20231008.json @@ -87449,8 +87449,8 @@ "uniquenessRatio": 0.09259259259259259 }, "prefixed": { - "total": 30, - "totalUnique": 29, + "total": 29, + "totalUnique": 28, "unique": { "button::-moz-focus-inner": 2, "input::-moz-focus-inner": 1, @@ -87479,11 +87479,10 @@ "::-webkit-search-decoration": 1, "::-webkit-file-upload-button": 1, "input::-moz-placeholder": 1, - "textarea::-moz-placeholder": 1, - ".-tw-bottom-\\[35px\\]": 1 + "textarea::-moz-placeholder": 1 }, - "uniquenessRatio": 0.9666666666666667, - "ratio": 0.0028161081385525205 + "uniquenessRatio": 0.9655172413793104, + "ratio": 0.0027222378672674364 }, "combinators": { "total": 12605, diff --git a/src/selectors/complexity.test.js b/src/selectors/complexity.test.js index 71fb2e1..f269698 100644 --- a/src/selectors/complexity.test.js +++ b/src/selectors/complexity.test.js @@ -58,11 +58,13 @@ Complexity('calculates complexity with vendor prefixes', () => { no-prefix, fake-webkit, .-mt-px, - .-space-x-1 {} + .-space-x-1, + .-pd-translate-y-2, + .-pd-translate-x-full {} `).selectors.complexity assert.equal(actual.unique, { - '1': 4, + '1': 6, '5': 1, '2': 1, '12': 1, diff --git a/src/selectors/utils.js b/src/selectors/utils.js index 2112cbc..78d0c24 100644 --- a/src/selectors/utils.js +++ b/src/selectors/utils.js @@ -3,8 +3,6 @@ import { startsWith, strEquals } from '../string-utils.js' import { hasVendorPrefix } from '../vendor-prefix.js' import { PseudoClassSelector, - IdSelector, - ClassSelector, PseudoElementSelector, TypeSelector, Combinator, @@ -82,9 +80,7 @@ export function isPrefixed(selector) { let isPrefixed = false walk(selector, function (node) { - if (node.type === IdSelector - || node.type === ClassSelector - || node.type === PseudoElementSelector + if (node.type === PseudoElementSelector || node.type === TypeSelector || node.type === PseudoClassSelector ) {