@@ -83,7 +83,7 @@ export const calculateForAST = (selectorAST: Selector): Specificity => {
8383 if ( current . has_children ) {
8484 // The first child should be a NODE_SELECTOR_LIST
8585 const childSelectorList = current . first_child
86- if ( is_selector_list ( childSelectorList ) ) {
86+ if ( childSelectorList && is_selector_list ( childSelectorList ) ) {
8787 // Calculate Specificity for all selectors in the list and get max
8888 const max1 = max ( calculate ( childSelectorList ) )
8989
@@ -103,7 +103,7 @@ export const calculateForAST = (selectorAST: Selector): Specificity => {
103103
104104 // Get NODE_SELECTOR_NTH_OF which contains the "of" selector list
105105 const nthOf = current . first_child
106- if ( is_nth_of_selector ( nthOf ) && nthOf . selector ) {
106+ if ( nthOf && is_nth_of_selector ( nthOf ) && nthOf . selector ) {
107107 // Use the convenience property to access the selector list directly
108108 const max2 = max ( calculate ( nthOf . selector ) )
109109
@@ -121,7 +121,7 @@ export const calculateForAST = (selectorAST: Selector): Specificity => {
121121 b += 1
122122
123123 const selector_list = current . first_child
124- const childSelector = selector_list . first_child
124+ const childSelector = selector_list ? .first_child
125125 if ( childSelector && is_selector ( childSelector ) ) {
126126 // Calculate specificity for parts before the first combinator
127127 let childPart = childSelector . first_child
@@ -165,8 +165,8 @@ export const calculateForAST = (selectorAST: Selector): Specificity => {
165165 c += 1
166166
167167 const selector_list = current . first_child
168- const childSelector = selector_list . first_child
169- if ( is_selector ( childSelector ) ) {
168+ const childSelector = selector_list ? .first_child
169+ if ( childSelector && is_selector ( childSelector ) ) {
170170 // Calculate specificity for parts before the first combinator
171171 let childPart = childSelector . first_child
172172 while ( childPart ) {
0 commit comments