Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove es6 code from the browser version #672

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
"license": "MIT",
"scripts": {
"lint": "xo",
"test": "npm run test:node && npm run test:browser",
"test": "npm run test:es5compat && npm run test:node && npm run test:browser",
"test:node": "istanbul cover _mocha -- test.js",
"test:browser": "karma start --single-run",
"test:coverage": "cat ./coverage/lcov.info | coveralls"
"test:coverage": "cat ./coverage/lcov.info | coveralls",
"test:es5compat": "browserify src/browser.js | uglifyjs > /dev/null"
},
"dependencies": {
"ms": "^2.1.1"
Expand All @@ -44,8 +45,17 @@
"karma-mocha": "^1.3.0",
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.2.0",
"uglify-js": "^3.4.9",
"xo": "^0.23.0"
},
"main": "./src/index.js",
"browser": "./src/browser.js"
"browser": "./src/browser.js",
"xo": {
"rules": {
"no-var": 0,
"prefer-arrow-callback": 0,
"prefer-destructuring": 0,
"prefer-rest-params": 0
}
}
}
14 changes: 7 additions & 7 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ function formatArgs(args) {
return;
}

const c = 'color: ' + this.color;
var c = 'color: ' + this.color;
args.splice(1, 0, c, 'color: inherit');

// The final "%c" is somewhat tricky, because there could be other
// arguments passed either before or after the %c, so we need to
// figure out the correct index to insert the CSS into
let index = 0;
let lastC = 0;
args[0].replace(/%[a-zA-Z%]/g, match => {
var index = 0;
var lastC = 0;
args[0].replace(/%[a-zA-Z%]/g, function (match) {
if (match === '%%') {
return;
}
Expand All @@ -176,7 +176,7 @@ function formatArgs(args) {
*
* @api public
*/
exports.log = console.debug || console.log || (() => {});
exports.log = console.debug || console.log || function () {};

/**
* Save `namespaces`.
Expand Down Expand Up @@ -204,7 +204,7 @@ function save(namespaces) {
* @api private
*/
function load() {
let r;
var r;
try {
r = exports.storage.getItem('debug');
} catch (error) {
Expand Down Expand Up @@ -244,7 +244,7 @@ function localstorage() {

module.exports = require('./common')(exports);

const {formatters} = module.exports;
var formatters = module.exports.formatters;

/**
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
Expand Down
56 changes: 29 additions & 27 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function setup(env) {
createDebug.enabled = enabled;
createDebug.humanize = require('ms');

Object.keys(env).forEach(key => {
Object.keys(env).forEach(function (key) {
createDebug[key] = env[key];
});

Expand All @@ -32,7 +32,7 @@ function setup(env) {
/**
* Map of special "%n" handling functions, for the debug "format" argument.
*
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
* Valid key names are a single, lower or upper-case varter, i.e. "n" and "N".
*/
createDebug.formatters = {};

Expand All @@ -43,9 +43,9 @@ function setup(env) {
* @api private
*/
function selectColor(namespace) {
let hash = 0;
var hash = 0;

for (let i = 0; i < namespace.length; i++) {
for (var i = 0; i < namespace.length; i++) {
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
hash |= 0; // Convert to 32bit integer
}
Expand All @@ -62,19 +62,20 @@ function setup(env) {
* @api public
*/
function createDebug(namespace) {
let prevTime;
var prevTime;

function debug(...args) {
function debug() {
var args = Array.prototype.slice.call(arguments);
// Disabled?
if (!debug.enabled) {
return;
}

const self = debug;
var self = debug;

// Set `diff` timestamp
const curr = Number(new Date());
const ms = curr - (prevTime || curr);
var curr = Number(new Date());
var ms = curr - (prevTime || curr);
self.diff = ms;
self.prev = prevTime;
self.curr = curr;
Expand All @@ -83,21 +84,21 @@ function setup(env) {
args[0] = createDebug.coerce(args[0]);

if (typeof args[0] !== 'string') {
// Anything else let's inspect with %O
// Anything else var's inspect with %O
args.unshift('%O');
}

// Apply any `formatters` transformations
let index = 0;
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
var index = 0;
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
// If we encounter an escaped % then don't increase the array index
if (match === '%%') {
return match;
}
index++;
const formatter = createDebug.formatters[format];
var formatter = createDebug.formatters[format];
if (typeof formatter === 'function') {
const val = args[index];
var val = args[index];
match = formatter.call(self, val);

// Now we need to remove `args[index]` since it's inlined in the `format`
Expand All @@ -110,7 +111,7 @@ function setup(env) {
// Apply env-specific formatting (colors, etc.)
createDebug.formatArgs.call(self, args);

const logFn = self.log || createDebug.log;
var logFn = self.log || createDebug.log;
logFn.apply(self, args);
}

Expand All @@ -134,7 +135,7 @@ function setup(env) {
}

function destroy() {
const index = createDebug.instances.indexOf(this);
var index = createDebug.instances.indexOf(this);
if (index !== -1) {
createDebug.instances.splice(index, 1);
return true;
Expand All @@ -143,7 +144,7 @@ function setup(env) {
}

function extend(namespace, delimiter) {
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
newDebug.log = this.log;
return newDebug;
}
Expand All @@ -161,9 +162,9 @@ function setup(env) {
createDebug.names = [];
createDebug.skips = [];

let i;
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
const len = split.length;
var i;
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
var len = split.length;

for (i = 0; i < len; i++) {
if (!split[i]) {
Expand All @@ -181,7 +182,7 @@ function setup(env) {
}

for (i = 0; i < createDebug.instances.length; i++) {
const instance = createDebug.instances[i];
var instance = createDebug.instances[i];
instance.enabled = createDebug.enabled(instance.namespace);
}
}
Expand All @@ -193,10 +194,11 @@ function setup(env) {
* @api public
*/
function disable() {
const namespaces = [
...createDebug.names.map(toNamespace),
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
].join(',');
var namespaces = createDebug.names.map(toNamespace).concat(
createDebug.skips.map(toNamespace).map(function (namespace) {
return '-' + namespace;
})
).join(',');
createDebug.enable('');
return namespaces;
}
Expand All @@ -213,8 +215,8 @@ function setup(env) {
return true;
}

let i;
let len;
var i;
var len;

for (i = 0, len = createDebug.skips.length; i < len; i++) {
if (createDebug.skips[i].test(name)) {
Expand Down