import { postcss } from "opticss" ; import { BLOCK_ID } from "../../BlockSyntax" ; import { Configuration } from "../../configuration" ; import * as errors from "../../errors" ; import { sourceRange } from "../../SourceLocation" ; import { stripQuotes } from "../utils" ; export function discoverGuid ( configuration , root , file , isDfnFile = false , expectedId ? ) { let blockId ; let scopeNode ; if ( ! isDfnFile ) { return ; } root . walkRules ( ":scope" , ( rule ) => { scopeNode = rule ; rule . walkDecls ( BLOCK_ID , ( decl ) => { blockId = stripQuotes ( decl . value . trim ( ) ) ; if ( expectedId && blockId !== expectedId ) { throw new errors . InvalidBlockSyntax ( `Expected block-id property in definition data to match header in Compiled CSS.` , sourceRange ( configuration , root , file , decl ) ) ; } } ) ; } ) ; if ( ! blockId ) { if ( scopeNode ) { throw new errors . InvalidBlockSyntax ( `Expected block-id to be declared in definition's :scope rule.` , sourceRange ( configuration , root , file , scopeNode ) ) ; } else { throw new errors . InvalidBlockSyntax ( `Expected block-id to be declared in definition's :scope rule.` , { filename : file , } ) ; } } return blockId ; }