Open Bug 2088402 Opened 14 days ago Updated 13 days ago

fallback value in var()/attr() isn't detected as used/unused when var/attribute name comes from a `var()` function

Categories

(DevTools :: Inspector: Rules, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: nchevobbe, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Attached file test_case.html —

For the attached test case

In the following rule:

h1 {
 --x: --y;
 --y: red;
 color: var(var(--x), blue); 
}

for color, the blue fallback value should be struck through


In the following rule:

h2 {
  --x: --unknown;
  color: var(var(--x), blue); 
}

for color, var(--x) should be struck through as the fallback is being used

#onCloseParenthesisForVar in output-parser.js takes the variable name from the first Ident part before the comma. In var(var(--x), blue) the only part there is the already-closed inner var(), an AGGREGATED_TOKEN_TYPE part, so varNameIndex stays null and the parts are returned untouched, with neither the name nor the fallback marked. #onCloseParenthesisForAttr bails out the same way at #885-909, and the same early return is why bug 2087977 has no swatch.

Fix: In both handlers, accept an aggregated var()/attr()/env() part as the name. Resolve the name from its token.data.substitutedText, trimmed and required to start with -- for var(), and use that name for getVariableData/getAttributeValue and the jump-to-definition button, keeping the inner node instead of overwriting it with a text node as the attr path does at #1020. Add both rules from comment 0 to browser_outputparser.js and browser_rules_variables_02.js, plus an attr(var(--x), …) case in browser_rules_attr.js.

Suggested severity: S4. Only a used/unused hint is missing, and only for the nested-name syntax that shipped in Firefox 161 with bug 2080511, which few stylesheets use yet; the computed value is still correct.


If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.
If you want to categorize your feedback you can add one of the following tags: ai-triage-{wrong-file, wrong-cause, hallucination, out-of-scope, not-a-bug, wrong-fix, shallow-fix, wrong-severity}.

Needinfo hackbot@mozilla.tld to have a patch generated for this bug, include any questions or directions as needed in your comment.

Severity: -- → S3
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: