From 4dd1150ee987ed42eac40d89eb3f51099166700f Mon Sep 17 00:00:00 2001 From: Brendan Kenny Date: Tue, 24 Jan 2017 14:18:59 -0800 Subject: [PATCH] use rest parameters instead of arguments now possible by dropping support for node older than v6 --- .eslintrc.js | 2 -- lighthouse-cli/test/global-mocha-hooks.js | 4 ++-- lighthouse-core/gather/driver.js | 6 ++--- lighthouse-core/lib/console-quieter.js | 12 +++++----- lighthouse-core/lib/log.js | 26 ++++++++++++---------- lighthouse-core/report/report-generator.js | 6 ++--- lighthouse-core/test/global-mocha-hooks.js | 4 ++-- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 020f8ff402c2..0f2def50d210 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -44,8 +44,6 @@ module.exports = { "valid-jsdoc": 0, "comma-dangle": 0, "arrow-parens": 0, - // Compat: support for rest params is behind a flag for node v5.x - "prefer-rest-params": 0, }, "parserOptions": { "ecmaVersion": 6, diff --git a/lighthouse-cli/test/global-mocha-hooks.js b/lighthouse-cli/test/global-mocha-hooks.js index 4f14eefeff1e..8cdd95ff568c 100644 --- a/lighthouse-cli/test/global-mocha-hooks.js +++ b/lighthouse-cli/test/global-mocha-hooks.js @@ -15,11 +15,11 @@ Object.keys(assert) .filter(key => typeof assert[key] === 'function') .forEach(key => { const _origFn = assert[key]; - assert[key] = function() { + assert[key] = function(...args) { if (currTest) { currTest._assertions++; } - return _origFn.apply(this, arguments); + return _origFn.apply(this, args); }; } ); diff --git a/lighthouse-core/gather/driver.js b/lighthouse-core/gather/driver.js index 57849a7ec9e8..639ee8eb1c79 100644 --- a/lighthouse-core/gather/driver.js +++ b/lighthouse-core/gather/driver.js @@ -801,11 +801,9 @@ function captureJSCallUsage(funcRef, set) { const originalFunc = funcRef; const originalPrepareStackTrace = __nativeError.prepareStackTrace; - return function() { + return function(...args) { // Note: this function runs in the context of the page that is being audited. - const args = [...arguments]; // callee's arguments. - // See v8's Stack Trace API https://github.com/v8/v8/wiki/Stack-Trace-API#customizing-stack-traces __nativeError.prepareStackTrace = function(error, structStackTrace) { // First frame is the function we injected (the one that just threw). @@ -850,7 +848,7 @@ function captureJSCallUsage(funcRef, set) { __nativeError.prepareStackTrace = originalPrepareStackTrace; // eslint-disable-next-line no-invalid-this - return originalFunc.apply(this, arguments); + return originalFunc.apply(this, args); }; } diff --git a/lighthouse-core/lib/console-quieter.js b/lighthouse-core/lib/console-quieter.js index 055428ddf589..0a94dabcc6fd 100644 --- a/lighthouse-core/lib/console-quieter.js +++ b/lighthouse-core/lib/console-quieter.js @@ -26,14 +26,14 @@ class ConsoleQuieter { static mute(opts) { ConsoleQuieter._logs = ConsoleQuieter._logs || []; - console.log = function() { - ConsoleQuieter._logs.push({type: 'log', args: arguments, prefix: opts.prefix}); + console.log = function(...args) { + ConsoleQuieter._logs.push({type: 'log', args: args, prefix: opts.prefix}); }; - console.warn = function() { - ConsoleQuieter._logs.push({type: 'warn', args: arguments, prefix: opts.prefix}); + console.warn = function(...args) { + ConsoleQuieter._logs.push({type: 'warn', args: args, prefix: opts.prefix}); }; - console.error = function() { - ConsoleQuieter._logs.push({type: 'error', args: arguments, prefix: opts.prefix}); + console.error = function(...args) { + ConsoleQuieter._logs.push({type: 'error', args: args, prefix: opts.prefix}); }; } diff --git a/lighthouse-core/lib/log.js b/lighthouse-core/lib/log.js index 62ba8bbd3876..00df0e8d68d2 100644 --- a/lighthouse-core/lib/log.js +++ b/lighthouse-core/lib/log.js @@ -40,8 +40,9 @@ class Emitter extends EventEmitter { * Fires off all status updates. Listen with * `require('lib/log').events.addListener('status', callback)` * @param {string} title + * @param {...*} args */ - issueStatus(title, args) { + issueStatus(title, ...args) { if (title === 'status' || title === 'statusEnd') { this.emit(title, args); } @@ -50,8 +51,9 @@ class Emitter extends EventEmitter { /** * Fires off all warnings. Listen with * `require('lib/log').events.addListener('warning', callback)` + * @param {...*} args */ - issueWarning(args) { + issueWarning(...args) { this.emit('warning', args); } } @@ -113,23 +115,23 @@ class Log { Log._logToStdErr(`${prefix}:${level || ''}`, [data.method, snippet]); } - static log(title) { - Log.events.issueStatus(title, arguments); - return Log._logToStdErr(title, Array.from(arguments).slice(1)); + static log(title, ...args) { + Log.events.issueStatus(title, ...args); + return Log._logToStdErr(title, args); } - static warn(title) { - Log.events.issueWarning(arguments); - return Log._logToStdErr(`${title}:warn`, Array.from(arguments).slice(1)); + static warn(title, ...args) { + Log.events.issueWarning(title, ...args); + return Log._logToStdErr(`${title}:warn`, args); } - static error(title) { - return Log._logToStdErr(`${title}:error`, Array.from(arguments).slice(1)); + static error(title, ...args) { + return Log._logToStdErr(`${title}:error`, args); } - static verbose(title) { + static verbose(title, ...args) { Log.events.issueStatus(title); - return Log._logToStdErr(`${title}:verbose`, Array.from(arguments).slice(1)); + return Log._logToStdErr(`${title}:verbose`, args); } /** diff --git a/lighthouse-core/report/report-generator.js b/lighthouse-core/report/report-generator.js index ba0a78de57ea..33083116290c 100644 --- a/lighthouse-core/report/report-generator.js +++ b/lighthouse-core/report/report-generator.js @@ -101,10 +101,10 @@ class ReportGenerator { }); // arg1 && arg2 && ... && argn - Handlebars.registerHelper('and', function() { + Handlebars.registerHelper('and', function(...args) { let arg = false; - for (let i = 0, n = arguments.length - 1; i < n; i++) { - arg = arguments[i]; + for (let i = 0, n = args.length - 1; i < n; i++) { + arg = args[i]; if (!arg) { break; } diff --git a/lighthouse-core/test/global-mocha-hooks.js b/lighthouse-core/test/global-mocha-hooks.js index 371fc60bfefc..ea8433af5ea0 100644 --- a/lighthouse-core/test/global-mocha-hooks.js +++ b/lighthouse-core/test/global-mocha-hooks.js @@ -16,11 +16,11 @@ Object.keys(assert) .filter(key => typeof assert[key] === 'function') .forEach(key => { const _origFn = assert[key]; - assert[key] = function() { + assert[key] = function(...args) { if (currTest) { currTest._assertions++; } - return _origFn.apply(this, arguments); + return _origFn.apply(this, args); }; } );