23
23
* Info passed around.
24
24
* @property {boolean } showPositions
25
25
* Whether to include positional information.
26
+ * @property {Style } style
27
+ * Rendering stylization.
26
28
*/
27
29
28
30
import { color } from 'unist-util-inspect/do-not-use-conditional-color'
@@ -42,16 +44,6 @@ export const inspect = color ? inspectColor : inspectNoColor
42
44
43
45
const own = { } . hasOwnProperty
44
46
45
- /**
46
- * @type Style
47
- */
48
- const style = {
49
- bold : ansiColor ( 1 , 22 ) ,
50
- dim : ansiColor ( 2 , 22 ) ,
51
- yellow : ansiColor ( 33 , 39 ) ,
52
- green : ansiColor ( 32 , 39 )
53
- }
54
-
55
47
// ANSI color regex.
56
48
/* eslint-disable no-control-regex */
57
49
const colorExpression =
@@ -85,6 +77,12 @@ export function inspectNoColor(tree, options) {
85
77
export function inspectColor ( tree , options ) {
86
78
/** @type {State } */
87
79
const state = {
80
+ style : {
81
+ bold : ansiColor ( 1 , 22 ) ,
82
+ dim : ansiColor ( 2 , 22 ) ,
83
+ yellow : ansiColor ( 33 , 39 ) ,
84
+ green : ansiColor ( 32 , 39 )
85
+ } ,
88
86
showPositions :
89
87
! options ||
90
88
options . showPositions === null ||
@@ -141,6 +139,7 @@ function inspectNonTree(value) {
141
139
* Formatted nodes.
142
140
*/
143
141
function inspectNodes ( nodes , state ) {
142
+ const style = state . style
144
143
const size = String ( nodes . length - 1 ) . length
145
144
/** @type {Array<string> } */
146
145
const result = [ ]
@@ -178,6 +177,8 @@ function inspectNodes(nodes, state) {
178
177
*/
179
178
// eslint-disable-next-line complexity
180
179
function inspectFields ( object , state ) {
180
+ const style = state . style
181
+
181
182
/** @type {Array<string> } */
182
183
const result = [ ]
183
184
/** @type {string } */
@@ -273,6 +274,7 @@ function inspectTree(node, state) {
273
274
* Formatted node.
274
275
*/
275
276
function formatNode ( node , state ) {
277
+ const style = state . style
276
278
const result = [ style . bold ( node . type ) ]
277
279
// Cast as record to allow indexing.
278
280
const map = /** @type {Record<string, unknown> } */ (
0 commit comments