Skip to content

Commit

Permalink
test: fix firefox 118 css transform for tests and bump to ff118
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 571464389
  • Loading branch information
Elliott Marquez authored and copybara-github committed Oct 6, 2023
1 parent 1f7296d commit 2e72802
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions testing/transform-pseudo-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ export function transformPseudoClasses(
}
}

/**
* Determines whether or not the CSSRule is a CSSGroupingRule.
*
* Cannot check instanceof because FF treats a CSSStyleRule as a subclass of
* CSSGroupingRule unlike Chrome and Safari
*/
function isCSSGroupingRule(rule: CSSRule): rule is CSSGroupingRule {
return !!(rule as CSSGroupingRule)?.cssRules &&
!(rule as CSSStyleRule).selectorText;
}

/**
* Visits a rule for the given stylesheet and adds a rule that replaces any
* pseudo classes with a regular transformed class for simulation styling.
Expand All @@ -96,9 +107,7 @@ export function transformPseudoClasses(
function visitRule(
rule: CSSRule, stylesheet: CSSStyleSheet|CSSGroupingRule, index: number,
pseudoClasses: string[]) {
// Closure externs don't know about `CSSGroupingRule`, which is why we need to
// reference `globalThis` and use quotes to ensure it is not renamed.
if (rule instanceof globalThis['CSSGroupingRule']) {
if (isCSSGroupingRule(rule)) {
for (let i = rule.cssRules.length - 1; i >= 0; i--) {
visitRule(rule.cssRules[i], rule, i, pseudoClasses);
}
Expand Down

0 comments on commit 2e72802

Please sign in to comment.