Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a86c54c

Browse files
eps1lonDavidRieman
andauthored
feat: Reduce caught exceptions in prettyDom (reland) (#1323)
Co-authored-by: David Rieman <DavidRieman@users.noreply.github.com> Co-authored-by: David Rieman <david.rieman@wbd.com>
1 parent 33555a3 commit a86c54c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

‎src/pretty-dom.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ import {getDocument} from './helpers'
55
import {getConfig} from './config'
66

77
const shouldHighlight = () => {
8+
if (typeof process === 'undefined') {
9+
// Don't colorize in non-node environments (e.g. Browsers)
10+
return false
11+
}
812
let colors
13+
// Try to safely parse env COLORS: We will default behavior if any step fails.
914
try {
10-
colors = JSON.parse(process?.env?.COLORS)
11-
} catch (e) {
12-
// If this throws, process?.env?.COLORS wasn't parsable. Since we only
15+
const colorsJSON = process.env?.COLORS
16+
if (colorsJSON) {
17+
colors = JSON.parse(colorsJSON)
18+
}
19+
} catch {
20+
// If this throws, process.env?.COLORS wasn't parsable. Since we only
1321
// care about `true` or `false`, we can safely ignore the error.
1422
}
1523

@@ -18,11 +26,7 @@ const shouldHighlight = () => {
1826
return colors
1927
} else {
2028
// If `colors` is not set, colorize if we're in node.
21-
return (
22-
typeof process !== 'undefined' &&
23-
process.versions !== undefined &&
24-
process.versions.node !== undefined
25-
)
29+
return process.versions !== undefined && process.versions.node !== undefined
2630
}
2731
}
2832

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /