Merge pull request #8 from electron/felixr-optional-chaining

fix: Handle optional chaining
This commit is contained in:
Felix Rieseberg 2024-10-07 08:57:08 -07:00 committed by GitHub
commit 9abc964e4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -93,11 +93,11 @@ class Logger {
} }
set level (level) { set level (level) {
this.#level = this.#levels.get(level)?.id || null this.#level = (this.#levels.get(level) && this.#levels.get(level).id) || null
} }
isVisible (level) { isVisible (level) {
return this.level?.index <= this.#levels.get(level)?.index || -1 return (this.level && this.level.index <= (this.#levels.get(level) && this.#levels.get(level).index)) || -1
} }
#onLog (...args) { #onLog (...args) {
@ -124,7 +124,7 @@ class Logger {
} }
#color (str, { fg, bg, inverse }) { #color (str, { fg, bg, inverse }) {
if (!this.#stream?.isTTY) { if (!this.#stream || !this.#stream.isTTY) {
return str return str
} }
@ -136,7 +136,7 @@ class Logger {
} }
#log (levelId, msgPrefix, ...args) { #log (levelId, msgPrefix, ...args) {
if (!this.isVisible(levelId) || typeof this.#stream?.write !== 'function') { if (!this.isVisible(levelId) || (this.#stream && typeof this.#stream.write !== 'function')) {
return return
} }