diff --git a/packages/babel-helper-function-name/package.json b/packages/babel-helper-function-name/package.json index 73a0222b3c82..01943b4a5ebb 100644 --- a/packages/babel-helper-function-name/package.json +++ b/packages/babel-helper-function-name/package.json @@ -14,7 +14,6 @@ }, "main": "./lib/index.js", "dependencies": { - "@babel/helper-get-function-arity": "workspace:^", "@babel/template": "workspace:^", "@babel/types": "workspace:^" }, diff --git a/packages/babel-helper-function-name/src/index.ts b/packages/babel-helper-function-name/src/index.ts index 09dd4c61bd53..fc157b28be35 100644 --- a/packages/babel-helper-function-name/src/index.ts +++ b/packages/babel-helper-function-name/src/index.ts @@ -1,10 +1,10 @@ -import getFunctionArity from "@babel/helper-get-function-arity"; import template from "@babel/template"; import { NOT_LOCAL_BINDING, cloneNode, identifier, isAssignmentExpression, + isAssignmentPattern, isFunction, isIdentifier, isLiteral, @@ -12,12 +12,20 @@ import { isObjectMethod, isObjectProperty, isRegExpLiteral, + isRestElement, isTemplateLiteral, isVariableDeclarator, toBindingIdentifierName, } from "@babel/types"; import type * as t from "@babel/types"; +function getFunctionArity(node: t.Function): number { + const count = node.params.findIndex( + param => isAssignmentPattern(param) || isRestElement(param), + ); + return count === -1 ? node.params.length : count; +} + const buildPropertyMethodAssignmentWrapper = template(` (function (FUNCTION_KEY) { function FUNCTION_ID() { diff --git a/packages/babel-helper-get-function-arity/.npmignore b/packages/babel-helper-get-function-arity/.npmignore deleted file mode 100644 index f9806945836e..000000000000 --- a/packages/babel-helper-get-function-arity/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -src -test -*.log diff --git a/packages/babel-helper-get-function-arity/README.md b/packages/babel-helper-get-function-arity/README.md deleted file mode 100644 index ca7f8b120b44..000000000000 --- a/packages/babel-helper-get-function-arity/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# @babel/helper-get-function-arity - -> Helper function to get function arity - -See our website [@babel/helper-get-function-arity](https://babeljs.io/docs/en/babel-helper-get-function-arity) for more information. - -## Install - -Using npm: - -```sh -npm install --save @babel/helper-get-function-arity -``` - -or using yarn: - -```sh -yarn add @babel/helper-get-function-arity -``` diff --git a/packages/babel-helper-get-function-arity/package.json b/packages/babel-helper-get-function-arity/package.json deleted file mode 100644 index e25397d37469..000000000000 --- a/packages/babel-helper-get-function-arity/package.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "@babel/helper-get-function-arity", - "version": "7.16.7", - "description": "Helper function to get function arity", - "repository": { - "type": "git", - "url": "https://github.com/babel/babel.git", - "directory": "packages/babel-helper-get-function-arity" - }, - "homepage": "https://babel.dev/docs/en/next/babel-helper-get-function-arity", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "main": "./lib/index.js", - "dependencies": { - "@babel/types": "workspace:^" - }, - "engines": { - "node": ">=6.9.0" - }, - "author": "The Babel Team (https://babel.dev/team)", - "conditions": { - "BABEL_8_BREAKING": [ - null, - { - "exports": null - } - ] - }, - "exports": { - ".": "./lib/index.js", - "./package.json": "./package.json" - } -} diff --git a/packages/babel-helper-get-function-arity/src/index.ts b/packages/babel-helper-get-function-arity/src/index.ts deleted file mode 100644 index 96176b1fe329..000000000000 --- a/packages/babel-helper-get-function-arity/src/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { isAssignmentPattern, isRestElement } from "@babel/types"; -import type * as t from "@babel/types"; - -export default function (node: t.Function): number { - const params = node.params; - for (let i = 0; i < params.length; i++) { - const param = params[i]; - if (isAssignmentPattern(param) || isRestElement(param)) { - return i; - } - } - return params.length; -} diff --git a/tsconfig.json b/tsconfig.json index f0cb0df8795a..6238556a7f0d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,6 @@ "./packages/babel-helper-explode-assignable-expression/src/**/*.ts", "./packages/babel-helper-fixtures/src/**/*.ts", "./packages/babel-helper-function-name/src/**/*.ts", - "./packages/babel-helper-get-function-arity/src/**/*.ts", "./packages/babel-helper-hoist-variables/src/**/*.ts", "./packages/babel-helper-member-expression-to-functions/src/**/*.ts", "./packages/babel-helper-module-imports/src/**/*.ts", @@ -190,9 +189,6 @@ "@babel/helper-function-name": [ "./packages/babel-helper-function-name/src" ], - "@babel/helper-get-function-arity": [ - "./packages/babel-helper-get-function-arity/src" - ], "@babel/helper-hoist-variables": [ "./packages/babel-helper-hoist-variables/src" ], diff --git a/yarn.lock b/yarn.lock index 788a41e02609..a9e4eb9e9e7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -691,7 +691,6 @@ __metadata: version: 0.0.0-use.local resolution: "@babel/helper-function-name@workspace:packages/babel-helper-function-name" dependencies: - "@babel/helper-get-function-arity": "workspace:^" "@babel/template": "workspace:^" "@babel/types": "workspace:^" languageName: unknown @@ -706,14 +705,6 @@ __metadata: languageName: node linkType: hard -"@babel/helper-get-function-arity@workspace:^, @babel/helper-get-function-arity@workspace:packages/babel-helper-get-function-arity": - version: 0.0.0-use.local - resolution: "@babel/helper-get-function-arity@workspace:packages/babel-helper-get-function-arity" - dependencies: - "@babel/types": "workspace:^" - languageName: unknown - linkType: soft - "@babel/helper-hoist-variables@npm:^7.15.4, @babel/helper-hoist-variables@npm:^7.16.7": version: 7.16.7 resolution: "@babel/helper-hoist-variables@npm:7.16.7"