diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
| commit | aa773172311dcada759dfbaac485f4bc6e00bc21 (patch) | |
| tree | ca6d9a5eff3ab8f689f9acb4f0df791d9486813d /node_modules/@babel/helper-wrap-function | |
| parent | c5a5384e846f242e901e859fe600d695d8990a9a (diff) | |
added babel
Diffstat (limited to 'node_modules/@babel/helper-wrap-function')
5 files changed, 194 insertions, 0 deletions
diff --git a/node_modules/@babel/helper-wrap-function/LICENSE b/node_modules/@babel/helper-wrap-function/LICENSE new file mode 100644 index 00000000..f31575ec --- /dev/null +++ b/node_modules/@babel/helper-wrap-function/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2014-present Sebastian McKenzie and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/@babel/helper-wrap-function/README.md b/node_modules/@babel/helper-wrap-function/README.md new file mode 100644 index 00000000..74158704 --- /dev/null +++ b/node_modules/@babel/helper-wrap-function/README.md @@ -0,0 +1,19 @@ +# @babel/helper-wrap-function + +> Helper to wrap functions inside a function call. + +See our website [@babel/helper-wrap-function](https://babeljs.io/docs/babel-helper-wrap-function) for more information. + +## Install + +Using npm: + +```sh +npm install --save @babel/helper-wrap-function +``` + +or using yarn: + +```sh +yarn add @babel/helper-wrap-function +``` diff --git a/node_modules/@babel/helper-wrap-function/lib/index.js b/node_modules/@babel/helper-wrap-function/lib/index.js new file mode 100644 index 00000000..3c7b997a --- /dev/null +++ b/node_modules/@babel/helper-wrap-function/lib/index.js @@ -0,0 +1,123 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = wrapFunction; +var _helperFunctionName = require("@babel/helper-function-name"); +var _template = require("@babel/template"); +var _t = require("@babel/types"); +const { + blockStatement, + callExpression, + functionExpression, + isAssignmentPattern, + isFunctionDeclaration, + isRestElement, + returnStatement, + isCallExpression +} = _t; +const buildAnonymousExpressionWrapper = _template.default.expression(` + (function () { + var REF = FUNCTION; + return function NAME(PARAMS) { + return REF.apply(this, arguments); + }; + })() +`); +const buildNamedExpressionWrapper = _template.default.expression(` + (function () { + var REF = FUNCTION; + function NAME(PARAMS) { + return REF.apply(this, arguments); + } + return NAME; + })() +`); +const buildDeclarationWrapper = _template.default.statements(` + function NAME(PARAMS) { return REF.apply(this, arguments); } + function REF() { + REF = FUNCTION; + return REF.apply(this, arguments); + } +`); +function classOrObjectMethod(path, callId) { + const node = path.node; + const body = node.body; + const container = functionExpression(null, [], blockStatement(body.body), true); + body.body = [returnStatement(callExpression(callExpression(callId, [container]), []))]; + node.async = false; + node.generator = false; + path.get("body.body.0.argument.callee.arguments.0").unwrapFunctionEnvironment(); +} +function plainFunction(inPath, callId, noNewArrows, ignoreFunctionLength) { + let path = inPath; + let node; + let functionId = null; + const nodeParams = inPath.node.params; + if (path.isArrowFunctionExpression()) { + { + var _path$arrowFunctionTo; + path = (_path$arrowFunctionTo = path.arrowFunctionToExpression({ + noNewArrows + })) != null ? _path$arrowFunctionTo : path; + } + node = path.node; + } else { + node = path.node; + } + const isDeclaration = isFunctionDeclaration(node); + let built = node; + if (!isCallExpression(node)) { + functionId = node.id; + node.id = null; + node.type = "FunctionExpression"; + built = callExpression(callId, [node]); + } + const params = []; + for (const param of nodeParams) { + if (isAssignmentPattern(param) || isRestElement(param)) { + break; + } + params.push(path.scope.generateUidIdentifier("x")); + } + const wrapperArgs = { + NAME: functionId || null, + REF: path.scope.generateUidIdentifier(functionId ? functionId.name : "ref"), + FUNCTION: built, + PARAMS: params + }; + if (isDeclaration) { + const container = buildDeclarationWrapper(wrapperArgs); + path.replaceWith(container[0]); + path.insertAfter(container[1]); + } else { + let container; + if (functionId) { + container = buildNamedExpressionWrapper(wrapperArgs); + } else { + container = buildAnonymousExpressionWrapper(wrapperArgs); + const returnFn = container.callee.body.body[1].argument; + (0, _helperFunctionName.default)({ + node: returnFn, + parent: path.parent, + scope: path.scope + }); + functionId = returnFn.id; + } + if (functionId || !ignoreFunctionLength && params.length) { + path.replaceWith(container); + } else { + path.replaceWith(built); + } + } +} +function wrapFunction(path, callId, noNewArrows = true, ignoreFunctionLength = false) { + if (path.isMethod()) { + classOrObjectMethod(path, callId); + } else { + plainFunction(path, callId, noNewArrows, ignoreFunctionLength); + } +} + +//# sourceMappingURL=index.js.map diff --git a/node_modules/@babel/helper-wrap-function/lib/index.js.map b/node_modules/@babel/helper-wrap-function/lib/index.js.map new file mode 100644 index 00000000..3241e0dc --- /dev/null +++ b/node_modules/@babel/helper-wrap-function/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_helperFunctionName","require","_template","_t","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","_path$arrowFunctionTo","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 | t.FunctionDeclaration\n | t.FunctionExpression\n | t.CallExpression;\n } else {\n node = path.node as t.FunctionDeclaration | t.FunctionExpression;\n }\n\n const isDeclaration = isFunctionDeclaration(node);\n\n let built = node;\n if (!isCallExpression(node)) {\n functionId = node.id;\n node.id = null;\n node.type = \"FunctionExpression\";\n built = callExpression(callId, [\n node as Exclude<typeof node, t.FunctionDeclaration>,\n ]);\n }\n\n const params: t.Identifier[] = [];\n for (const param of nodeParams) {\n if (isAssignmentPattern(param) || isRestElement(param)) {\n break;\n }\n params.push(path.scope.generateUidIdentifier(\"x\"));\n }\n\n const wrapperArgs = {\n NAME: functionId || null,\n REF: path.scope.generateUidIdentifier(functionId ? functionId.name : \"ref\"),\n FUNCTION: built,\n PARAMS: params,\n };\n\n if (isDeclaration) {\n const container = buildDeclarationWrapper(wrapperArgs);\n path.replaceWith(container[0]);\n path.insertAfter(container[1]);\n } else {\n let container;\n\n if (functionId) {\n container = buildNamedExpressionWrapper(wrapperArgs);\n } else {\n container = buildAnonymousExpressionWrapper(wrapperArgs);\n\n const returnFn = container.callee.body.body[1].argument;\n nameFunction({\n node: returnFn,\n parent: (path as NodePath<t.FunctionExpression>).parent,\n scope: path.scope,\n });\n functionId = returnFn.id;\n }\n\n if (functionId || (!ignoreFunctionLength && params.length)) {\n path.replaceWith(container);\n } else {\n // we can omit this wrapper as the conditions it protects for do not apply\n path.replaceWith(built);\n }\n }\n}\n\nexport default function wrapFunction(\n path: NodePath<t.Function>,\n callId: t.Expression,\n // TODO(Babel 8): Consider defaulting to false for spec compliance\n noNewArrows: boolean = true,\n ignoreFunctionLength: boolean = false,\n) {\n if (path.isMethod()) {\n classOrObjectMethod(path, callId);\n } else {\n plainFunction(\n path as NodePath<Exclude<t.Function, t.Method>>,\n callId,\n noNewArrows,\n ignoreFunctionLength,\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,EAAA,GAAAF,OAAA;AASsB;EARpBG,cAAc;EACdC,cAAc;EACdC,kBAAkB;EAClBC,mBAAmB;EACnBC,qBAAqB;EACrBC,aAAa;EACbC,eAAe;EACfC;AAAgB,IAAAR,EAAA;AAqBlB,MAAMS,+BAA+B,GAAGC,iBAAQ,CAACC,UAAU,CAAE;AAC7D;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,CAEA;AAED,MAAMC,2BAA2B,GAAGF,iBAAQ,CAACC,UAAU,CAAE;AACzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC,CAEA;AAED,MAAME,uBAAuB,GAAGH,iBAAQ,CAACI,UAAU,CAAE;AACrD;AACA;AACA;AACA;AACA;AACA,CAAC,CAAC;AAEF,SAASC,mBAAmBA,CAC1BC,IAAqE,EACrEC,MAAoB,EACpB;EACA,MAAMC,IAAI,GAAGF,IAAI,CAACE,IAAI;EACtB,MAAMC,IAAI,GAAGD,IAAI,CAACC,IAAI;EAEtB,M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EAAE;IAC1B;IAEA,IAAIR,UAAU,IAAK,CAACD,oBAAoB,IAAIG,MAAM,CAACyB,MAAO,EAAE;MAC1DxC,IAAI,CAACiC,WAAW,CAAC7B,SAAS,CAAC;IAC7B,CAAC,MAAM;MAELJ,IAAI,CAACiC,WAAW,CAACb,KAAK,CAAC;IACzB;EACF;AACF;AAEe,SAASqB,YAAYA,CAClCzC,IAA0B,EAC1BC,MAAoB,EAEpBU,WAAoB,GAAG,IAAI,EAC3BC,oBAA6B,GAAG,KAAK,EACrC;EACA,IAAIZ,IAAI,CAAC0C,QAAQ,CAAC,CAAC,EAAE;IACnB3C,mBAAmB,CAACC,IAAI,EAAEC,MAAM,CAAC;EACnC,CAAC,MAAM;IACLQ,aAAa,CACXT,IAAI,EACJC,MAAM,EACNU,WAAW,EACXC,oBACF,CAAC;EACH;AACF"}
\ No newline at end of file diff --git a/node_modules/@babel/helper-wrap-function/package.json b/node_modules/@babel/helper-wrap-function/package.json new file mode 100644 index 00000000..41416065 --- /dev/null +++ b/node_modules/@babel/helper-wrap-function/package.json @@ -0,0 +1,29 @@ +{ + "name": "@babel/helper-wrap-function", + "version": "7.22.20", + "description": "Helper to wrap functions inside a function call.", + "repository": { + "type": "git", + "url": "https://github.com/babel/babel.git", + "directory": "packages/babel-helper-wrap-function" + }, + "homepage": "https://babel.dev/docs/en/next/babel-helper-wrap-function", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "./lib/index.js", + "dependencies": { + "@babel/helper-function-name": "^7.22.5", + "@babel/template": "^7.22.15", + "@babel/types": "^7.22.19" + }, + "engines": { + "node": ">=6.9.0" + }, + "devDependencies": { + "@babel/traverse": "^7.22.20" + }, + "author": "The Babel Team (https://babel.dev/team)", + "type": "commonjs" +}
\ No newline at end of file |
