10
10
import { color } from './color.js'
11
11
12
12
/* c8 ignore next */
13
- export var inspect = color ? inspectColor : inspectNoColor
13
+ export const inspect = color ? inspectColor : inspectNoColor
14
14
15
- var own = { } . hasOwnProperty
15
+ const own = { } . hasOwnProperty
16
16
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 )
21
21
22
22
// ANSI color regex.
23
23
/* eslint-disable no-control-regex */
24
- var colorExpression =
24
+ const colorExpression =
25
25
/ (?: (?: \u001B \[ ) | \u009B ) (?: \d { 1 , 3 } ) ? (?: (?: ; \d { 0 , 3 } ) * ) ? [ A - M | f - m ] | \u001B [ A - M ] / g
26
26
/* eslint-enable no-control-regex */
27
27
@@ -43,11 +43,9 @@ export function inspectNoColor(node, options) {
43
43
* @param {InspectOptions } [options]
44
44
* @returns {string }
45
45
*/
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
51
49
? true
52
50
: options . showPositions
53
51
@@ -86,8 +84,8 @@ export function inspectColor(tree, options) {
86
84
*/
87
85
function inspectNodes ( nodes ) {
88
86
/** @type {Array.<string> } */
89
- var result = [ ]
90
- var index = - 1
87
+ const result = [ ]
88
+ let index = - 1
91
89
92
90
while ( ++ index < nodes . length ) {
93
91
result . push (
@@ -108,21 +106,20 @@ export function inspectColor(tree, options) {
108
106
* @param {Object.<string, unknown> } object
109
107
* @returns {string }
110
108
*/
109
+ // eslint-disable-next-line complexity
111
110
function inspectFields ( object ) {
112
111
/** @type {Array.<string> } */
113
- var result = [ ]
112
+ const result = [ ]
114
113
/** @type {string } */
115
- var key
116
- /** @type {unknown } */
117
- var value
118
- /** @type {string } */
119
- var formatted
114
+ let key
120
115
121
116
for ( key in object ) {
122
117
/* c8 ignore next 1 */
123
118
if ( ! own . call ( object , key ) ) continue
124
119
125
- value = object [ key ]
120
+ const value = object [ key ]
121
+ /** @type {string } */
122
+ let formatted
126
123
127
124
if (
128
125
value === undefined ||
@@ -182,11 +179,11 @@ export function inspectColor(tree, options) {
182
179
* @returns {string }
183
180
*/
184
181
function inspectTree ( node ) {
185
- var result = [ formatNode ( node ) ]
182
+ const result = [ formatNode ( node ) ]
186
183
// @ts -expect-error: looks like a record.
187
- var fields = inspectFields ( node )
184
+ const fields = inspectFields ( node )
188
185
// @ts -ignore looks like a parent.
189
- var content = inspectNodes ( node . children || [ ] )
186
+ const content = inspectNodes ( node . children || [ ] )
190
187
if ( fields ) result . push ( fields )
191
188
if ( content ) result . push ( content )
192
189
return result . join ( '\n' )
@@ -199,11 +196,11 @@ export function inspectColor(tree, options) {
199
196
* @returns {string }
200
197
*/
201
198
function formatNode ( node ) {
202
- var result = [ bold ( node . type ) ]
203
- /** @type {string } */
199
+ const result = [ bold ( node . type ) ]
200
+ /** @type {string|undefined } */
204
201
// @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 ) : ''
207
204
208
205
if ( typeof kind === 'string' ) {
209
206
result . push ( '<' , kind , '>' )
@@ -234,8 +231,8 @@ export function inspectColor(tree, options) {
234
231
* @returns {string }
235
232
*/
236
233
function 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
239
236
240
237
if ( ! value ) return value
241
238
@@ -253,13 +250,13 @@ function indent(value, indentation, ignoreFirst) {
253
250
function stringifyPosition ( value ) {
254
251
/** @type {Position } */
255
252
// @ts -ignore
256
- var position = value || { }
253
+ const position = value || { }
257
254
/** @type {Array.<string> } */
258
- var result = [ ]
255
+ const result = [ ]
259
256
/** @type {Array.<string> } */
260
- var positions = [ ]
257
+ const positions = [ ]
261
258
/** @type {Array.<string> } */
262
- var offsets = [ ]
259
+ const offsets = [ ]
263
260
264
261
point ( position . start )
265
262
point ( position . end )
0 commit comments