update
This commit is contained in:
+3
-3
@@ -2,18 +2,18 @@
|
||||
|
||||
> Helper function to explode an assignable expression
|
||||
|
||||
See our website [@babel/helper-explode-assignable-expression](https://babeljs.io/docs/en/next/babel-helper-explode-assignable-expression.html) for more information.
|
||||
See our website [@babel/helper-explode-assignable-expression](https://babeljs.io/docs/en/babel-helper-explode-assignable-expression) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
Using npm:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @babel/helper-explode-assignable-expression
|
||||
npm install --save @babel/helper-explode-assignable-expression
|
||||
```
|
||||
|
||||
or using yarn:
|
||||
|
||||
```sh
|
||||
yarn add @babel/helper-explode-assignable-expression --dev
|
||||
yarn add @babel/helper-explode-assignable-expression
|
||||
```
|
||||
|
||||
+36
-24
@@ -5,72 +5,84 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = _default;
|
||||
|
||||
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 {
|
||||
assignmentExpression,
|
||||
cloneNode,
|
||||
isIdentifier,
|
||||
isLiteral,
|
||||
isMemberExpression,
|
||||
isPrivateName,
|
||||
isPureish,
|
||||
isSuper,
|
||||
memberExpression,
|
||||
toComputedKey
|
||||
} = _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 getObjRef(node, nodes, file, scope) {
|
||||
function getObjRef(node, nodes, scope) {
|
||||
let ref;
|
||||
|
||||
if (t.isSuper(node)) {
|
||||
return node;
|
||||
} else if (t.isIdentifier(node)) {
|
||||
if (isIdentifier(node)) {
|
||||
if (scope.hasBinding(node.name)) {
|
||||
return node;
|
||||
} else {
|
||||
ref = node;
|
||||
}
|
||||
} else if (t.isMemberExpression(node)) {
|
||||
} else if (isMemberExpression(node)) {
|
||||
ref = node.object;
|
||||
|
||||
if (t.isSuper(ref) || t.isIdentifier(ref) && scope.hasBinding(ref.name)) {
|
||||
if (isSuper(ref) || isIdentifier(ref) && scope.hasBinding(ref.name)) {
|
||||
return ref;
|
||||
}
|
||||
} else {
|
||||
throw new Error(`We can't explode this node type ${node.type}`);
|
||||
throw new Error(`We can't explode this node type ${node["type"]}`);
|
||||
}
|
||||
|
||||
const temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||
scope.push({
|
||||
id: temp
|
||||
});
|
||||
nodes.push(t.assignmentExpression("=", t.cloneNode(temp), t.cloneNode(ref)));
|
||||
nodes.push(assignmentExpression("=", cloneNode(temp), cloneNode(ref)));
|
||||
return temp;
|
||||
}
|
||||
|
||||
function getPropRef(node, nodes, file, scope) {
|
||||
function getPropRef(node, nodes, scope) {
|
||||
const prop = node.property;
|
||||
const key = t.toComputedKey(node, prop);
|
||||
if (t.isLiteral(key) && t.isPureish(key)) return key;
|
||||
|
||||
if (isPrivateName(prop)) {
|
||||
throw new Error("We can't generate property ref for private name, please install `@babel/plugin-proposal-class-properties`");
|
||||
}
|
||||
|
||||
const key = toComputedKey(node, prop);
|
||||
if (isLiteral(key) && isPureish(key)) return key;
|
||||
const temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||
scope.push({
|
||||
id: temp
|
||||
});
|
||||
nodes.push(t.assignmentExpression("=", t.cloneNode(temp), t.cloneNode(prop)));
|
||||
nodes.push(assignmentExpression("=", cloneNode(temp), cloneNode(prop)));
|
||||
return temp;
|
||||
}
|
||||
|
||||
function _default(node, nodes, file, scope, allowedSingleIdent) {
|
||||
let obj;
|
||||
|
||||
if (t.isIdentifier(node) && allowedSingleIdent) {
|
||||
if (isIdentifier(node) && allowedSingleIdent) {
|
||||
obj = node;
|
||||
} else {
|
||||
obj = getObjRef(node, nodes, file, scope);
|
||||
obj = getObjRef(node, nodes, scope);
|
||||
}
|
||||
|
||||
let ref, uid;
|
||||
|
||||
if (t.isIdentifier(node)) {
|
||||
ref = t.cloneNode(node);
|
||||
if (isIdentifier(node)) {
|
||||
ref = cloneNode(node);
|
||||
uid = obj;
|
||||
} else {
|
||||
const prop = getPropRef(node, nodes, file, scope);
|
||||
const computed = node.computed || t.isLiteral(prop);
|
||||
uid = t.memberExpression(t.cloneNode(obj), t.cloneNode(prop), computed);
|
||||
ref = t.memberExpression(t.cloneNode(obj), t.cloneNode(prop), computed);
|
||||
const prop = getPropRef(node, nodes, scope);
|
||||
const computed = node.computed || isLiteral(prop);
|
||||
uid = memberExpression(cloneNode(obj), cloneNode(prop), computed);
|
||||
ref = memberExpression(cloneNode(obj), cloneNode(prop), computed);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
+26
-17
@@ -1,45 +1,53 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"@babel/helper-explode-assignable-expression@7.10.4",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"@babel/helper-explode-assignable-expression@7.18.6",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "@babel/helper-explode-assignable-expression@7.10.4",
|
||||
"_id": "@babel/helper-explode-assignable-expression@7.10.4",
|
||||
"_from": "@babel/helper-explode-assignable-expression@7.18.6",
|
||||
"_id": "@babel/helper-explode-assignable-expression@7.18.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-4K71RyRQNPRrR85sr5QY4X3VwG4wtVoXZB9+L3r1Gp38DhELyHCtovqydRi7c1Ovb17eRGiQ/FD5s8JdU0Uy5A==",
|
||||
"_integrity": "sha512-eyAYAsQmB80jNfg4baAtLeWAQHfHFiR483rzFK+BhETlGZaQC9bsfrugfXDCbRHLQbIA7U5NxhhOxN7p/dWIcg==",
|
||||
"_location": "/@babel/helper-explode-assignable-expression",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@babel/helper-explode-assignable-expression@7.10.4",
|
||||
"raw": "@babel/helper-explode-assignable-expression@7.18.6",
|
||||
"name": "@babel/helper-explode-assignable-expression",
|
||||
"escapedName": "@babel%2fhelper-explode-assignable-expression",
|
||||
"scope": "@babel",
|
||||
"rawSpec": "7.10.4",
|
||||
"rawSpec": "7.18.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "7.10.4"
|
||||
"fetchSpec": "7.18.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@babel/helper-builder-binary-assignment-operator-visitor"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.10.4.tgz",
|
||||
"_spec": "7.10.4",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.18.6.tgz",
|
||||
"_spec": "7.18.6",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "The Babel Team",
|
||||
"url": "https://babel.dev/team"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/babel/babel/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/traverse": "^7.10.4",
|
||||
"@babel/types": "^7.10.4"
|
||||
"@babel/types": "^7.18.6"
|
||||
},
|
||||
"description": "Helper function to explode an assignable expression",
|
||||
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df",
|
||||
"homepage": "https://github.com/babel/babel#readme",
|
||||
"devDependencies": {
|
||||
"@babel/traverse": "^7.18.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-helper-explode-assignable-expression",
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"main": "./lib/index.js",
|
||||
"name": "@babel/helper-explode-assignable-expression",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
@@ -49,5 +57,6 @@
|
||||
"url": "git+https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-helper-explode-assignable-expression"
|
||||
},
|
||||
"version": "7.10.4"
|
||||
"type": "commonjs",
|
||||
"version": "7.18.6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user