(node)
| 134 | csstree.walk(ast, { |
| 135 | visit: "Function", |
| 136 | enter(node) { |
| 137 | const fnNode = node as csstree.FunctionNode; |
| 138 | if (fnNode.name !== "var" || !fnNode.loc) { |
| 139 | return; |
| 140 | } |
| 141 | const varRef = parseCssVar(fnNode); |
| 142 | if (!varRef) { |
| 143 | return walkSkip; |
| 144 | } |
| 145 | |
| 146 | const direct = |
| 147 | customProperties.get(`--${varRef.value}`) ?? |
| 148 | cssVars?.get(`--${varRef.value}`); |
| 149 | |
| 150 | if (direct !== undefined) { |
| 151 | if (!customProperties.has(`--${varRef.value}`)) { |
| 152 | usedCssVarsSubstitution = true; |
| 153 | } |
| 154 | subs.push({ |
| 155 | start: fnNode.loc.start.offset, |
| 156 | end: fnNode.loc.end.offset, |
| 157 | text: direct, |
| 158 | }); |
| 159 | return walkSkip; |
| 160 | } |
| 161 | |
| 162 | // Try inline fallback — may itself contain var() references. |
| 163 | if (varRef.fallback?.type === "unparsed") { |
| 164 | const fbValue = varRef.fallback.value; |
| 165 | // If the fallback itself has no var(), use it directly. |
| 166 | // Otherwise recursively resolve any nested vars inside it. |
| 167 | const fallbackResult = fbValue.includes("var(") |
| 168 | ? resolveVars(fbValue, customProperties, cssVars, depth + 1) |
| 169 | : { resolved: fbValue, dropped: [] }; |
| 170 | if ( |
| 171 | fallbackResult !== undefined && |
| 172 | fallbackResult.dropped.length === 0 |
| 173 | ) { |
| 174 | subs.push({ |
| 175 | start: fnNode.loc.start.offset, |
| 176 | end: fnNode.loc.end.offset, |
| 177 | text: fallbackResult.resolved, |
| 178 | }); |
| 179 | return walkSkip; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | dropped.push(`--${varRef.value}`); |
| 184 | return walkSkip; |
| 185 | }, |
| 186 | }); |
| 187 | |
| 188 | let resolved = value; |
no test coverage detected