From a6a3fa9cc0661715d0609cf16ecef6fdf6ab07e5 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Fri, 22 Nov 2024 11:44:22 -0800 Subject: [PATCH 1/3] Tweak rendering of object keys. --- src/loggy-intf/private/HumanVisitor.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/loggy-intf/private/HumanVisitor.js b/src/loggy-intf/private/HumanVisitor.js index d2096509..443fc080 100644 --- a/src/loggy-intf/private/HumanVisitor.js +++ b/src/loggy-intf/private/HumanVisitor.js @@ -178,11 +178,24 @@ export class HumanVisitor extends BaseValueVisitor { * @returns {TypeText} The rendered form. */ #renderKey(key) { - if ((typeof key === 'string') && /^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(key)) { - // It doesn't have to be quoted. - return `${key}:`; + if (typeof key === 'string') { + if (/^([$_a-zA-Z][$_a-zA-Z0-9]*|[1-9][0-9]{0,15}|0)$/.test(key)) { + // It doesn't have to be quoted. + return `${key}:`; + } else if (/^-[1-9][0-9]{0,15}$/.test(key)) { + // It can be treated like a negative numeric literal. + return `[${key}]:`; + } else { + // It needs to be quoted. + return `${util.inspect(key)}:`; + } } else { - return new ComboText(this._impl_visitString(key), ':'); + // A non-string, perhaps a symbol, however as of this writing this case + // isn't used. + return new ComboText( + '[', ComboText.NO_BREAK, + this._prot_visitSync(key), + ComboText.NO_BREAK, ']:'); } } From 5c330a59e21a44796bc5285eff179a3903d1a792 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Fri, 22 Nov 2024 11:47:34 -0800 Subject: [PATCH 2/3] Changelog. --- CHANGELOG.md | 9 +++++++-- src/host/export/ProductInfo.js | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1accb1eb..f9d2d400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,8 +17,13 @@ Other notable changes: * general: * Allow node version 23. * `loggy-intf` / `loggy`: - * Made several improvements to "human" (non-JSON) log rendering, including - fixing it to be able to log values with reference cycles. + * Improved the data model used to encode logged items, including: + * Representing functions and classes as structured objects instead of just + strings. + * Making it possible to encode values with reference cycles. + * Improved "human" (non-JSON) log rendering, including: + * Correctly rendering shared references. + * Tweaking the styling for readability. * `structy`: * Started allowing any object (plain or not) to be used as the argument to the `BaseStruct` constructor. diff --git a/src/host/export/ProductInfo.js b/src/host/export/ProductInfo.js index d6444e27..ae392e8d 100644 --- a/src/host/export/ProductInfo.js +++ b/src/host/export/ProductInfo.js @@ -50,6 +50,7 @@ export class ProductInfo { static init() { this.#extractInfo(); ThisModule.logger?.productInfo(this.#info); + ThisModule.logger?.HELLO_THERE({ abc: 'boop', 'cd-ef': 'floop', 97: 'zoop', [-123]: 'doop' }); } /** From 7b30c38b044b48afc0492b3b19f4ff3cb6fdd422 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Fri, 22 Nov 2024 11:51:55 -0800 Subject: [PATCH 3/3] Remove debug code. --- src/host/export/ProductInfo.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/host/export/ProductInfo.js b/src/host/export/ProductInfo.js index ae392e8d..d6444e27 100644 --- a/src/host/export/ProductInfo.js +++ b/src/host/export/ProductInfo.js @@ -50,7 +50,6 @@ export class ProductInfo { static init() { this.#extractInfo(); ThisModule.logger?.productInfo(this.#info); - ThisModule.logger?.HELLO_THERE({ abc: 'boop', 'cd-ef': 'floop', 97: 'zoop', [-123]: 'doop' }); } /**