import { parseSelector , postcss , postcssSelectorParser as selectorParser } from "opticss" ; import { BLOCK_GLOBAL } from "../../BlockSyntax" ; import { Block } from "../../BlockTree" ; import { Configuration } from "../../configuration" ; import * as errors from "../../errors" ; import { sourceRange as range } from "../../SourceLocation" ; import { toAttrToken } from "../block-intermediates" ; export function globalAttributes ( configuration , root , block , file ) { root . walkAtRules ( BLOCK_GLOBAL , ( atRule ) => { let selectors = parseSelector ( atRule . params . trim ( ) ) ; if ( selectors . length === 1 && selectors [ 0 ] . key === selectors [ 0 ] . selector ) { let firstNode = selectors [ 0 ] . key . nodes [ 0 ] ; if ( firstNode && selectorParser . isAttribute ( firstNode ) ) { let attr = block . rootClass . ensureAttributeValue ( toAttrToken ( firstNode ) ) ; attr . isGlobal = true ; } else { block . addError ( new errors . InvalidBlockSyntax ( `Illegal global attribute declaration: ${ atRule . toString ( ) }` , range ( configuration , root , file , atRule ) ) ) ; } } } ) ; return block ; }