This commit is contained in:
2023-08-11 10:45:20 +08:00
commit 161ca982f3
31850 changed files with 2706500 additions and 0 deletions

View File

@ -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.

View File

@ -0,0 +1,19 @@
# @babel/helper-member-expression-to-functions
> Helper function to replace certain member expressions with function calls
See our website [@babel/helper-member-expression-to-functions](https://babeljs.io/docs/en/babel-helper-member-expression-to-functions) for more information.
## Install
Using npm:
```sh
npm install --save @babel/helper-member-expression-to-functions
```
or using yarn:
```sh
yarn add @babel/helper-member-expression-to-functions
```

View File

@ -0,0 +1,391 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _t = require('@babel/types');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var _t__namespace = /*#__PURE__*/_interopNamespace(_t);
function willPathCastToBoolean(path) {
const maybeWrapped = path;
const {
node,
parentPath
} = maybeWrapped;
if (parentPath.isLogicalExpression()) {
const {
operator,
right
} = parentPath.node;
if (operator === "&&" || operator === "||" || operator === "??" && node === right) {
return willPathCastToBoolean(parentPath);
}
}
if (parentPath.isSequenceExpression()) {
const {
expressions
} = parentPath.node;
if (expressions[expressions.length - 1] === node) {
return willPathCastToBoolean(parentPath);
} else {
return true;
}
}
return parentPath.isConditional({
test: node
}) || parentPath.isUnaryExpression({
operator: "!"
}) || parentPath.isLoop({
test: node
});
}
const {
LOGICAL_OPERATORS,
arrowFunctionExpression,
assignmentExpression,
binaryExpression,
booleanLiteral,
callExpression,
cloneNode,
conditionalExpression,
identifier,
isMemberExpression,
isOptionalCallExpression,
isOptionalMemberExpression,
isUpdateExpression,
logicalExpression,
memberExpression,
nullLiteral,
optionalCallExpression,
optionalMemberExpression,
sequenceExpression,
updateExpression
} = _t__namespace;
class AssignmentMemoiser {
constructor() {
this._map = void 0;
this._map = new WeakMap();
}
has(key) {
return this._map.has(key);
}
get(key) {
if (!this.has(key)) return;
const record = this._map.get(key);
const {
value
} = record;
record.count--;
if (record.count === 0) {
return assignmentExpression("=", value, key);
}
return value;
}
set(key, value, count) {
return this._map.set(key, {
count,
value
});
}
}
function toNonOptional(path, base) {
const {
node
} = path;
if (isOptionalMemberExpression(node)) {
return memberExpression(base, node.property, node.computed);
}
if (path.isOptionalCallExpression()) {
const callee = path.get("callee");
if (path.node.optional && callee.isOptionalMemberExpression()) {
const object = callee.node.object;
const context = path.scope.maybeGenerateMemoised(object);
callee.get("object").replaceWith(assignmentExpression("=", context, object));
return callExpression(memberExpression(base, identifier("call")), [context, ...path.node.arguments]);
}
return callExpression(base, path.node.arguments);
}
return path.node;
}
function isInDetachedTree(path) {
while (path) {
if (path.isProgram()) break;
const {
parentPath,
container,
listKey
} = path;
const parentNode = parentPath.node;
if (listKey) {
if (container !== parentNode[listKey]) {
return true;
}
} else {
if (container !== parentNode) return true;
}
path = parentPath;
}
return false;
}
const handle = {
memoise() {},
handle(member, noDocumentAll) {
const {
node,
parent,
parentPath,
scope
} = member;
if (member.isOptionalMemberExpression()) {
if (isInDetachedTree(member)) return;
const endPath = member.find(({
node,
parent
}) => {
if (isOptionalMemberExpression(parent)) {
return parent.optional || parent.object !== node;
}
if (isOptionalCallExpression(parent)) {
return node !== member.node && parent.optional || parent.callee !== node;
}
return true;
});
if (scope.path.isPattern()) {
endPath.replaceWith(callExpression(arrowFunctionExpression([], endPath.node), []));
return;
}
const willEndPathCastToBoolean = willPathCastToBoolean(endPath);
const rootParentPath = endPath.parentPath;
if (rootParentPath.isUpdateExpression({
argument: node
}) || rootParentPath.isAssignmentExpression({
left: node
})) {
throw member.buildCodeFrameError(`can't handle assignment`);
}
const isDeleteOperation = rootParentPath.isUnaryExpression({
operator: "delete"
});
if (isDeleteOperation && endPath.isOptionalMemberExpression() && endPath.get("property").isPrivateName()) {
throw member.buildCodeFrameError(`can't delete a private class element`);
}
let startingOptional = member;
for (;;) {
if (startingOptional.isOptionalMemberExpression()) {
if (startingOptional.node.optional) break;
startingOptional = startingOptional.get("object");
continue;
} else if (startingOptional.isOptionalCallExpression()) {
if (startingOptional.node.optional) break;
startingOptional = startingOptional.get("callee");
continue;
}
throw new Error(`Internal error: unexpected ${startingOptional.node.type}`);
}
const startingNode = startingOptional.isOptionalMemberExpression() ? startingOptional.node.object : startingOptional.node.callee;
const baseNeedsMemoised = scope.maybeGenerateMemoised(startingNode);
const baseRef = baseNeedsMemoised != null ? baseNeedsMemoised : startingNode;
const parentIsOptionalCall = parentPath.isOptionalCallExpression({
callee: node
});
const isOptionalCall = parent => parentIsOptionalCall;
const parentIsCall = parentPath.isCallExpression({
callee: node
});
startingOptional.replaceWith(toNonOptional(startingOptional, baseRef));
if (isOptionalCall()) {
if (parent.optional) {
parentPath.replaceWith(this.optionalCall(member, parent.arguments));
} else {
parentPath.replaceWith(this.call(member, parent.arguments));
}
} else if (parentIsCall) {
member.replaceWith(this.boundGet(member));
} else if (this.delete && parentPath.isUnaryExpression({
operator: "delete"
})) {
parentPath.replaceWith(this.delete(member));
} else {
member.replaceWith(this.get(member));
}
let regular = member.node;
for (let current = member; current !== endPath;) {
const parentPath = current.parentPath;
if (parentPath === endPath && isOptionalCall() && parent.optional) {
regular = parentPath.node;
break;
}
regular = toNonOptional(parentPath, regular);
current = parentPath;
}
let context;
const endParentPath = endPath.parentPath;
if (isMemberExpression(regular) && endParentPath.isOptionalCallExpression({
callee: endPath.node,
optional: true
})) {
const {
object
} = regular;
context = member.scope.maybeGenerateMemoised(object);
if (context) {
regular.object = assignmentExpression("=", context, object);
}
}
let replacementPath = endPath;
if (isDeleteOperation) {
replacementPath = endParentPath;
regular = endParentPath.node;
}
const baseMemoised = baseNeedsMemoised ? assignmentExpression("=", cloneNode(baseRef), cloneNode(startingNode)) : cloneNode(baseRef);
if (willEndPathCastToBoolean) {
let nonNullishCheck;
if (noDocumentAll) {
nonNullishCheck = binaryExpression("!=", baseMemoised, nullLiteral());
} else {
nonNullishCheck = logicalExpression("&&", binaryExpression("!==", baseMemoised, nullLiteral()), binaryExpression("!==", cloneNode(baseRef), scope.buildUndefinedNode()));
}
replacementPath.replaceWith(logicalExpression("&&", nonNullishCheck, regular));
} else {
let nullishCheck;
if (noDocumentAll) {
nullishCheck = binaryExpression("==", baseMemoised, nullLiteral());
} else {
nullishCheck = logicalExpression("||", binaryExpression("===", baseMemoised, nullLiteral()), binaryExpression("===", cloneNode(baseRef), scope.buildUndefinedNode()));
}
replacementPath.replaceWith(conditionalExpression(nullishCheck, isDeleteOperation ? booleanLiteral(true) : scope.buildUndefinedNode(), regular));
}
if (context) {
const endParent = endParentPath.node;
endParentPath.replaceWith(optionalCallExpression(optionalMemberExpression(endParent.callee, identifier("call"), false, true), [cloneNode(context), ...endParent.arguments], false));
}
return;
}
if (isUpdateExpression(parent, {
argument: node
})) {
if (this.simpleSet) {
member.replaceWith(this.simpleSet(member));
return;
}
const {
operator,
prefix
} = parent;
this.memoise(member, 2);
const ref = scope.generateUidIdentifierBasedOnNode(node);
scope.push({
id: ref
});
const seq = [assignmentExpression("=", cloneNode(ref), this.get(member))];
if (prefix) {
seq.push(updateExpression(operator, cloneNode(ref), prefix));
const value = sequenceExpression(seq);
parentPath.replaceWith(this.set(member, value));
return;
} else {
const ref2 = scope.generateUidIdentifierBasedOnNode(node);
scope.push({
id: ref2
});
seq.push(assignmentExpression("=", cloneNode(ref2), updateExpression(operator, cloneNode(ref), prefix)), cloneNode(ref));
const value = sequenceExpression(seq);
parentPath.replaceWith(sequenceExpression([this.set(member, value), cloneNode(ref2)]));
return;
}
}
if (parentPath.isAssignmentExpression({
left: node
})) {
if (this.simpleSet) {
member.replaceWith(this.simpleSet(member));
return;
}
const {
operator,
right: value
} = parentPath.node;
if (operator === "=") {
parentPath.replaceWith(this.set(member, value));
} else {
const operatorTrunc = operator.slice(0, -1);
if (LOGICAL_OPERATORS.includes(operatorTrunc)) {
this.memoise(member, 1);
parentPath.replaceWith(logicalExpression(operatorTrunc, this.get(member), this.set(member, value)));
} else {
this.memoise(member, 2);
parentPath.replaceWith(this.set(member, binaryExpression(operatorTrunc, this.get(member), value)));
}
}
return;
}
if (parentPath.isCallExpression({
callee: node
})) {
parentPath.replaceWith(this.call(member, parentPath.node.arguments));
return;
}
if (parentPath.isOptionalCallExpression({
callee: node
})) {
if (scope.path.isPattern()) {
parentPath.replaceWith(callExpression(arrowFunctionExpression([], parentPath.node), []));
return;
}
parentPath.replaceWith(this.optionalCall(member, parentPath.node.arguments));
return;
}
if (this.delete && parentPath.isUnaryExpression({
operator: "delete"
})) {
parentPath.replaceWith(this.delete(member));
return;
}
if (parentPath.isForXStatement({
left: node
}) || parentPath.isObjectProperty({
value: node
}) && parentPath.parentPath.isObjectPattern() || parentPath.isAssignmentPattern({
left: node
}) && parentPath.parentPath.isObjectProperty({
value: parent
}) && parentPath.parentPath.parentPath.isObjectPattern() || parentPath.isArrayPattern() || parentPath.isAssignmentPattern({
left: node
}) && parentPath.parentPath.isArrayPattern() || parentPath.isRestElement()) {
member.replaceWith(this.destructureSet(member));
return;
}
if (parentPath.isTaggedTemplateExpression()) {
member.replaceWith(this.boundGet(member));
} else {
member.replaceWith(this.get(member));
}
}
};
function memberExpressionToFunctions(path, visitor, state) {
path.traverse(visitor, Object.assign({}, handle, state, {
memoiser: new AssignmentMemoiser()
}));
}
exports["default"] = memberExpressionToFunctions;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.willPathCastToBoolean = willPathCastToBoolean;
function willPathCastToBoolean(path) {
const maybeWrapped = path;
const {
node,
parentPath
} = maybeWrapped;
if (parentPath.isLogicalExpression()) {
const {
operator,
right
} = parentPath.node;
if (operator === "&&" || operator === "||" || operator === "??" && node === right) {
return willPathCastToBoolean(parentPath);
}
}
if (parentPath.isSequenceExpression()) {
const {
expressions
} = parentPath.node;
if (expressions[expressions.length - 1] === node) {
return willPathCastToBoolean(parentPath);
} else {
return true;
}
}
return parentPath.isConditional({
test: node
}) || parentPath.isUnaryExpression({
operator: "!"
}) || parentPath.isLoop({
test: node
});
}
//# sourceMappingURL=util.js.map

View File

@ -0,0 +1 @@
{"version":3,"names":["willPathCastToBoolean","path","maybeWrapped","node","parentPath","isLogicalExpression","operator","right","isSequenceExpression","expressions","length","isConditional","test","isUnaryExpression","isLoop"],"sources":["../src/util.ts"],"sourcesContent":["import type { NodePath } from \"@babel/traverse\";\n\n/**\n * Test if a NodePath will be cast to boolean when evaluated.\n *\n * @example\n * // returns true\n * const nodePathAQDotB = NodePath(\"if (a?.#b) {}\").get(\"test\"); // a?.#b\n * willPathCastToBoolean(nodePathAQDotB)\n * @example\n * // returns false\n * willPathCastToBoolean(NodePath(\"a?.#b\"))\n * @todo Respect transparent expression wrappers\n * @see {@link packages/babel-plugin-transform-optional-chaining/src/util.js}\n * @param {NodePath} path\n * @returns {boolean}\n */\nexport function willPathCastToBoolean(path: NodePath): boolean {\n const maybeWrapped = path;\n const { node, parentPath } = maybeWrapped;\n if (parentPath.isLogicalExpression()) {\n const { operator, right } = parentPath.node;\n if (\n operator === \"&&\" ||\n operator === \"||\" ||\n (operator === \"??\" && node === right)\n ) {\n return willPathCastToBoolean(parentPath);\n }\n }\n if (parentPath.isSequenceExpression()) {\n const { expressions } = parentPath.node;\n if (expressions[expressions.length - 1] === node) {\n return willPathCastToBoolean(parentPath);\n } else {\n // if it is in the middle of a sequence expression, we don't\n // care the return value so just cast to boolean for smaller\n // output\n return true;\n }\n }\n return (\n parentPath.isConditional({ test: node }) ||\n parentPath.isUnaryExpression({ operator: \"!\" }) ||\n parentPath.isLoop({ test: node })\n );\n}\n"],"mappings":";;;;;;AAiBO,SAASA,qBAAqBA,CAACC,IAAc,EAAW;EAC7D,MAAMC,YAAY,GAAGD,IAAI;EACzB,MAAM;IAAEE,IAAI;IAAEC;EAAW,CAAC,GAAGF,YAAY;EACzC,IAAIE,UAAU,CAACC,mBAAmB,CAAC,CAAC,EAAE;IACpC,MAAM;MAAEC,QAAQ;MAAEC;IAAM,CAAC,GAAGH,UAAU,CAACD,IAAI;IAC3C,IACEG,QAAQ,KAAK,IAAI,IACjBA,QAAQ,KAAK,IAAI,IAChBA,QAAQ,KAAK,IAAI,IAAIH,IAAI,KAAKI,KAAM,EACrC;MACA,OAAOP,qBAAqB,CAACI,UAAU,CAAC;IAC1C;EACF;EACA,IAAIA,UAAU,CAACI,oBAAoB,CAAC,CAAC,EAAE;IACrC,MAAM;MAAEC;IAAY,CAAC,GAAGL,UAAU,CAACD,IAAI;IACvC,IAAIM,WAAW,CAACA,WAAW,CAACC,MAAM,GAAG,CAAC,CAAC,KAAKP,IAAI,EAAE;MAChD,OAAOH,qBAAqB,CAACI,UAAU,CAAC;IAC1C,CAAC,MAAM;MAIL,OAAO,IAAI;IACb;EACF;EACA,OACEA,UAAU,CAACO,aAAa,CAAC;IAAEC,IAAI,EAAET;EAAK,CAAC,CAAC,IACxCC,UAAU,CAACS,iBAAiB,CAAC;IAAEP,QAAQ,EAAE;EAAI,CAAC,CAAC,IAC/CF,UAAU,CAACU,MAAM,CAAC;IAAEF,IAAI,EAAET;EAAK,CAAC,CAAC;AAErC"}

View File

@ -0,0 +1,60 @@
{
"_from": "@babel/helper-member-expression-to-functions@^7.22.5",
"_id": "@babel/helper-member-expression-to-functions@7.22.5",
"_inBundle": false,
"_integrity": "sha512-aBiH1NKMG0H2cGZqspNvsaBe6wNGjbJjuLy29aU+eDZjSbbN53BaxlpB02xm9v34pLTZ1nIQPFYn2qMZoa5BQQ==",
"_location": "/@babel/helper-member-expression-to-functions",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@babel/helper-member-expression-to-functions@^7.22.5",
"name": "@babel/helper-member-expression-to-functions",
"escapedName": "@babel%2fhelper-member-expression-to-functions",
"scope": "@babel",
"rawSpec": "^7.22.5",
"saveSpec": null,
"fetchSpec": "^7.22.5"
},
"_requiredBy": [
"/@babel/helper-create-class-features-plugin",
"/@babel/helper-replace-supers"
],
"_resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.22.5.tgz",
"_shasum": "0a7c56117cad3372fbf8d2fb4bf8f8d64a1e76b2",
"_spec": "@babel/helper-member-expression-to-functions@^7.22.5",
"_where": "C:\\Users\\zhouxueli\\Desktop\\scheduling-app\\node_modules\\@babel\\helper-create-class-features-plugin",
"author": {
"name": "The Babel Team",
"url": "https://babel.dev/team"
},
"bugs": {
"url": "https://github.com/babel/babel/issues"
},
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.22.5"
},
"deprecated": false,
"description": "Helper function to replace certain member expressions with function calls",
"devDependencies": {
"@babel/traverse": "^7.22.5"
},
"engines": {
"node": ">=6.9.0"
},
"homepage": "https://babel.dev/docs/en/next/babel-helper-member-expression-to-functions",
"license": "MIT",
"main": "./lib/index.js",
"name": "@babel/helper-member-expression-to-functions",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/babel/babel.git",
"directory": "packages/babel-helper-member-expression-to-functions"
},
"type": "commonjs",
"version": "7.22.5"
}