import * as css from "css" ; import CssClassDefinition from "../../common/css-class-definition" ; export default class CssClassExtractor { description public static extract ( ast ) { const classNameRegex = /[.]([\w-]+)/g ; const definitions = [ ] ; const addRule = ( rule ) => { rule . selectors ?. forEach ( ( selector ) => { let item = classNameRegex . exec ( selector ) ; while ( item ) { definitions . push ( new CssClassDefinition ( item [ 1 ] ) ) ; item = classNameRegex . exec ( selector ) ; } } ) ; } ; ast . stylesheet ?. rules . forEach ( ( rule ) => { if ( rule . type === "rule" ) { addRule ( rule ) ; } if ( rule . type === "media" ) { rule . rules ?. forEach ( ( rule ) => addRule ( rule ) ) ; } } ) ; return definitions ; } }