Skip to content

Commit

Permalink
Remove charset and import statements from incoming CSS, as they can't…
Browse files Browse the repository at this point in the history
… appear mid-stream
  • Loading branch information
Mark George committed Dec 12, 2023
1 parent 450c06a commit d3cc334
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 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.pruneKeyframes();
clone.pruneAtRules();
clone.pruneNonCriticalSelectors( criticalSelectors );
clone.pruneExcludedProperties();
clone.pruneLargeBase64Embeds();
Expand Down Expand Up @@ -256,14 +256,16 @@ export class StyleAST {
}

/**
* Remove keyframe definitions.
* Remove atrules which are incompatible with Critical CSS.
* Targets keyframes (for animations), charsets and imports.
*/
pruneKeyframes(): void {
pruneAtRules(): void {
const prune = [ 'keyframes', 'charset', 'import' ];

csstree.walk( this.ast, {
visit: 'Atrule',
enter: ( atrule, atitem, atlist ) => {
// Ignore non-keyframes.
if ( csstree.keyword( atrule.name ).basename === 'keyframes' ) {
if ( prune.includes( csstree.keyword( atrule.name ).basename ) ) {
atlist.remove( atitem );
}
},
Expand Down

0 comments on commit d3cc334

Please sign in to comment.