@@ -17,6 +17,8 @@ import { isCustom, isHack, isProperty } from './properties/property-utils.js'
1717import { getEmbedType } from './stylesheet/stylesheet.js'
1818import { isIe9Hack } from './values/browserhacks.js'
1919
20+ /** @typedef {[number, number, number] } Specificity */
21+
2022function ratio ( part , total ) {
2123 if ( total === 0 ) return 0
2224 return part / total
@@ -49,12 +51,12 @@ const analyze = (css) => {
4951 let embedSize = 0
5052 const embedTypes = {
5153 total : 0 ,
54+ /** @type {Map<string, {size: number, count: number}> } */
5255 unique : new Map ( )
5356 }
5457
5558 const startParse = Date . now ( )
5659
57- /** @type import('css-tree').CssNode */
5860 const ast = parse ( css , {
5961 parseCustomProperty : true , // To find font-families, colors, etc.
6062 positions : true , // So we can use stringifyNode()
@@ -70,7 +72,7 @@ const analyze = (css) => {
7072
7173 // Atrules
7274 let totalAtRules = 0
73- /** @type {string }[]} */
75+ /** @type {{[property: string]: string}[] } */
7476 const fontfaces = [ ]
7577 const layers = new CountableCollection ( )
7678 const imports = new CountableCollection ( )
@@ -94,16 +96,16 @@ const analyze = (css) => {
9496 const keyframeSelectors = new CountableCollection ( )
9597 const uniqueSelectors = new Set ( )
9698 const prefixedSelectors = new CountableCollection ( )
97- /** @type [number,number,number] */
99+ /** @type { Specificity } */
98100 let maxSpecificity
99- /** @type [number,number,number] */
101+ /** @type { Specificity } */
100102 let minSpecificity
101103 const specificityA = new AggregateCollection ( )
102104 const specificityB = new AggregateCollection ( )
103105 const specificityC = new AggregateCollection ( )
104106 const uniqueSpecificities = new CountableCollection ( )
105107 const selectorComplexities = new AggregateCollection ( )
106- /** @type [number,number,number][] */
108+ /** @type { Specificity[] } */
107109 const specificities = [ ]
108110 const ids = new CountableCollection ( )
109111 const a11y = new CountableCollection ( )
@@ -144,7 +146,6 @@ const analyze = (css) => {
144146 const atRuleName = node . name
145147
146148 if ( atRuleName === 'font-face' ) {
147- /** @type {[index: string]: string } */
148149 const descriptors = { }
149150
150151 node . block . children . forEach ( descriptor => {
@@ -226,6 +227,7 @@ const analyze = (css) => {
226227 }
227228
228229 const [ { value : specificityObj } ] = calculate ( node )
230+ /** @type {Specificity } */
229231 const specificity = [ specificityObj . a , specificityObj . b , specificityObj . c ]
230232
231233 if ( specificity [ 0 ] > 0 ) {
@@ -601,17 +603,17 @@ const analyze = (css) => {
601603 totalUnique : totalUniqueSelectors ,
602604 uniquenessRatio : ratio ( totalUniqueSelectors , totalSelectors ) ,
603605 specificity : {
604- /** @type [number, number, number] */
606+ /** @type Specificity */
605607 min : minSpecificity === undefined ? [ 0 , 0 , 0 ] : minSpecificity ,
606- /** @type [number, number, number] */
608+ /** @type Specificity */
607609 max : maxSpecificity === undefined ? [ 0 , 0 , 0 ] : maxSpecificity ,
608- /** @type [number, number, number] */
610+ /** @type Specificity */
609611 sum : [ specificitiesA . sum , specificitiesB . sum , specificitiesC . sum ] ,
610- /** @type [number, number, number] */
612+ /** @type Specificity */
611613 mean : [ specificitiesA . mean , specificitiesB . mean , specificitiesC . mean ] ,
612- /** @type [number, number, number] */
614+ /** @type Specificity */
613615 mode : [ specificitiesA . mode , specificitiesB . mode , specificitiesC . mode ] ,
614- /** @type [number, number, number] */
616+ /** @type Specificity */
615617 median : [ specificitiesA . median , specificitiesB . median , specificitiesC . median ] ,
616618 items : specificities ,
617619 unique : uniqueSpecificitiesCount . unique ,
0 commit comments