hexo/node_modules/@babel/helper-wrap-function/lib/index.js.map

1 line
9.2 KiB
Plaintext
Raw Normal View History

2023-09-25 15:58:56 +08:00
{"version":3,"names":["blockStatement","callExpression","functionExpression","isAssignmentPattern","isFunctionDeclaration","isRestElement","returnStatement","isCallExpression","buildAnonymousExpressionWrapper","template","expression","buildNamedExpressionWrapper","buildDeclarationWrapper","statements","classOrObjectMethod","path","callId","node","body","container","async","generator","get","unwrapFunctionEnvironment","plainFunction","inPath","noNewArrows","ignoreFunctionLength","functionId","nodeParams","params","isArrowFunctionExpression","arrowFunctionToExpression","isDeclaration","built","id","type","param","push","scope","generateUidIdentifier","wrapperArgs","NAME","REF","name","FUNCTION","PARAMS","replaceWith","insertAfter","returnFn","callee","argument","nameFunction","parent","length","wrapFunction","isMethod"],"sources":["../src/index.ts"],"sourcesContent":["import type { NodePath } from \"@babel/traverse\";\nimport nameFunction from \"@babel/helper-function-name\";\nimport template from \"@babel/template\";\nimport {\n blockStatement,\n callExpression,\n functionExpression,\n isAssignmentPattern,\n isFunctionDeclaration,\n isRestElement,\n returnStatement,\n isCallExpression,\n} from \"@babel/types\";\nimport type * as t from \"@babel/types\";\n\ntype ExpressionWrapperBuilder<ExtraBody extends t.Node[]> = (\n replacements?: Parameters<ReturnType<typeof template.expression>>[0],\n) => t.CallExpression & {\n callee: t.FunctionExpression & {\n body: {\n body: [\n t.VariableDeclaration & {\n declarations: [\n { init: t.FunctionExpression | t.ArrowFunctionExpression },\n ];\n },\n ...ExtraBody,\n ];\n };\n };\n};\n\nconst buildAnonymousExpressionWrapper = template.expression(`\n (function () {\n var REF = FUNCTION;\n return function NAME(PARAMS) {\n return REF.apply(this, arguments);\n };\n })()\n`) as ExpressionWrapperBuilder<\n [t.ReturnStatement & { argument: t.FunctionExpression }]\n>;\n\nconst buildNamedExpressionWrapper = template.expression(`\n (function () {\n var REF = FUNCTION;\n function NAME(PARAMS) {\n return REF.apply(this, arguments);\n }\n return NAME;\n })()\n`) as ExpressionWrapperBuilder<\n [t.FunctionDeclaration, t.ReturnStatement & { argument: t.Identifier }]\n>;\n\nconst buildDeclarationWrapper = template.statements(`\n function NAME(PARAMS) { return REF.apply(this, arguments); }\n function REF() {\n REF = FUNCTION;\n return REF.apply(this, arguments);\n }\n`);\n\nfunction classOrObjectMethod(\n path: NodePath<t.ClassMethod | t.ClassPrivateMethod | t.ObjectMethod>,\n callId: t.Expression,\n) {\n const node = path.node;\n const body = node.body;\n\n const container = functionExpression(\n null,\n [],\n blockStatement(body.body),\n true,\n );\n body.body = [\n returnStatement(callExpression(callExpression(callId, [container]), [])),\n ];\n\n // Regardless of whether or not the wrapped function is a an async method\n // or generator the outer function should not be\n node.async = false;\n node.generator = false;\n\n // Unwrap the wrapper IIFE's environment so super and this and such still work.\n (\n path.get(\"body.body.0.argument.callee.arguments.0\") as NodePath\n ).unwrapFunctionEnvironment();\n}\n\nfunction plainFunction(\n inPath: NodePath<Exclude<t.Function, t.Method>>,\n callId: t.Expression,\n noNewArrows: boolean,\n ignoreFunctionLength: boolean,\n) {\n let path: NodePath<\n | t.FunctionDeclaration\n | t.FunctionExpression\n | t.CallExpression\n | t.ArrowFunctionExpression\n > = inPath;\n let node;\n let functionId = null;\n const nodeParams = inPath.node.params;\n\n if (path.isArrowFunctionExpression()) {\n if (process.env.BABEL_8_BREAKING) {\n path = path.arrowFunctionToExpression({ noNewArrows });\n } else {\n // arrowFunctionToExpression returns undefined in @babel/traverse < 7.18.10\n path = path.arrowFunctionToExpression({ noNewArrows }) ?? path;\n }\n node = path.node as\n |