import { CssBlockError } from "@css-blocks/core" ; import type { AST } from "@glimmer/syntax" ; import { ClassifiedParsedSelectors } from "opticss" ; export type AnalyzableNode = AST . ElementNode | AST . BlockStatement | AST . MustacheStatement | AST . SubExpression ; export type AnalyzableProperty = AST . AttrNode | AST . HashPair | AST . PathExpression ; export function pathFromSpecifier ( specifier ) { return specifier . split ( ":" ) [ 1 ] ; } export function selectorCount ( result ) { let count = result . main . length ; Object . keys ( result . other ) . forEach ( ( k ) => { count += result . other [ k ] . length ; } ) ; return count ; } export function parseSpecifier ( specifier ) { if ( /^(component|template|stylesheet):(.*)$/ . test ( specifier ) ) { return { componentType : RegExp . $1 , componentName : RegExp . $2 , } ; } else { return null ; } } export function pathString ( node ) { if ( isStringLiteral ( node . path ) || isPathExpression ( node . path ) ) { return node . path . original ; } else { return null ; } } export function cssBlockError ( message , node , templatePath ) { return new CssBlockError ( message , { filename : node . loc . source || templatePath , start : node . loc . start , end : node . loc . end , } ) ; } export function isStringLiteral ( value ) { return value !== undefined && value !== null && value . type === "StringLiteral" ; } export function isConcatStatement ( value ) { return ! ! value && value . type === "ConcatStatement" ; } export function isTextNode ( value ) { return ! ! value && value . type === "TextNode" ; } export function isBooleanLiteral ( value ) { return ! ! value && value . type === "BooleanLiteral" ; } export function isMustacheStatement ( value ) { return ! ! value && value . type === "MustacheStatement" ; } export function isBlockStatement ( value ) { return ! ! value && value . type === "BlockStatement" ; } export function isSubExpression ( value ) { return ! ! value && value . type === "SubExpression" ; } export function isElementNode ( value ) { return ! ! value && value . type === "ElementNode" ; } export function isNumberLiteral ( value ) { return ! ! value && value . type === "NumberLiteral" ; } export function isNullLiteral ( value ) { return ! ! value && value . type === "NullLiteral" ; } export function isUndefinedLiteral ( value ) { return ! ! value && value . type === "UndefinedLiteral" ; } export function isPathExpression ( value ) { return ! ! value && value . type === "PathExpression" ; } export function isHashPair ( value ) { return ! ! value && value . type === "HashPair" ; } export function isAttrNode ( value ) { return ! ! value && value . type === "AttrNode" ; } export function isAnalyzableProperty ( value ) { return ! ! value && ( isAttrNode ( value ) || isHashPair ( value ) || isPathExpression ( value ) ) ; }