Skip to content

Commit

Permalink
lib: refactor debuglog init
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed May 29, 2021
1 parent bbab59d commit 102f98e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const {
FunctionPrototypeBind,
ObjectCreate,
ObjectDefineProperty,
RegExp,
RegExpPrototypeTest,
RegExpPrototypeExec,
SafeArrayIterator,
StringPrototypeToLowerCase,
StringPrototypeToUpperCase,
Expand All @@ -17,20 +16,19 @@ const { inspect, format, formatWithOptions } = require('internal/util/inspect');
// debuglog() before initializeDebugEnv() is called will throw.
let debugImpls;

let debugEnvRegex = /^$/;
let testEnabled;
let testEnabled = () => false;

// `debugEnv` is initial value of process.env.NODE_DEBUG
function initializeDebugEnv(debugEnv) {
debugImpls = ObjectCreate(null);
if (debugEnv) {
// This is run before any user code, it's OK not to use primordials.
debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&')
.replace(/\*/g, '.*')
.replace(/,/g, '$|^')
.toUpperCase();
debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
.replaceAll('*', '.*')
.replaceAll(',', '$|^');
const debugEnvRegex = new RegExp(`^${debugEnv}$`, 'i');
testEnabled = (str) => RegExpPrototypeExec(debugEnvRegex, str) !== null;
}
testEnabled = FunctionPrototypeBind(RegExpPrototypeTest, null, debugEnvRegex);
}

// Emits warning when user sets
Expand Down

0 comments on commit 102f98e

Please sign in to comment.