update
This commit is contained in:
+3
-3
@@ -2,18 +2,18 @@
|
||||
|
||||
> Babel helper for ensuring that access to a given value is performed through simple accesses
|
||||
|
||||
See our website [@babel/helper-simple-access](https://babeljs.io/docs/en/next/babel-helper-simple-access.html) for more information.
|
||||
See our website [@babel/helper-simple-access](https://babeljs.io/docs/en/babel-helper-simple-access) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-simple-access
|
||||
npm install --save @babel/helper-simple-access
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-simple-access --dev
|
||||
yarn add @babel/helper-simple-access
|
||||
```
|
||||
|
||||
+34
-13
@@ -5,17 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = simplifyAccess;
|
||||
|
||||
var t = _interopRequireWildcard(require("@babel/types"));
|
||||
var _t = require("@babel/types");
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
const {
|
||||
LOGICAL_OPERATORS,
|
||||
assignmentExpression,
|
||||
binaryExpression,
|
||||
cloneNode,
|
||||
identifier,
|
||||
logicalExpression,
|
||||
numericLiteral,
|
||||
sequenceExpression,
|
||||
unaryExpression
|
||||
} = _t;
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function simplifyAccess(path, bindingNames) {
|
||||
function simplifyAccess(path, bindingNames, includeUpdateExpression = true) {
|
||||
path.traverse(simpleAssignmentVisitor, {
|
||||
scope: path.scope,
|
||||
bindingNames,
|
||||
seen: new WeakSet()
|
||||
seen: new WeakSet(),
|
||||
includeUpdateExpression
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,8 +33,14 @@ const simpleAssignmentVisitor = {
|
||||
exit(path) {
|
||||
const {
|
||||
scope,
|
||||
bindingNames
|
||||
bindingNames,
|
||||
includeUpdateExpression
|
||||
} = this;
|
||||
|
||||
if (!includeUpdateExpression) {
|
||||
return;
|
||||
}
|
||||
|
||||
const arg = path.get("argument");
|
||||
if (!arg.isIdentifier()) return;
|
||||
const localName = arg.node.name;
|
||||
@@ -37,17 +52,17 @@ const simpleAssignmentVisitor = {
|
||||
|
||||
if (path.parentPath.isExpressionStatement() && !path.isCompletionRecord()) {
|
||||
const operator = path.node.operator == "++" ? "+=" : "-=";
|
||||
path.replaceWith(t.assignmentExpression(operator, arg.node, t.numericLiteral(1)));
|
||||
path.replaceWith(assignmentExpression(operator, arg.node, numericLiteral(1)));
|
||||
} else if (path.node.prefix) {
|
||||
path.replaceWith(t.assignmentExpression("=", t.identifier(localName), t.binaryExpression(path.node.operator[0], t.unaryExpression("+", arg.node), t.numericLiteral(1))));
|
||||
path.replaceWith(assignmentExpression("=", identifier(localName), binaryExpression(path.node.operator[0], unaryExpression("+", arg.node), numericLiteral(1))));
|
||||
} else {
|
||||
const old = path.scope.generateUidIdentifierBasedOnNode(arg.node, "old");
|
||||
const varName = old.name;
|
||||
path.scope.push({
|
||||
id: old
|
||||
});
|
||||
const binary = t.binaryExpression(path.node.operator[0], t.identifier(varName), t.numericLiteral(1));
|
||||
path.replaceWith(t.sequenceExpression([t.assignmentExpression("=", t.identifier(varName), t.unaryExpression("+", arg.node)), t.assignmentExpression("=", t.cloneNode(arg.node), binary), t.identifier(varName)]));
|
||||
const binary = binaryExpression(path.node.operator[0], identifier(varName), numericLiteral(1));
|
||||
path.replaceWith(sequenceExpression([assignmentExpression("=", identifier(varName), unaryExpression("+", arg.node)), assignmentExpression("=", cloneNode(arg.node), binary), identifier(varName)]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +86,14 @@ const simpleAssignmentVisitor = {
|
||||
return;
|
||||
}
|
||||
|
||||
path.node.right = t.binaryExpression(path.node.operator.slice(0, -1), t.cloneNode(path.node.left), path.node.right);
|
||||
path.node.operator = "=";
|
||||
const operator = path.node.operator.slice(0, -1);
|
||||
|
||||
if (LOGICAL_OPERATORS.includes(operator)) {
|
||||
path.replaceWith(logicalExpression(operator, path.node.left, assignmentExpression("=", cloneNode(path.node.left), path.node.right)));
|
||||
} else {
|
||||
path.node.right = binaryExpression(operator, cloneNode(path.node.left), path.node.right);
|
||||
path.node.operator = "=";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
-19
@@ -1,50 +1,54 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"@babel/helper-simple-access@7.10.4",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"@babel/helper-simple-access@7.18.6",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "@babel/helper-simple-access@7.10.4",
|
||||
"_id": "@babel/helper-simple-access@7.10.4",
|
||||
"_from": "@babel/helper-simple-access@7.18.6",
|
||||
"_id": "@babel/helper-simple-access@7.18.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-0fMy72ej/VEvF8ULmX6yb5MtHG4uH4Dbd6I/aHDb/JVg0bbivwt9Wg+h3uMvX+QSFtwr5MeItvazbrc4jtRAXw==",
|
||||
"_integrity": "sha512-iNpIgTgyAvDQpDj76POqg+YEt8fPxx3yaNBg3S30dxNKm2SWfYhD0TGrK/Eu9wHpUW63VQU894TsTg+GLbUa1g==",
|
||||
"_location": "/@babel/helper-simple-access",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@babel/helper-simple-access@7.10.4",
|
||||
"raw": "@babel/helper-simple-access@7.18.6",
|
||||
"name": "@babel/helper-simple-access",
|
||||
"escapedName": "@babel%2fhelper-simple-access",
|
||||
"scope": "@babel",
|
||||
"rawSpec": "7.10.4",
|
||||
"rawSpec": "7.18.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "7.10.4"
|
||||
"fetchSpec": "7.18.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@babel/helper-module-transforms",
|
||||
"/@babel/plugin-transform-modules-commonjs"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.10.4.tgz",
|
||||
"_spec": "7.10.4",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.18.6.tgz",
|
||||
"_spec": "7.18.6",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Logan Smyth",
|
||||
"email": "loganfsmyth@gmail.com"
|
||||
"name": "The Babel Team",
|
||||
"url": "https://babel.dev/team"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/babel/babel/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.10.4",
|
||||
"@babel/types": "^7.10.4"
|
||||
"@babel/types": "^7.18.6"
|
||||
},
|
||||
"description": "Babel helper for ensuring that access to a given value is performed through simple accesses",
|
||||
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"devDependencies": {
|
||||
"@babel/traverse": "^7.18.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-simple-access",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"main": "./lib/index.js",
|
||||
"name": "@babel/helper-simple-access",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
@@ -54,5 +58,6 @@
|
||||
"url": "git+https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-simple-access"
|
||||
},
|
||||
"version": "7.10.4"
|
||||
"type": "commonjs",
|
||||
"version": "7.18.6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user