fix(lint): a descendant selector inside a scoped query hides the overlay too

This commit is contained in:
Miguel Angel Simon Sierra
2026-10-29 23:29:14 -04:00
parent 4c41244936
commit ae7e6a73cb
2 changed files with 27 additions and 2 deletions
+18
View File
@@ -3753,6 +3753,24 @@ describe("SVG draw-on rules", () => {
).toBe(false);
});
it("accepts a descendant selector inside the query", async () => {
expect(
await flagged(
scene(
'gsap.set(document.querySelector("[data-composition-id=scene] .ov"), { opacity: 0 });',
),
),
).toBe(false);
});
it("accepts a querySelector variable written without semicolons", async () => {
expect(
await flagged(
scene('const ov = root.querySelector(".ov")\n gsap.set(ov, { opacity: 0 })'),
),
).toBe(false);
});
it("still flags an overlay nothing hides at zero", async () => {
expect(await flagged(scene(""))).toBe(true);
});
+9 -2
View File
@@ -274,7 +274,7 @@ function extractStandaloneHiddenSelectors(script: string): Set<string> {
aliases.set(match[1] ?? "", match[3] ?? "");
}
for (const match of source.matchAll(
/(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*[\w$.]+\.querySelector(?:All)?\(\s*(["'`])([^"'`]+)\2\s*\)\s*;/g,
/(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*[\w$.]+\.querySelector(?:All)?\(\s*(["'`])([^"'`]+)\2\s*\)/g,
)) {
aliases.set(match[1] ?? "", match[3] ?? "");
}
@@ -1202,7 +1202,14 @@ export const gsapRules: LintRule<LintContext>[] = [
(win.fromPropertyValues !== undefined && isHiddenGsapState(win.fromPropertyValues))),
);
if (startsHiddenAtZero) continue;
if (selectors.some((selector) => authoredHiddenSelectors.has(selector))) continue;
if (
selectors.some((selector) =>
[...authoredHiddenSelectors].some(
(hidden) => hidden === selector || targetedSelectorTokens(hidden).has(selector),
),
)
)
continue;
const firstVisible = visibilityWindows.find((win) => makesOverlayVisible(win));
if (!firstVisible) continue;
const selector =