massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / debug / src / common.js
index 2f82b8dc7d886526e3faf1c5494516d4eafc9565..6d571d2844dd950db81c8e07cabbfc9048c59658 100644 (file)
@@ -12,16 +12,12 @@ function setup(env) {
        createDebug.enable = enable;
        createDebug.enabled = enabled;
        createDebug.humanize = require('ms');
+       createDebug.destroy = destroy;
 
        Object.keys(env).forEach(key => {
                createDebug[key] = env[key];
        });
 
-       /**
-       * Active `debug` instances.
-       */
-       createDebug.instances = [];
-
        /**
        * The currently active debug mode names, and names to skip.
        */
@@ -38,7 +34,7 @@ function setup(env) {
 
        /**
        * Selects a color for a debug namespace
-       * @param {String} namespace The namespace string for the for the debug instance to be colored
+       * @param {String} namespace The namespace string for the debug instance to be colored
        * @return {Number|String} An ANSI color code for the given namespace
        * @api private
        */
@@ -63,6 +59,9 @@ function setup(env) {
        */
        function createDebug(namespace) {
                let prevTime;
+               let enableOverride = null;
+               let namespacesCache;
+               let enabledCache;
 
                function debug(...args) {
                        // Disabled?
@@ -92,7 +91,7 @@ function setup(env) {
                        args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
                                // If we encounter an escaped % then don't increase the array index
                                if (match === '%%') {
-                                       return match;
+                                       return '%';
                                }
                                index++;
                                const formatter = createDebug.formatters[format];
@@ -115,33 +114,38 @@ function setup(env) {
                }
 
                debug.namespace = namespace;
-               debug.enabled = createDebug.enabled(namespace);
                debug.useColors = createDebug.useColors();
-               debug.color = selectColor(namespace);
-               debug.destroy = destroy;
+               debug.color = createDebug.selectColor(namespace);
                debug.extend = extend;
-               // Debug.formatArgs = formatArgs;
-               // debug.rawLog = rawLog;
+               debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
+
+               Object.defineProperty(debug, 'enabled', {
+                       enumerable: true,
+                       configurable: false,
+                       get: () => {
+                               if (enableOverride !== null) {
+                                       return enableOverride;
+                               }
+                               if (namespacesCache !== createDebug.namespaces) {
+                                       namespacesCache = createDebug.namespaces;
+                                       enabledCache = createDebug.enabled(namespace);
+                               }
 
-               // env-specific initialization logic for debug instances
+                               return enabledCache;
+                       },
+                       set: v => {
+                               enableOverride = v;
+                       }
+               });
+
+               // Env-specific initialization logic for debug instances
                if (typeof createDebug.init === 'function') {
                        createDebug.init(debug);
                }
 
-               createDebug.instances.push(debug);
-
                return debug;
        }
 
-       function destroy() {
-               const index = createDebug.instances.indexOf(this);
-               if (index !== -1) {
-                       createDebug.instances.splice(index, 1);
-                       return true;
-               }
-               return false;
-       }
-
        function extend(namespace, delimiter) {
                const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
                newDebug.log = this.log;
@@ -157,6 +161,7 @@ function setup(env) {
        */
        function enable(namespaces) {
                createDebug.save(namespaces);
+               createDebug.namespaces = namespaces;
 
                createDebug.names = [];
                createDebug.skips = [];
@@ -179,11 +184,6 @@ function setup(env) {
                                createDebug.names.push(new RegExp('^' + namespaces + '$'));
                        }
                }
-
-               for (i = 0; i < createDebug.instances.length; i++) {
-                       const instance = createDebug.instances[i];
-                       instance.enabled = createDebug.enabled(instance.namespace);
-               }
        }
 
        /**
@@ -258,6 +258,14 @@ function setup(env) {
                return val;
        }
 
+       /**
+       * XXX DO NOT USE. This is a temporary stub function.
+       * XXX It WILL be removed in the next major release.
+       */
+       function destroy() {
+               console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
+       }
+
        createDebug.enable(createDebug.load());
 
        return createDebug;