babel-helper-function-name
Advanced tools
Comparing version 6.8.0 to 6.18.0
@@ -1,19 +0,16 @@ | ||
/*istanbul ignore next*/"use strict"; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.default = function ( /*istanbul ignore next*/_ref) { | ||
/*istanbul ignore next*/var node = _ref.node; | ||
/*istanbul ignore next*/var parent = _ref.parent; | ||
/*istanbul ignore next*/var scope = _ref.scope; | ||
/*istanbul ignore next*/var id = _ref.id; | ||
exports.default = function (_ref) { | ||
var node = _ref.node; | ||
var parent = _ref.parent; | ||
var scope = _ref.scope; | ||
var id = _ref.id; | ||
// has an `id` so we don't need to infer one | ||
if (node.id) return; | ||
if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, { kind: "method" })) && (!parent.computed || t.isLiteral(parent.key))) { | ||
// { foo() {} }; | ||
id = parent.key; | ||
} else if (t.isVariableDeclarator(parent)) { | ||
// let foo = function () {}; | ||
id = parent.id; | ||
@@ -24,3 +21,2 @@ | ||
if (binding && binding.constant && scope.getBinding(id.name) === binding) { | ||
// always going to reference this method | ||
node.id = id; | ||
@@ -32,3 +28,2 @@ node.id[t.NOT_LOCAL_BINDING] = true; | ||
} else if (t.isAssignmentExpression(parent)) { | ||
// foo = function () {}; | ||
id = parent.left; | ||
@@ -39,3 +34,3 @@ } else if (!id) { | ||
var name = /*istanbul ignore next*/void 0; | ||
var name = void 0; | ||
if (id && t.isLiteral(id)) { | ||
@@ -52,5 +47,2 @@ name = id.value; | ||
// The id shouldn't be considered a local binding to the function because | ||
// we are simply trying to set the function name and not actually create | ||
// a local binding. | ||
id[t.NOT_LOCAL_BINDING] = true; | ||
@@ -62,18 +54,14 @@ | ||
var /*istanbul ignore next*/_babelHelperGetFunctionArity = require("babel-helper-get-function-arity"); | ||
var _babelHelperGetFunctionArity = require("babel-helper-get-function-arity"); | ||
/*istanbul ignore next*/ | ||
var _babelHelperGetFunctionArity2 = _interopRequireDefault(_babelHelperGetFunctionArity); | ||
var /*istanbul ignore next*/_babelTemplate = require("babel-template"); | ||
var _babelTemplate = require("babel-template"); | ||
/*istanbul ignore next*/ | ||
var _babelTemplate2 = _interopRequireDefault(_babelTemplate); | ||
var /*istanbul ignore next*/_babelTypes = require("babel-types"); | ||
var _babelTypes = require("babel-types"); | ||
/*istanbul ignore next*/ | ||
var t = _interopRequireWildcard(_babelTypes); | ||
/*istanbul ignore next*/ | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -83,13 +71,10 @@ | ||
var buildPropertyMethodAssignmentWrapper = /*istanbul ignore next*/(0, _babelTemplate2.default)( /*istanbul ignore next*/"\n (function (FUNCTION_KEY) {\n function FUNCTION_ID() {\n return FUNCTION_KEY.apply(this, arguments);\n }\n\n FUNCTION_ID.toString = function () {\n return FUNCTION_KEY.toString();\n }\n\n return FUNCTION_ID;\n })(FUNCTION)\n"); /* eslint max-len: 0 */ | ||
var buildPropertyMethodAssignmentWrapper = (0, _babelTemplate2.default)("\n (function (FUNCTION_KEY) {\n function FUNCTION_ID() {\n return FUNCTION_KEY.apply(this, arguments);\n }\n\n FUNCTION_ID.toString = function () {\n return FUNCTION_KEY.toString();\n }\n\n return FUNCTION_ID;\n })(FUNCTION)\n"); | ||
var buildGeneratorPropertyMethodAssignmentWrapper = /*istanbul ignore next*/(0, _babelTemplate2.default)( /*istanbul ignore next*/"\n (function (FUNCTION_KEY) {\n function* FUNCTION_ID() {\n return yield* FUNCTION_KEY.apply(this, arguments);\n }\n\n FUNCTION_ID.toString = function () {\n return FUNCTION_KEY.toString();\n };\n\n return FUNCTION_ID;\n })(FUNCTION)\n"); | ||
var buildGeneratorPropertyMethodAssignmentWrapper = (0, _babelTemplate2.default)("\n (function (FUNCTION_KEY) {\n function* FUNCTION_ID() {\n return yield* FUNCTION_KEY.apply(this, arguments);\n }\n\n FUNCTION_ID.toString = function () {\n return FUNCTION_KEY.toString();\n };\n\n return FUNCTION_ID;\n })(FUNCTION)\n"); | ||
var visitor = { /*istanbul ignore next*/ | ||
var visitor = { | ||
"ReferencedIdentifier|BindingIdentifier": function ReferencedIdentifierBindingIdentifier(path, state) { | ||
// check if this node matches our function id | ||
if (path.node.name !== state.name) return; | ||
// check that we don't have a local variable declared as that removes the need | ||
// for the wrapper | ||
var localDeclar = path.scope.getBindingIdentifier(state.name); | ||
@@ -106,9 +91,6 @@ if (localDeclar !== state.outerDeclar) return; | ||
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) { | ||
// we can just munge the local binding | ||
scope.rename(id.name); | ||
} else { | ||
// we don't currently support wrapping class expressions | ||
if (!t.isFunction(method)) return; | ||
// need to add a wrapper since we can't change the references | ||
var build = buildPropertyMethodAssignmentWrapper; | ||
@@ -123,6 +105,4 @@ if (method.generator) build = buildGeneratorPropertyMethodAssignmentWrapper; | ||
// shim in dummy params to retain function arity, if you try to read the | ||
// source then you'll get the original since it's proxied so it's all good | ||
var params = _template.callee.body.body[0].params; | ||
for (var i = 0, len = /*istanbul ignore next*/(0, _babelHelperGetFunctionArity2.default)(method); i < len; i++) { | ||
for (var i = 0, len = (0, _babelHelperGetFunctionArity2.default)(method); i < len; i++) { | ||
params.push(scope.generateUidIdentifier("x")); | ||
@@ -148,5 +128,2 @@ } | ||
// check to see if we have a local binding of the id we're setting inside of | ||
// the function, this is important as there are caveats associated | ||
var binding = scope.getOwnBinding(name); | ||
@@ -156,28 +133,7 @@ | ||
if (binding.kind === "param") { | ||
// safari will blow up in strict mode with code like: | ||
// | ||
// let t = function t(t) {}; | ||
// | ||
// with the error: | ||
// | ||
// Cannot declare a parameter named 't' as it shadows the name of a | ||
// strict mode function. | ||
// | ||
// this isn't to the spec and they've invented this behaviour which is | ||
// **extremely** annoying so we avoid setting the name if it has a param | ||
// with the same id | ||
state.selfReference = true; | ||
} else { | ||
// otherwise it's defined somewhere in scope like: | ||
// | ||
// let t = function () { | ||
// let t = 2; | ||
// }; | ||
// | ||
// so we can safely just set the id and move along as it shadows the | ||
// bound function id | ||
} | ||
} else {} | ||
} else if (state.outerDeclar || scope.hasGlobal(name)) { | ||
scope.traverse(node, visitor, state); | ||
} | ||
scope.traverse(node, visitor, state); | ||
} | ||
@@ -187,2 +143,2 @@ return state; | ||
/*istanbul ignore next*/module.exports = exports["default"]; | ||
module.exports = exports["default"]; |
{ | ||
"name": "babel-helper-function-name", | ||
"version": "6.8.0", | ||
"description": "", | ||
"version": "6.18.0", | ||
"description": "Helper function to change the property 'name' of every function", | ||
"repository": "https://github.com/babel/babel/tree/master/packages/babel-helper-function-name", | ||
@@ -10,7 +10,7 @@ "license": "MIT", | ||
"babel-runtime": "^6.0.0", | ||
"babel-types": "^6.8.0", | ||
"babel-traverse": "^6.8.0", | ||
"babel-helper-get-function-arity": "^6.8.0", | ||
"babel-types": "^6.18.0", | ||
"babel-traverse": "^6.18.0", | ||
"babel-helper-get-function-arity": "^6.18.0", | ||
"babel-template": "^6.8.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4885
102
Updatedbabel-traverse@^6.18.0
Updatedbabel-types@^6.18.0