Skip to content

Commit 83e1f7b

Browse files
committed
store stylization functions in state
1 parent 359110c commit 83e1f7b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* Info passed around.
2424
* @property {boolean} showPositions
2525
* Whether to include positional information.
26+
* @property {Style} style
27+
* Rendering stylization.
2628
*/
2729

2830
import {color} from 'unist-util-inspect/do-not-use-conditional-color'
@@ -42,16 +44,6 @@ export const inspect = color ? inspectColor : inspectNoColor
4244

4345
const own = {}.hasOwnProperty
4446

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-
5547
// ANSI color regex.
5648
/* eslint-disable no-control-regex */
5749
const colorExpression =
@@ -85,6 +77,12 @@ export function inspectNoColor(tree, options) {
8577
export function inspectColor(tree, options) {
8678
/** @type {State} */
8779
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+
},
8886
showPositions:
8987
!options ||
9088
options.showPositions === null ||
@@ -141,6 +139,7 @@ function inspectNonTree(value) {
141139
* Formatted nodes.
142140
*/
143141
function inspectNodes(nodes, state) {
142+
const style = state.style
144143
const size = String(nodes.length - 1).length
145144
/** @type {Array<string>} */
146145
const result = []
@@ -178,6 +177,8 @@ function inspectNodes(nodes, state) {
178177
*/
179178
// eslint-disable-next-line complexity
180179
function inspectFields(object, state) {
180+
const style = state.style
181+
181182
/** @type {Array<string>} */
182183
const result = []
183184
/** @type {string} */
@@ -273,6 +274,7 @@ function inspectTree(node, state) {
273274
* Formatted node.
274275
*/
275276
function formatNode(node, state) {
277+
const style = state.style
276278
const result = [style.bold(node.type)]
277279
// Cast as record to allow indexing.
278280
const map = /** @type {Record<string, unknown>} */ (

0 commit comments

Comments
 (0)