1010import { color } from './color.js'
1111
1212/* c8 ignore next */
13- export var inspect = color ? inspectColor : inspectNoColor
13+ export const inspect = color ? inspectColor : inspectNoColor
1414
15- var own = { } . hasOwnProperty
15+ const own = { } . hasOwnProperty
1616
17- var bold = ansiColor ( 1 , 22 )
18- var dim = ansiColor ( 2 , 22 )
19- var yellow = ansiColor ( 33 , 39 )
20- var green = ansiColor ( 32 , 39 )
17+ const bold = ansiColor ( 1 , 22 )
18+ const dim = ansiColor ( 2 , 22 )
19+ const yellow = ansiColor ( 33 , 39 )
20+ const green = ansiColor ( 32 , 39 )
2121
2222// ANSI color regex.
2323/* eslint-disable no-control-regex */
24- var colorExpression =
24+ const colorExpression =
2525 / (?: (?: \u001B \[ ) | \u009B ) (?: \d { 1 , 3 } ) ? (?: (?: ; \d { 0 , 3 } ) * ) ? [ A - M | f - m ] | \u001B [ A - M ] / g
2626/* eslint-enable no-control-regex */
2727
@@ -43,11 +43,9 @@ export function inspectNoColor(node, options) {
4343 * @param {InspectOptions } [options]
4444 * @returns {string }
4545 */
46- export function inspectColor ( tree , options ) {
47- var positions =
48- ! options ||
49- options . showPositions === null ||
50- options . showPositions === undefined
46+ export function inspectColor ( tree , options = { } ) {
47+ const positions =
48+ options . showPositions === null || options . showPositions === undefined
5149 ? true
5250 : options . showPositions
5351
@@ -86,8 +84,8 @@ export function inspectColor(tree, options) {
8684 */
8785 function inspectNodes ( nodes ) {
8886 /** @type {Array.<string> } */
89- var result = [ ]
90- var index = - 1
87+ const result = [ ]
88+ let index = - 1
9189
9290 while ( ++ index < nodes . length ) {
9391 result . push (
@@ -108,21 +106,20 @@ export function inspectColor(tree, options) {
108106 * @param {Object.<string, unknown> } object
109107 * @returns {string }
110108 */
109+ // eslint-disable-next-line complexity
111110 function inspectFields ( object ) {
112111 /** @type {Array.<string> } */
113- var result = [ ]
112+ const result = [ ]
114113 /** @type {string } */
115- var key
116- /** @type {unknown } */
117- var value
118- /** @type {string } */
119- var formatted
114+ let key
120115
121116 for ( key in object ) {
122117 /* c8 ignore next 1 */
123118 if ( ! own . call ( object , key ) ) continue
124119
125- value = object [ key ]
120+ const value = object [ key ]
121+ /** @type {string } */
122+ let formatted
126123
127124 if (
128125 value === undefined ||
@@ -182,11 +179,11 @@ export function inspectColor(tree, options) {
182179 * @returns {string }
183180 */
184181 function inspectTree ( node ) {
185- var result = [ formatNode ( node ) ]
182+ const result = [ formatNode ( node ) ]
186183 // @ts -expect-error: looks like a record.
187- var fields = inspectFields ( node )
184+ const fields = inspectFields ( node )
188185 // @ts -ignore looks like a parent.
189- var content = inspectNodes ( node . children || [ ] )
186+ const content = inspectNodes ( node . children || [ ] )
190187 if ( fields ) result . push ( fields )
191188 if ( content ) result . push ( content )
192189 return result . join ( '\n' )
@@ -199,11 +196,11 @@ export function inspectColor(tree, options) {
199196 * @returns {string }
200197 */
201198 function formatNode ( node ) {
202- var result = [ bold ( node . type ) ]
203- /** @type {string } */
199+ const result = [ bold ( node . type ) ]
200+ /** @type {string|undefined } */
204201 // @ts -expect-error: might be available.
205- var kind = node . tagName || node . name
206- var position = positions ? stringifyPosition ( node . position ) : ''
202+ const kind = node . tagName || node . name
203+ const position = positions ? stringifyPosition ( node . position ) : ''
207204
208205 if ( typeof kind === 'string' ) {
209206 result . push ( '<' , kind , '>' )
@@ -234,8 +231,8 @@ export function inspectColor(tree, options) {
234231 * @returns {string }
235232 */
236233function indent ( value , indentation , ignoreFirst ) {
237- var lines = value . split ( '\n' )
238- var index = ignoreFirst ? 0 : - 1
234+ const lines = value . split ( '\n' )
235+ let index = ignoreFirst ? 0 : - 1
239236
240237 if ( ! value ) return value
241238
@@ -253,13 +250,13 @@ function indent(value, indentation, ignoreFirst) {
253250function stringifyPosition ( value ) {
254251 /** @type {Position } */
255252 // @ts -ignore
256- var position = value || { }
253+ const position = value || { }
257254 /** @type {Array.<string> } */
258- var result = [ ]
255+ const result = [ ]
259256 /** @type {Array.<string> } */
260- var positions = [ ]
257+ const positions = [ ]
261258 /** @type {Array.<string> } */
262- var offsets = [ ]
259+ const offsets = [ ]
263260
264261 point ( position . start )
265262 point ( position . end )
0 commit comments