summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/onetime/index.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-10-25 12:48:14 -0700
committercjihrig <cjihrig@gmail.com>2019-10-28 09:51:24 -0400
commit511f67bcb42b59c9a3a3efab8fed578db100afe1 (patch)
tree8b64f390dd727dd739fd2fb84d69df3c829a9315 /tools/node_modules/eslint/node_modules/onetime/index.js
parentb35181f877d5a92e8bb52eb071489f2a7d87494b (diff)
downloadandroid-node-v8-511f67bcb42b59c9a3a3efab8fed578db100afe1.tar.gz
android-node-v8-511f67bcb42b59c9a3a3efab8fed578db100afe1.tar.bz2
android-node-v8-511f67bcb42b59c9a3a3efab8fed578db100afe1.zip
tools: update ESLint to 6.6.0
Update ESLint to 6.6.0 PR-URL: https://github.com/nodejs/node/pull/30123 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/onetime/index.js')
-rw-r--r--tools/node_modules/eslint/node_modules/onetime/index.js41
1 files changed, 26 insertions, 15 deletions
diff --git a/tools/node_modules/eslint/node_modules/onetime/index.js b/tools/node_modules/eslint/node_modules/onetime/index.js
index 0d76476b0b..a3f412af1b 100644
--- a/tools/node_modules/eslint/node_modules/onetime/index.js
+++ b/tools/node_modules/eslint/node_modules/onetime/index.js
@@ -1,39 +1,50 @@
'use strict';
const mimicFn = require('mimic-fn');
-module.exports = (fn, opts) => {
- // TODO: Remove this in v3
- if (opts === true) {
- throw new TypeError('The second argument is now an options object');
- }
+const calledFunctions = new WeakMap();
+const oneTime = (fn, options = {}) => {
if (typeof fn !== 'function') {
throw new TypeError('Expected a function');
}
- opts = opts || {};
-
let ret;
- let called = false;
- const fnName = fn.displayName || fn.name || '<anonymous>';
+ let isCalled = false;
+ let callCount = 0;
+ const functionName = fn.displayName || fn.name || '<anonymous>';
- const onetime = function () {
- if (called) {
- if (opts.throw === true) {
- throw new Error(`Function \`${fnName}\` can only be called once`);
+ const onetime = function (...args) {
+ calledFunctions.set(onetime, ++callCount);
+
+ if (isCalled) {
+ if (options.throw === true) {
+ throw new Error(`Function \`${functionName}\` can only be called once`);
}
return ret;
}
- called = true;
- ret = fn.apply(this, arguments);
+ isCalled = true;
+ ret = fn.apply(this, args);
fn = null;
return ret;
};
mimicFn(onetime, fn);
+ calledFunctions.set(onetime, callCount);
return onetime;
};
+
+module.exports = oneTime;
+// TODO: Remove this for the next major release
+module.exports.default = oneTime;
+
+module.exports.callCount = fn => {
+ if (!calledFunctions.has(fn)) {
+ throw new Error(`The given function \`${fn.name}\` is not wrapped by the \`onetime\` package`);
+ }
+
+ return calledFunctions.get(fn);
+};