This commit is contained in:
2022-07-18 02:50:52 +00:00
parent befd344ab0
commit 06181b34d6
8569 changed files with 818704 additions and 352705 deletions
+3 -3
View File
@@ -2,18 +2,18 @@
> Helper function to change the property 'name' of every function
See our website [@babel/helper-function-name](https://babeljs.io/docs/en/next/babel-helper-function-name.html) for more information.
See our website [@babel/helper-function-name](https://babeljs.io/docs/en/babel-helper-function-name) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/helper-function-name
npm install --save @babel/helper-function-name
```
or using yarn:
```sh
yarn add @babel/helper-function-name --dev
yarn add @babel/helper-function-name
```
+51 -30
View File
@@ -5,19 +5,35 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = _default;
var _helperGetFunctionArity = _interopRequireDefault(require("@babel/helper-get-function-arity"));
var _template = require("@babel/template");
var _template = _interopRequireDefault(require("@babel/template"));
var _t = require("@babel/types");
var t = _interopRequireWildcard(require("@babel/types"));
const {
NOT_LOCAL_BINDING,
cloneNode,
identifier,
isAssignmentExpression,
isAssignmentPattern,
isFunction,
isIdentifier,
isLiteral,
isNullLiteral,
isObjectMethod,
isObjectProperty,
isRegExpLiteral,
isRestElement,
isTemplateLiteral,
isVariableDeclarator,
toBindingIdentifierName
} = _t;
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function getFunctionArity(node) {
const count = node.params.findIndex(param => isAssignmentPattern(param) || isRestElement(param));
return count === -1 ? node.params.length : count;
}
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const buildPropertyMethodAssignmentWrapper = (0, _template.default)(`
const buildPropertyMethodAssignmentWrapper = _template.default.statement(`
(function (FUNCTION_KEY) {
function FUNCTION_ID() {
return FUNCTION_KEY.apply(this, arguments);
@@ -30,7 +46,8 @@ const buildPropertyMethodAssignmentWrapper = (0, _template.default)(`
return FUNCTION_ID;
})(FUNCTION)
`);
const buildGeneratorPropertyMethodAssignmentWrapper = (0, _template.default)(`
const buildGeneratorPropertyMethodAssignmentWrapper = _template.default.statement(`
(function (FUNCTION_KEY) {
function* FUNCTION_ID() {
return yield* FUNCTION_KEY.apply(this, arguments);
@@ -43,6 +60,7 @@ const buildGeneratorPropertyMethodAssignmentWrapper = (0, _template.default)(`
return FUNCTION_ID;
})(FUNCTION)
`);
const visitor = {
"ReferencedIdentifier|BindingIdentifier"(path, state) {
if (path.node.name !== state.name) return;
@@ -55,15 +73,15 @@ const visitor = {
};
function getNameFromLiteralId(id) {
if (t.isNullLiteral(id)) {
if (isNullLiteral(id)) {
return "null";
}
if (t.isRegExpLiteral(id)) {
if (isRegExpLiteral(id)) {
return `_${id.pattern}_${id.flags}`;
}
if (t.isTemplateLiteral(id)) {
if (isTemplateLiteral(id)) {
return id.quasis.map(quasi => quasi.value.raw).join("");
}
@@ -79,7 +97,7 @@ function wrap(state, method, id, scope) {
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
scope.rename(id.name);
} else {
if (!t.isFunction(method)) return;
if (!isFunction(method)) return;
let build = buildPropertyMethodAssignmentWrapper;
if (method.generator) {
@@ -93,7 +111,7 @@ function wrap(state, method, id, scope) {
}).expression;
const params = template.callee.body.body[0].params;
for (let i = 0, len = (0, _helperGetFunctionArity.default)(method); i < len; i++) {
for (let i = 0, len = getFunctionArity(method); i < len; i++) {
params.push(scope.generateUidIdentifier("x"));
}
@@ -110,7 +128,6 @@ function visit(node, name, scope) {
selfAssignment: false,
selfReference: false,
outerDeclar: scope.getBindingIdentifier(name),
references: [],
name: name
};
const binding = scope.getOwnBinding(name);
@@ -131,26 +148,26 @@ function _default({
parent,
scope,
id
}, localBinding = false) {
}, localBinding = false, supportUnicodeId = false) {
if (node.id) return;
if ((t.isObjectProperty(parent) || t.isObjectMethod(parent, {
if ((isObjectProperty(parent) || isObjectMethod(parent, {
kind: "method"
})) && (!parent.computed || t.isLiteral(parent.key))) {
})) && (!parent.computed || isLiteral(parent.key))) {
id = parent.key;
} else if (t.isVariableDeclarator(parent)) {
} else if (isVariableDeclarator(parent)) {
id = parent.id;
if (t.isIdentifier(id) && !localBinding) {
if (isIdentifier(id) && !localBinding) {
const binding = scope.parent.getBinding(id.name);
if (binding && binding.constant && scope.getBinding(id.name) === binding) {
node.id = t.cloneNode(id);
node.id[t.NOT_LOCAL_BINDING] = true;
node.id = cloneNode(id);
node.id[NOT_LOCAL_BINDING] = true;
return;
}
}
} else if (t.isAssignmentExpression(parent, {
} else if (isAssignmentExpression(parent, {
operator: "="
})) {
id = parent.left;
@@ -160,9 +177,9 @@ function _default({
let name;
if (id && t.isLiteral(id)) {
if (id && isLiteral(id)) {
name = getNameFromLiteralId(id);
} else if (id && t.isIdentifier(id)) {
} else if (id && isIdentifier(id)) {
name = id.name;
}
@@ -170,9 +187,13 @@ function _default({
return;
}
name = t.toBindingIdentifierName(name);
id = t.identifier(name);
id[t.NOT_LOCAL_BINDING] = true;
if (!supportUnicodeId && isFunction(node) && /[\uD800-\uDFFF]/.test(name)) {
return;
}
name = toBindingIdentifierName(name);
const newId = identifier(name);
newId[NOT_LOCAL_BINDING] = true;
const state = visit(node, name, scope);
return wrap(state, node, id, scope) || node;
return wrap(state, node, newId, scope) || node;
}
+24 -19
View File
@@ -1,51 +1,55 @@
{
"_args": [
[
"@babel/helper-function-name@7.10.4",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
"@babel/helper-function-name@7.18.6",
"/home/node/nuxt"
]
],
"_from": "@babel/helper-function-name@7.10.4",
"_id": "@babel/helper-function-name@7.10.4",
"_from": "@babel/helper-function-name@7.18.6",
"_id": "@babel/helper-function-name@7.18.6",
"_inBundle": false,
"_integrity": "sha512-YdaSyz1n8gY44EmN7x44zBn9zQ1Ry2Y+3GTA+3vH6Mizke1Vw0aWDM66FOYEPw8//qKkmqOckrGgTYa+6sceqQ==",
"_integrity": "sha512-0mWMxV1aC97dhjCah5U5Ua7668r5ZmSC2DLfH2EZnf9c3/dHZKiFa5pRLMH5tjSl471tY6496ZWk/kjNONBxhw==",
"_location": "/@babel/helper-function-name",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@babel/helper-function-name@7.10.4",
"raw": "@babel/helper-function-name@7.18.6",
"name": "@babel/helper-function-name",
"escapedName": "@babel%2fhelper-function-name",
"scope": "@babel",
"rawSpec": "7.10.4",
"rawSpec": "7.18.6",
"saveSpec": null,
"fetchSpec": "7.10.4"
"fetchSpec": "7.18.6"
},
"_requiredBy": [
"/@babel/helper-create-class-features-plugin",
"/@babel/helper-define-map",
"/@babel/helper-wrap-function",
"/@babel/plugin-transform-classes",
"/@babel/plugin-transform-function-name",
"/@babel/traverse"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.10.4.tgz",
"_spec": "7.10.4",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"_resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.18.6.tgz",
"_spec": "7.18.6",
"_where": "/home/node/nuxt",
"author": {
"name": "The Babel Team",
"url": "https://babel.dev/team"
},
"bugs": {
"url": "https://github.com/babel/babel/issues"
},
"dependencies": {
"@babel/helper-get-function-arity": "^7.10.4",
"@babel/template": "^7.10.4",
"@babel/types": "^7.10.4"
"@babel/template": "^7.18.6",
"@babel/types": "^7.18.6"
},
"description": "Helper function to change the property 'name' of every function",
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df",
"homepage": "https://github.com/babel/babel#readme",
"engines": {
"node": ">=6.9.0"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-function-name",
"license": "MIT",
"main": "lib/index.js",
"main": "./lib/index.js",
"name": "@babel/helper-function-name",
"publishConfig": {
"access": "public"
@@ -55,5 +59,6 @@
"url": "git+https://github.com/babel/babel.git",
"directory": "packages/babel-helper-function-name"
},
"version": "7.10.4"
"type": "commonjs",
"version": "7.18.6"
}