@@ -110,7 +110,7 @@ export function analyze(css, options = {}) {
110
110
let linesOfCode = ast . loc . end . line - ast . loc . start . line + 1
111
111
112
112
// Atrules
113
- let totalAtRules = 0
113
+ let atrules = new Collection ( useLocations )
114
114
let atRuleComplexities = new AggregateCollection ( )
115
115
/** @type {Record<string, string>[] } */
116
116
let fontfaces = [ ]
@@ -209,7 +209,7 @@ export function analyze(css, options = {}) {
209
209
enter ( node ) {
210
210
switch ( node . type ) {
211
211
case Atrule : {
212
- totalAtRules ++
212
+ atrules . p ( node . name , node . loc )
213
213
atruleNesting . push ( nestingDepth )
214
214
uniqueAtruleNesting . p ( nestingDepth , node . loc )
215
215
@@ -795,10 +795,11 @@ export function analyze(css, options = {}) {
795
795
let declarationComplexity = declarationComplexities . aggregate ( )
796
796
let propertyComplexity = propertyComplexities . aggregate ( )
797
797
let valueComplexity = valueComplexities . aggregate ( )
798
+ let atruleCount = atrules . c ( )
798
799
799
800
return {
800
801
stylesheet : {
801
- sourceLinesOfCode : totalAtRules + totalSelectors + totalDeclarations + keyframeSelectors . size ( ) ,
802
+ sourceLinesOfCode : atruleCount . total + totalSelectors + totalDeclarations + keyframeSelectors . size ( ) ,
802
803
linesOfCode,
803
804
size : cssLen ,
804
805
complexity : atRuleComplexity . sum + selectorComplexity . sum + declarationComplexity . sum + propertyComplexity . sum + valueComplexity . sum ,
@@ -819,55 +820,57 @@ export function analyze(css, options = {}) {
819
820
} ,
820
821
} ,
821
822
} ,
822
- atrules : {
823
- fontface : assign ( {
824
- total : fontFacesCount ,
825
- totalUnique : fontFacesCount ,
826
- unique : fontfaces ,
827
- uniquenessRatio : fontFacesCount === 0 ? 0 : 1 ,
828
- } , useLocations ? {
829
- uniqueWithLocations : fontfaces_with_loc . c ( ) . uniqueWithLocations ,
830
- } : { } ) ,
831
- import : imports . c ( ) ,
832
- media : assign (
833
- medias . c ( ) ,
834
- {
835
- browserhacks : mediaBrowserhacks . c ( ) ,
836
- features : mediaFeatures . c ( ) ,
837
- }
838
- ) ,
839
- charset : charsets . c ( ) ,
840
- supports : assign (
841
- supports . c ( ) ,
842
- {
843
- browserhacks : supportsBrowserhacks . c ( ) ,
844
- } ,
845
- ) ,
846
- keyframes : assign (
847
- keyframes . c ( ) , {
848
- prefixed : assign (
849
- prefixedKeyframes . c ( ) , {
850
- ratio : ratio ( prefixedKeyframes . size ( ) , keyframes . size ( ) )
823
+ atrules : assign (
824
+ atruleCount ,
825
+ {
826
+ fontface : assign ( {
827
+ total : fontFacesCount ,
828
+ totalUnique : fontFacesCount ,
829
+ unique : fontfaces ,
830
+ uniquenessRatio : fontFacesCount === 0 ? 0 : 1 ,
831
+ } , useLocations ? {
832
+ uniqueWithLocations : fontfaces_with_loc . c ( ) . uniqueWithLocations ,
833
+ } : { } ) ,
834
+ import : imports . c ( ) ,
835
+ media : assign (
836
+ medias . c ( ) ,
837
+ {
838
+ browserhacks : mediaBrowserhacks . c ( ) ,
839
+ features : mediaFeatures . c ( ) ,
840
+ }
841
+ ) ,
842
+ charset : charsets . c ( ) ,
843
+ supports : assign (
844
+ supports . c ( ) ,
845
+ {
846
+ browserhacks : supportsBrowserhacks . c ( ) ,
847
+ } ,
848
+ ) ,
849
+ keyframes : assign (
850
+ keyframes . c ( ) , {
851
+ prefixed : assign (
852
+ prefixedKeyframes . c ( ) , {
853
+ ratio : ratio ( prefixedKeyframes . size ( ) , keyframes . size ( ) )
854
+ } ) ,
851
855
} ) ,
852
- } ) ,
853
- container : assign (
854
- containers . c ( ) ,
855
- {
856
- names : containerNames . c ( ) ,
857
- }
858
- ) ,
859
- layer : layers . c ( ) ,
860
- property : registeredProperties . c ( ) ,
861
- total : totalAtRules ,
862
- complexity : atRuleComplexity ,
863
- nesting : assign (
864
- atruleNesting . aggregate ( ) ,
865
- {
866
- items : atruleNesting . toArray ( ) ,
867
- } ,
868
- uniqueAtruleNesting . c ( ) ,
869
- ) ,
870
- } ,
856
+ container : assign (
857
+ containers . c ( ) ,
858
+ {
859
+ names : containerNames . c ( ) ,
860
+ }
861
+ ) ,
862
+ layer : layers . c ( ) ,
863
+ property : registeredProperties . c ( ) ,
864
+ complexity : atRuleComplexity ,
865
+ nesting : assign (
866
+ atruleNesting . aggregate ( ) ,
867
+ {
868
+ items : atruleNesting . toArray ( ) ,
869
+ } ,
870
+ uniqueAtruleNesting . c ( ) ,
871
+ ) ,
872
+ }
873
+ ) ,
871
874
rules : {
872
875
total : totalRules ,
873
876
empty : {
0 commit comments