aboutsummaryrefslogtreecommitdiff
path: root/node_modules/function-name-support
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/function-name-support
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/function-name-support')
-rw-r--r--node_modules/function-name-support/LICENSE41
-rw-r--r--node_modules/function-name-support/README.md61
-rw-r--r--node_modules/function-name-support/index.js163
-rw-r--r--node_modules/function-name-support/package.json41
4 files changed, 306 insertions, 0 deletions
diff --git a/node_modules/function-name-support/LICENSE b/node_modules/function-name-support/LICENSE
new file mode 100644
index 000000000..06dffffbf
--- /dev/null
+++ b/node_modules/function-name-support/LICENSE
@@ -0,0 +1,41 @@
+MIT License
+
+Copyright (c) 2017 Mark Wubben <mark@novemberborn.net> (novemberborn.net)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+---
+
+Tests from <https://github.com/kangax/compat-table/blob/c0a3b882b27e4e9f4ef449a1c985ee7857326b94/data-es6.js#L12733:L13115>.
+
+Copyright (c) 2010-2013 Juriy Zaytsev
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/node_modules/function-name-support/README.md b/node_modules/function-name-support/README.md
new file mode 100644
index 000000000..68ec9995d
--- /dev/null
+++ b/node_modules/function-name-support/README.md
@@ -0,0 +1,61 @@
+# function-name-support
+
+Feature detection for function names. See [*The names of functions in
+ES6*](http://2ality.com/2015/09/function-names-es6.html) for background.
+Provides the [same results as
+`node-compat-table`][node-compat-table].
+
+## Installation
+
+```console
+$ npm install --save function-name-support
+```
+
+## Usage
+
+```js
+const functionNameSupport = require('function-name-support')
+```
+
+### `support`
+
+A frozen object with boolean values. Compare with
+[`node-compat-table`][node-compat-table]:
+
+* *function statements*: `functionStatements`
+* *function expressions*: `functionExpressions`
+* *new Function*: `newFunction`
+* *bound functions*: `boundFunctions`
+* *variables (function)*: `functionVariables`
+* *object methods (function)*: `functionObjectMethods`
+* *accessor properties*: `accessorProperties`
+* *shorthand methods*: `shorthandMethods`
+* *symbol-keyed methods*: `symbolKeyedMethods`
+* *class statements*: `classStatements`
+* *class expressions*: `classExpressions`
+* *variables (class)*: `classVariables`
+* *object methods (class)*: `classObjectMethods`
+* *class prototype methods*: `classPrototypeMethods`
+* *class static methods*: `classStaticMethods`
+
+### `hasFullSupport`
+
+A boolean indicating whether all known function name inferences are supported.
+
+### `bitFlags`
+
+An integer that stores a serialization of the `support` object. Useful when
+storing a function name (or lack thereof) for later comparisons along with
+details on whether the function name was inferable at all.
+
+### `isSubsetOf(otherFlags): boolean`
+
+Helper method for comparing `bitFlags`. Returns `true` if it is a subset of
+`otherFlags`.
+
+### `isSupersetOf(otherFlags: number): boolean`
+
+Helper method for comparing `bitFlags`. Returns `true` if it is a superset of
+`otherFlags`.
+
+[node-compat-table]: http://node.green/#ES2015-built-in-extensions-function--name--property
diff --git a/node_modules/function-name-support/index.js b/node_modules/function-name-support/index.js
new file mode 100644
index 000000000..d42149961
--- /dev/null
+++ b/node_modules/function-name-support/index.js
@@ -0,0 +1,163 @@
+'use strict'
+
+const vm = require('vm')
+
+const context = vm.createContext()
+function test (code) {
+ try {
+ return vm.runInContext(`(function () {
+ 'use strict'
+ ${code}
+ })()`, context) === true
+ } catch (err) {
+ return false
+ }
+}
+
+const support = {}
+
+// Tests from <https://github.com/kangax/compat-table/blob/c0a3b882b27e4e9f4ef449a1c985ee7857326b94/data-es6.js#L12733:L13115>.
+support.functionStatements = test(`
+ function foo(){};
+ return foo.name === 'foo' &&
+ (function(){}).name === '';
+`)
+
+support.functionExpressions = test(`
+ return (function foo(){}).name === 'foo' &&
+ (function(){}).name === '';
+`)
+
+support.newFunction = test(`
+ return (new Function).name === "anonymous";
+`)
+
+support.boundFunctions = test(`
+ function foo() {};
+ return foo.bind({}).name === "bound foo" &&
+ (function(){}).bind({}).name === "bound ";
+`)
+
+support.functionVariables = test(`
+ var foo = function() {};
+ var bar = function baz() {};
+ return foo.name === "foo" && bar.name === "baz";
+`)
+
+support.functionObjectMethods = test(`
+ var o = { foo: function(){}, bar: function baz(){}};
+ o.qux = function(){};
+ return o.foo.name === "foo" &&
+ o.bar.name === "baz" &&
+ o.qux.name === "";
+`)
+
+support.accessorProperties = test(`
+ var o = { get foo(){}, set foo(x){} };
+ var descriptor = Object.getOwnPropertyDescriptor(o, "foo");
+ return descriptor.get.name === "get foo" &&
+ descriptor.set.name === "set foo";
+`)
+
+support.shorthandMethods = test(`
+ var o = { foo(){} };
+ return o.foo.name === "foo"
+`)
+
+support.symbolKeyedMethods = test(`
+ var sym1 = Symbol("foo");
+ var sym2 = Symbol();
+ var o = {
+ [sym1]: function(){},
+ [sym2]: function(){}
+ };
+
+ return o[sym1].name === "[foo]" &&
+ o[sym2].name === "";
+`)
+
+support.classStatements = test(`
+ class foo {};
+ class bar { static name() {} };
+ return foo.name === "foo" &&
+ typeof bar.name === "function";
+`)
+
+support.classExpressions = test(`
+ return class foo {}.name === "foo" &&
+ typeof class bar { static name() {} }.name === "function";
+`)
+
+support.classVariables = test(`
+ var foo = class {};
+ var bar = class baz {};
+ var qux = class { static name() {} };
+ return foo.name === "foo" &&
+ bar.name === "baz" &&
+ typeof qux.name === "function";
+`)
+
+support.classObjectMethods = test(`
+ var o = { foo: class {}, bar: class baz {}};
+ o.qux = class {};
+ return o.foo.name === "foo" &&
+ o.bar.name === "baz" &&
+ o.qux.name === "";
+`)
+
+support.classPrototypeMethods = test(`
+ class C { foo(){} };
+ return (new C).foo.name === "foo";
+`)
+
+support.classStaticMethods = test(`
+ class C { static foo(){} };
+ return C.foo.name === "foo";
+`)
+
+exports.support = Object.freeze(support)
+
+const hasFullSupport =
+ support.functionStatements &&
+ support.functionExpressions &&
+ support.newFunction &&
+ support.boundFunctions &&
+ support.functionVariables &&
+ support.functionObjectMethods &&
+ support.accessorProperties &&
+ support.shorthandMethods &&
+ support.symbolKeyedMethods &&
+ support.classStatements &&
+ support.classExpressions &&
+ support.classVariables &&
+ support.classObjectMethods &&
+ support.classPrototypeMethods &&
+ support.classStaticMethods
+exports.hasFullSupport = hasFullSupport
+
+const bitFlags = [
+ 'functionStatements',
+ 'functionExpressions',
+ 'newFunction',
+ 'boundFunctions',
+ 'functionVariables',
+ 'functionObjectMethods',
+ 'accessorProperties',
+ 'shorthandMethods',
+ 'symbolKeyedMethods',
+ 'classStatements',
+ 'classExpressions',
+ 'classVariables',
+ 'classObjectMethods',
+ 'classPrototypeMethods',
+ 'classStaticMethods'
+ // Add new flags at the end. Reordering flags is a breaking change.
+].reduce((acc, key, index) => {
+ return support[key] === true
+ ? acc + (1 << index)
+ : acc
+}, 0b0)
+exports.bitFlags = bitFlags
+
+exports.isSubsetOf = otherFlags => (bitFlags & otherFlags) === bitFlags
+exports.isSupersetOf = otherFlags => (bitFlags & otherFlags) === otherFlags
diff --git a/node_modules/function-name-support/package.json b/node_modules/function-name-support/package.json
new file mode 100644
index 000000000..97113ae4f
--- /dev/null
+++ b/node_modules/function-name-support/package.json
@@ -0,0 +1,41 @@
+{
+ "name": "function-name-support",
+ "version": "0.2.0",
+ "description": "Determine the level of support for function name inference.",
+ "main": "index.js",
+ "files": [
+ "index.js"
+ ],
+ "scripts": {
+ "coverage": "nyc npm test",
+ "lint": "as-i-preach",
+ "test": "ava",
+ "posttest": "npm run lint"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/novemberborn/function-name-inference.git"
+ },
+ "author": "Mark Wubben (https://novemberborn.net/)",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/novemberborn/function-name-inference/issues"
+ },
+ "homepage": "https://github.com/novemberborn/function-name-inference#readme",
+ "devDependencies": {
+ "@novemberborn/as-i-preach": "^9.0.0",
+ "ava": "^0.19.1",
+ "codecov": "^2.2.0",
+ "istanbul-lib-instrument": "^1.7.1",
+ "nyc": "^10.3.2",
+ "proxyquire": "^1.8.0"
+ },
+ "nyc": {
+ "reporter": [
+ "html",
+ "lcov",
+ "text"
+ ]
+ },
+ "standard-engine": "@novemberborn/as-i-preach"
+}