* @param {EvalContext} context * @param {Node[]} rules * @returns {Node[]}
(context, rules)
| 223 | * @returns {Node[]} |
| 224 | */ |
| 225 | evalRoot(context, rules) { |
| 226 | let ampersandCount = 0; |
| 227 | let noAmpersandCount = 0; |
| 228 | let noAmpersands = true; |
| 229 | |
| 230 | if (!this.simpleBlock) { |
| 231 | rules = [rules[0].eval(context)]; |
| 232 | } |
| 233 | |
| 234 | /** @type {Selector[]} */ |
| 235 | let precedingSelectors = []; |
| 236 | if (context.frames.length > 0) { |
| 237 | for (let index = 0; index < context.frames.length; index++) { |
| 238 | const frame = /** @type {RulesetLikeNode} */ (context.frames[index]); |
| 239 | if ( |
| 240 | frame.type === 'Ruleset' && |
| 241 | frame.rules && |
| 242 | frame.rules.length > 0 |
| 243 | ) { |
| 244 | if (frame && !frame.root && frame.selectors && frame.selectors.length > 0) { |
| 245 | precedingSelectors = precedingSelectors.concat(frame.selectors); |
| 246 | } |
| 247 | } |
| 248 | if (precedingSelectors.length > 0) { |
| 249 | const allAmpersandElements = precedingSelectors.every( |
| 250 | sel => sel.elements && sel.elements.length > 0 && sel.elements.every( |
| 251 | /** @param {import('./element.js').default} el */ |
| 252 | el => el.value === '&' |
| 253 | ) |
| 254 | ); |
| 255 | if (allAmpersandElements) { |
| 256 | noAmpersands = false; |
| 257 | noAmpersandCount++; |
| 258 | } else { |
| 259 | ampersandCount++; |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | const mixedAmpersands = ampersandCount > 0 && noAmpersandCount > 0 && !noAmpersands; |
| 266 | if ( |
| 267 | (this.isRooted && ampersandCount > 0 && noAmpersandCount === 0 && noAmpersands) |
| 268 | || !mixedAmpersands |
| 269 | ) { |
| 270 | /** @type {RulesetLikeNode} */ (rules[0]).root = true; |
| 271 | } |
| 272 | return rules; |
| 273 | } |
| 274 | |
| 275 | /** @param {string} name */ |
| 276 | variable(name) { |