Skip to content

Commit

Permalink
convert @babel/helper-function-name to TypeScript (#12486)
Browse files Browse the repository at this point in the history
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
  • Loading branch information
zxbodya and JLHwung committed Dec 15, 2020
1 parent 0ea0650 commit 4f1df9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/babel-packages.js.flow
Original file line number Diff line number Diff line change
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;
}
Original file line number Diff line number Diff line change
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

0 comments on commit 4f1df9a

Please sign in to comment.