diff --git a/examples/html.ts b/examples/html.ts
index d931795..5c30148 100644
--- a/examples/html.ts
+++ b/examples/html.ts
@@ -12,6 +12,7 @@ import { obj } from './values.js'
const html = dump(obj, {
styles: themes.nightOwl,
+ inspectStaticMembers: true,
collapse: ['DateTime'],
})
diff --git a/examples/values.ts b/examples/values.ts
index bb2aa41..e12bcc4 100644
--- a/examples/values.ts
+++ b/examples/values.ts
@@ -36,6 +36,13 @@ class User {
return this.#attributes.username
}
+ static keys = {
+ a: 1,
+ b: 2,
+ }
+
+ static attributes = new Map([['id', { name: 'id' }]])
+
static booted = false
static boot() {
this.booted = true
diff --git a/formatters/console/printers/main.ts b/formatters/console/printers/main.ts
index 358e775..246e83e 100644
--- a/formatters/console/printers/main.ts
+++ b/formatters/console/printers/main.ts
@@ -47,7 +47,8 @@ export const ConsolePrinters: TokenPrinters = {
formatter.indentation.increment()
const styles = formatter.styles.objectLabel
const label =
- formatter.context.isStaticMember || token.constructorName === 'Object'
+ (formatter.context.isStaticMember && formatter.context.staticDepth === 0) ||
+ token.constructorName === 'Object'
? ''
: styles(`${token.constructorName || 'Object [null]'}`) + ' '
@@ -79,8 +80,11 @@ export const ConsolePrinters: TokenPrinters = {
*/
let prefix = ''
if (formatter.context.isStaticMember) {
- const prefixStyles = formatter.styles.objectKeyPrefix
- prefix = `${prefixStyles('static')} `
+ formatter.context.staticDepth++
+ if (formatter.context.staticDepth === 1) {
+ const prefixStyles = formatter.styles.objectKeyPrefix
+ prefix = `${prefixStyles('static')} `
+ }
}
return indent + prefix + styles(value) + ': '
@@ -105,7 +109,10 @@ export const ConsolePrinters: TokenPrinters = {
return ''
},
- 'object-value-end': () => {
+ 'object-value-end': (_, formatter) => {
+ if (formatter.context.isStaticMember) {
+ formatter.context.staticDepth--
+ }
return `,`
},
@@ -179,7 +186,7 @@ export const ConsolePrinters: TokenPrinters = {
'map-start': (token, formatter) => {
formatter.indentation.increment()
const styles = formatter.styles.mapLabel
- const label = `Map:${token.size} `
+ const label = `Map(${token.size}) `
return styles(label) + openingBrace(formatter)
},
@@ -248,7 +255,7 @@ export const ConsolePrinters: TokenPrinters = {
'set-start': (token, formatter) => {
formatter.indentation.increment()
const styles = formatter.styles.setLabel
- const label = `Set:${token.size} `
+ const label = `Set(${token.size}) `
return styles(label) + openingBrackets(formatter)
},
@@ -432,11 +439,13 @@ export const ConsolePrinters: TokenPrinters = {
'static-members-start': function (_, formatter): string {
formatter.context.isStaticMember = true
- return ''
+ formatter.context.staticDepth = 0
+ return ' '
},
'static-members-end': function (_, formatter): string {
formatter.context.isStaticMember = false
+ formatter.context.staticDepth = 0
return ''
},
}
diff --git a/formatters/html/printers/main.ts b/formatters/html/printers/main.ts
index 62ae506..3ad1fef 100644
--- a/formatters/html/printers/main.ts
+++ b/formatters/html/printers/main.ts
@@ -49,9 +49,10 @@ export const HTMLPrinters: TokenPrinters = {
formatter.indentation.increment()
const styles = formatter.styles.objectLabel
const toggleStyles = formatter.styles.toggle
- const label = formatter.context.isStaticMember
- ? ' '
- : `${token.constructorName || 'Object [null]'} `
+ const label =
+ formatter.context.isStaticMember && formatter.context.staticDepth === 0
+ ? ' '
+ : `${token.constructorName || 'Object [null]'} `
return (
'' +
@@ -91,8 +92,12 @@ export const HTMLPrinters: TokenPrinters = {
*/
let prefix = ''
if (formatter.context.isStaticMember) {
- const prefixStyles = formatter.styles.objectKeyPrefix
- prefix = `` + `static ` + ''
+ formatter.context.staticDepth++
+ if (formatter.context.staticDepth === 1) {
+ const prefixStyles = formatter.styles.objectKeyPrefix
+ prefix =
+ `` + `static ` + ''
+ }
}
return (
@@ -123,7 +128,10 @@ export const HTMLPrinters: TokenPrinters = {
return ''
},
- 'object-value-end': () => {
+ 'object-value-end': (_, formatter) => {
+ if (formatter.context.isStaticMember) {
+ formatter.context.staticDepth--
+ }
return `,`
},
@@ -504,11 +512,13 @@ export const HTMLPrinters: TokenPrinters = {
'static-members-start': function (_, formatter): string {
formatter.context.isStaticMember = true
+ formatter.context.staticDepth = 0
return ''
},
'static-members-end': function (_, formatter): string {
formatter.context.isStaticMember = false
+ formatter.context.staticDepth = 0
return ''
},
}