index.js 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _default;
  6. var _helperExplodeAssignableExpression = require("@babel/helper-explode-assignable-expression");
  7. var t = require("@babel/types");
  8. function _default(opts) {
  9. const {
  10. build,
  11. operator
  12. } = opts;
  13. return {
  14. AssignmentExpression(path) {
  15. const {
  16. node,
  17. scope
  18. } = path;
  19. if (node.operator !== operator + "=") return;
  20. const nodes = [];
  21. const exploded = (0, _helperExplodeAssignableExpression.default)(node.left, nodes, this, scope);
  22. nodes.push(t.assignmentExpression("=", exploded.ref, build(exploded.uid, node.right)));
  23. path.replaceWith(t.sequenceExpression(nodes));
  24. },
  25. BinaryExpression(path) {
  26. const {
  27. node
  28. } = path;
  29. if (node.operator === operator) {
  30. path.replaceWith(build(node.left, node.right));
  31. }
  32. }
  33. };
  34. }