[Pkg-javascript-commits] [node-tap] 13/186: More classy arrowy refactoring

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 16:40:39 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-tap.

commit eadc0acdaf44c555601ced42ebd2afd147da7b45
Author: isaacs <i at izs.me>
Date:   Tue Aug 1 14:02:02 2017 -0700

    More classy arrowy refactoring
---
 lib/parse-test-args.js | 22 +++++++++-------------
 lib/point.js           | 21 ++++++++++++---------
 lib/stack.js           | 12 ++++++------
 lib/synonyms.js        | 37 ++++++++++++++-----------------------
 4 files changed, 41 insertions(+), 51 deletions(-)

diff --git a/lib/parse-test-args.js b/lib/parse-test-args.js
index 76b3aeb..e180ce9 100644
--- a/lib/parse-test-args.js
+++ b/lib/parse-test-args.js
@@ -1,25 +1,21 @@
 'use strict'
-function typeOf (arg) {
-  const t = typeof arg
-  switch (t) {
-    case 'object':
-      return arg ? 'object' : 'null'
-    default:
-      return t
-  }
-}
+const typeOf = arg =>
+  typeof arg === 'object' ? (arg ? 'object' : 'null')
+  : typeof arg
 
-module.exports = function (name_, extra_, cb_, defaultName) {
+module.exports = (name_, extra_, cb_, defaultName) => {
   let name
   let extra
   let cb
 
+  const args = [name_, extra_, cb_]
+
   // this only works if it's literally the 4th argument.  it's mostly
   // used internally.
   defaultName = defaultName || '(unnamed test)'
 
-  for (let i = 0; i < 3 && i < arguments.length; i++) {
-    const arg = arguments[i]
+  for (let i = 0; i < 3 && i < args.length; i++) {
+    const arg = args[i]
     const type = typeOf(arg)
     if (name === undefined && (type === 'string' || type === 'number'))
       name = '' + arg
@@ -60,6 +56,6 @@ module.exports = function (name_, extra_, cb_, defaultName) {
 }
 
 /* istanbul ignore next */
-function todoCb () {
+const todoCb = () => {
   throw new Error('callback called for TODO test')
 }
diff --git a/lib/point.js b/lib/point.js
index 5551054..4c35247 100644
--- a/lib/point.js
+++ b/lib/point.js
@@ -1,23 +1,24 @@
 'use strict'
-module.exports = TestPoint
 
 const path = require('path')
 const binpath = path.resolve(__dirname, '../bin')
 const util = require('util')
 const diags = require('./diags.js')
 
-function TestPoint (ok, message, extra) {
-  if (typeof ok !== 'boolean')
-    throw new TypeError('ok must be boolean')
+class TestPoint {
+  constructor (ok, message, extra) {
+    if (typeof ok !== 'boolean')
+      throw new TypeError('ok must be boolean')
 
-  if (!(this instanceof TestPoint))
-    return new TestPoint(ok, message, extra)
+    if (!(this instanceof TestPoint))
+      return new TestPoint(ok, message, extra)
 
-  this.ok = ok ? 'ok ' : 'not ok '
-  this.message = tpMessage(message, extra)
+    this.ok = ok ? 'ok ' : 'not ok '
+    this.message = tpMessage(message, extra)
+  }
 }
 
-function tpMessage (message, extra) {
+const tpMessage = (message, extra) => {
   message = message + ''
   if (message)
     message = ' - ' + message
@@ -47,3 +48,5 @@ function tpMessage (message, extra) {
   message += '\n'
   return message
 }
+
+module.exports = TestPoint
diff --git a/lib/stack.js b/lib/stack.js
index 5eb463e..f6faa36 100644
--- a/lib/stack.js
+++ b/lib/stack.js
@@ -4,6 +4,11 @@ const StackUtils = require('stack-utils')
 const path = require('path')
 const tapDir = path.resolve(__dirname, '..')
 
+const resc = str =>
+  str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')
+
+// Ignore tap if it's a dependency, or anything
+// in this lib folder.
 // don't skip when developing on tap itself
 const skip = process.cwd() !== tapDir ||
   +process.env.TAP_DEV_SHORTSTACK === 1 &&
@@ -17,13 +22,8 @@ const skip = process.cwd() !== tapDir ||
 : []
 
 sourceMapSupport.install({environment:'node'})
-// Ignore tap if it's a dependency, or anything
-// in this lib folder.
+
 module.exports = new StackUtils({
   internals: StackUtils.nodeInternals().concat(skip),
   wrapCallSite: sourceMapSupport.wrapCallSite
 })
-
-function resc(str) {
-  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
-}
diff --git a/lib/synonyms.js b/lib/synonyms.js
index c5b272b..cb42e10 100644
--- a/lib/synonyms.js
+++ b/lib/synonyms.js
@@ -2,6 +2,20 @@
 // A list of all the synonyms of assert methods.
 // In addition to these, multi-word camelCase are also synonymized to
 // all lowercase and snake_case
+
+const multiword = obj =>
+  Object.keys(obj).reduce((s, i) =>
+    (s[i] = [ multiword_(i) ]
+      .concat(obj[i].map(multiword_))
+      .reduce((s, i) => (s.push.apply(s, i), s), []), s), obj)
+
+const multiword_ = str =>
+  str.match(/[A-Z]/) ? [
+    str,
+    str.toLowerCase(),
+    str.replace(/[A-Z]/g, $0 => '_' + $0.toLowerCase())
+  ] : [str]
+
 module.exports = multiword({
   ok: ['true', 'assert'],
   notOk: ['false', 'assertNot'],
@@ -63,26 +77,3 @@ module.exports = multiword({
     'isa', 'isA'
   ]
 })
-
-function multiword (obj) {
-  Object.keys(obj).forEach(function (i) {
-    const list = obj[i]
-    const res = [ multiword_(i) ].concat(list.map(multiword_)).reduce(function (set, i) {
-      set.push.apply(set, i)
-      return set
-    }, [])
-    obj[i] = res
-  })
-  return obj
-}
-
-function multiword_ (str) {
-  const res = [ str ]
-  if (str.match(/[A-Z]/)) {
-    res.push(str.toLowerCase())
-    res.push(str.replace(/[A-Z]/g, function ($0) {
-      return '_' + $0.toLowerCase()
-    }))
-  }
-  return res
-}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-tap.git



More information about the Pkg-javascript-commits mailing list