Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert @babel/helper-function-name to TypeScript #12486

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/babel-packages.js.flow
Expand Up @@ -157,3 +157,10 @@ declare module "@babel/helper-validator-option" {
arr: $ReadonlyArray<string>
): string;
}

declare module "@babel/helper-function-name" {
declare export default function helperFunctionNamefunction(
options: any,
localBinding?: boolean
): any;
}
Expand Up @@ -79,15 +79,18 @@ function wrap(state, method, id, scope) {
if (method.generator) {
build = buildGeneratorPropertyMethodAssignmentWrapper;
}
const template = build({

const template = (build({
FUNCTION: method,
FUNCTION_ID: id,
FUNCTION_KEY: scope.generateUidIdentifier(id.name),
}).expression;
}) as t.ExpressionStatement).expression as t.CallExpression;

// 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
const params = template.callee.body.body[0].params;
const params = (((template.callee as t.FunctionExpression).body
.body[0] as any) as t.FunctionExpression).params;

for (let i = 0, len = getFunctionArity(method); i < len; i++) {
params.push(scope.generateUidIdentifier("x"));
}
Expand Down Expand Up @@ -150,7 +153,10 @@ function visit(node, name, scope) {
* @param {NodePath} param0
* @param {Boolean} localBinding whether a name could shadow a self-reference (e.g. converting arrow function)
*/
export default function ({ node, parent, scope, id }, localBinding = false) {
export default function (
{ node, parent, scope, id }: { node: any; parent: any; scope: any; id: any },
localBinding = false,
) {
// has an `id` so we don't need to infer one
if (node.id) return;

Expand Down