@@ -12,9 +12,9 @@ import {zwitch} from 'zwitch'
1212import { enterState } from './enter-state.js'
1313import { parent , element } from './util.js'
1414
15- var own = { } . hasOwnProperty
15+ const own = { } . hasOwnProperty
1616
17- var handle = zwitch ( 'nestingOperator' , {
17+ const handle = zwitch ( 'nestingOperator' , {
1818 unknown : unknownNesting ,
1919 invalid : topScan , // `undefined` is the top query selector.
2020 handlers : {
@@ -53,7 +53,7 @@ function topScan(query, node, index, parent, state) {
5353
5454/** @type {Handler } */
5555function descendant ( query , node , index , parent , state ) {
56- var previous = state . iterator
56+ const previous = state . iterator
5757
5858 state . iterator = iterator
5959 child ( query , node , index , parent , state )
@@ -103,16 +103,14 @@ function generalSibling(query, _, index, parent, state) {
103103 * @param {boolean } [firstElementOnly=false]
104104 */
105105function indexedSearch ( query , parent , state , from , firstElementOnly ) {
106- var handle = state . index ? delay : add
107- var children = parent . children
108- var elements = 0
109- var index = - 1
106+ const handle = state . index ? delay : add
107+ const children = parent . children
108+ let elements = 0
109+ let index = - 1
110110 /** @type {Object.<string, number> } */
111- var types = { }
111+ const types = { }
112112 /** @type {Array.<Function> } */
113- var delayed = [ ]
114- /** @type {Node } */
115- var child
113+ const delayed = [ ]
116114
117115 // Start looking at `from`
118116 if ( from === undefined || from === null ) from = 0
@@ -123,15 +121,15 @@ function indexedSearch(query, parent, state, from, firstElementOnly) {
123121 // If we need to index for types, do so for all elements before `from`.
124122 if ( state . index ) {
125123 while ( ++ index < from ) {
126- child = children [ index ]
124+ const child = children [ index ]
127125 if ( element ( child ) ) count ( child . tagName )
128126 }
129127 }
130128
131129 index = from - 1
132130
133131 while ( ++ index < children . length ) {
134- child = children [ index ]
132+ const child = children [ index ]
135133 // Only check elements.
136134 // Check either all elements, or only check the first sibling
137135 if ( element ( child ) ) {
@@ -157,8 +155,8 @@ function indexedSearch(query, parent, state, from, firstElementOnly) {
157155 * @param {number } childIndex
158156 */
159157 function delay ( node , childIndex ) {
160- var elementsBefore = elements
161- var elementsByTypeBefore = own . call ( types , node . tagName )
158+ const elementsBefore = elements
159+ const elementsByTypeBefore = own . call ( types , node . tagName )
162160 ? types [ node . tagName ]
163161 : 0
164162
@@ -184,7 +182,7 @@ function indexedSearch(query, parent, state, from, firstElementOnly) {
184182 * @param {number } childIndex
185183 */
186184 function add ( node , childIndex ) {
187- var exit = enterState ( state , node )
185+ const exit = enterState ( state , node )
188186 state . iterator ( query , node , childIndex , parent , state )
189187 exit ( )
190188 }
0 commit comments