@babel/helper-builder-binary-assignment-operator-visitor
Advanced tools
Comparing version 7.22.5 to 8.0.0-alpha.0
@@ -1,8 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = explode; | ||
var _t = require("@babel/types"); | ||
import * as _t from "@babel/types"; | ||
const { | ||
@@ -57,3 +51,3 @@ assignmentExpression, | ||
} | ||
function explode(node, nodes, scope) { | ||
export default function explode(node, nodes, scope) { | ||
const obj = getObjRef(node, nodes, scope); | ||
@@ -60,0 +54,0 @@ let ref, uid; |
@@ -1,14 +0,75 @@ | ||
"use strict"; | ||
import * as _t from '@babel/types'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
var _t = require("@babel/types"); | ||
var _explodeAssignableExpression = require("./explode-assignable-expression"); | ||
const { | ||
assignmentExpression: assignmentExpression$1, | ||
cloneNode, | ||
isIdentifier, | ||
isLiteral, | ||
isMemberExpression, | ||
isPrivateName, | ||
isPureish, | ||
isSuper, | ||
memberExpression, | ||
toComputedKey | ||
} = _t; | ||
function getObjRef(node, nodes, scope) { | ||
let ref; | ||
if (isIdentifier(node)) { | ||
if (scope.hasBinding(node.name)) { | ||
return node; | ||
} else { | ||
ref = node; | ||
} | ||
} else if (isMemberExpression(node)) { | ||
ref = node.object; | ||
if (isSuper(ref) || isIdentifier(ref) && scope.hasBinding(ref.name)) { | ||
return ref; | ||
} | ||
} else { | ||
throw new Error(`We can't explode this node type ${node["type"]}`); | ||
} | ||
const temp = scope.generateUidIdentifierBasedOnNode(ref); | ||
scope.push({ | ||
id: temp | ||
}); | ||
nodes.push(assignmentExpression$1("=", cloneNode(temp), cloneNode(ref))); | ||
return temp; | ||
} | ||
function getPropRef(node, nodes, scope) { | ||
const prop = node.property; | ||
if (isPrivateName(prop)) { | ||
throw new Error("We can't generate property ref for private name, please install `@babel/plugin-transform-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(assignmentExpression$1("=", cloneNode(temp), cloneNode(prop))); | ||
return temp; | ||
} | ||
function explode(node, nodes, scope) { | ||
const obj = getObjRef(node, nodes, scope); | ||
let ref, uid; | ||
if (isIdentifier(node)) { | ||
ref = cloneNode(node); | ||
uid = obj; | ||
} else { | ||
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 { | ||
uid: uid, | ||
ref: ref | ||
}; | ||
} | ||
const { | ||
assignmentExpression, | ||
sequenceExpression | ||
} = _t; | ||
function _default(opts) { | ||
function index (opts) { | ||
const { | ||
@@ -26,3 +87,3 @@ build, | ||
const nodes = []; | ||
const exploded = (0, _explodeAssignableExpression.default)(node.left, nodes, scope); | ||
const exploded = explode(node.left, nodes, scope); | ||
nodes.push(assignmentExpression("=", exploded.ref, build(exploded.uid, node.right))); | ||
@@ -43,2 +104,3 @@ path.replaceWith(sequenceExpression(nodes)); | ||
export { index as default }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/helper-builder-binary-assignment-operator-visitor", | ||
"version": "7.22.5", | ||
"version": "8.0.0-alpha.0", | ||
"description": "Helper function to build binary assignment operator visitors", | ||
@@ -17,12 +17,16 @@ "repository": { | ||
"dependencies": { | ||
"@babel/types": "^7.22.5" | ||
"@babel/types": "^8.0.0-alpha.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/traverse": "^7.22.5" | ||
"@babel/traverse": "^8.0.0-alpha.0" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
"node": "^16.20.0 || ^18.16.0 || >=20.0.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"type": "commonjs" | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "module" | ||
} |
@@ -5,3 +5,3 @@ # @babel/helper-builder-binary-assignment-operator-visitor | ||
See our website [@babel/helper-builder-binary-assignment-operator-visitor](https://babeljs.io/docs/en/babel-helper-builder-binary-assignment-operator-visitor) for more information. | ||
See our website [@babel/helper-builder-binary-assignment-operator-visitor](https://babeljs.io/docs/babel-helper-builder-binary-assignment-operator-visitor) for more information. | ||
@@ -8,0 +8,0 @@ ## Install |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20982
169
Yes
2
+ Added@babel/helper-string-parser@8.0.0-alpha.8(transitive)
+ Added@babel/helper-validator-identifier@8.0.0-alpha.8(transitive)
+ Added@babel/types@8.0.0-alpha.8(transitive)
+ Addedto-fast-properties@3.0.1(transitive)
- Removed@babel/helper-string-parser@7.24.1(transitive)
- Removed@babel/helper-validator-identifier@7.24.5(transitive)
- Removed@babel/types@7.24.5(transitive)
- Removedto-fast-properties@2.0.0(transitive)
Updated@babel/types@^8.0.0-alpha.0