import { TemplateAnalysis , TemplateIntegrationOptions , TemplateTypes , rewriteOptions } from "@opticss/template-api" ; import { assertNever } from "@opticss/util" ; import * as SelectorParser from "postcss-selector-parser" ; import { ParsedCssFile } from "../CssFile" ; import { OptiCSSOptions } from "../OpticssOptions" ; import { OptimizationPass } from "../OptimizationPass" ; import { eachFileIdent } from "../util/cssIntrospection" ; const { isClassName , isIdentifier } = SelectorParser ; param pass param analyses param files param options param templateOptions export function initKnownIdents ( pass , analyses , files , options , templateOptions ) { let opts = rewriteOptions ( options . rewriteIdents , templateOptions . rewriteIdents ) ; pass . identGenerators . reserve ( "class" , ... opts . omitIdents . class ) ; pass . identGenerators . reserve ( "id" , ... opts . omitIdents . id ) ; eachFileIdent ( files , pass . cache , opts , ( node ) => { if ( isClassName ( node ) ) { pass . identGenerators . reserve ( "class" , node . value ) ; pass . styleMapping . addSourceAttribute ( { name : "class" , value : node . value } ) ; } else if ( isIdentifier ( node ) ) { pass . identGenerators . reserve ( "id" , node . value ) ; pass . styleMapping . addSourceAttribute ( { name : "id" , value : node . value } ) ; } else { assertNever ( node ) ; } } ) ; for ( let analysis of analyses ) { let allConstants = analysis . constants ( new Set ( [ "class" , "id" ] ) ) ; for ( let constantType of Object . keys ( allConstants ) ) { for ( let constant of allConstants [ constantType ] ) { pass . identGenerators . reserve ( < "class" | "id" > constantType , constant ) ; } } } }