Skip to content

Commit

Permalink
Nicer function interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark George committed Dec 14, 2023
1 parent d3cc334 commit 289bcc6
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/style-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class StyleAST {
const clone = new StyleAST( this.css, csstree.clone( this.ast ), this.errors );

clone.pruneMediaQueries();
clone.pruneAtRules();
clone.pruneAtRules( [ 'keyframes', 'charset', 'import' ] );
clone.pruneNonCriticalSelectors( criticalSelectors );
clone.pruneExcludedProperties();
clone.pruneLargeBase64Embeds();
Expand Down Expand Up @@ -256,16 +256,15 @@ export class StyleAST {
}

/**
* Remove atrules which are incompatible with Critical CSS.
* Targets keyframes (for animations), charsets and imports.
* Remove unwanted at-rules.
*
* @param { string[] } names - Names of at-rules to remove, excluding the at symbol.
*/
pruneAtRules(): void {
const prune = [ 'keyframes', 'charset', 'import' ];

pruneAtRules( names: string[] ): void {
csstree.walk( this.ast, {
visit: 'Atrule',
enter: ( atrule, atitem, atlist ) => {
if ( prune.includes( csstree.keyword( atrule.name ).basename ) ) {
if ( names.includes( csstree.keyword( atrule.name ).basename ) ) {
atlist.remove( atitem );
}
},
Expand Down

0 comments on commit 289bcc6

Please sign in to comment.