index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. const {
  9. assignmentExpression,
  10. sequenceExpression
  11. } = _t;
  12. function _default(opts) {
  13. const {
  14. build,
  15. operator
  16. } = opts;
  17. const visitor = {
  18. AssignmentExpression(path) {
  19. const {
  20. node,
  21. scope
  22. } = path;
  23. if (node.operator !== operator + "=") return;
  24. const nodes = [];
  25. const exploded = (0, _helperExplodeAssignableExpression.default)(node.left, nodes, this, scope);
  26. nodes.push(assignmentExpression("=", exploded.ref, build(exploded.uid, node.right)));
  27. path.replaceWith(sequenceExpression(nodes));
  28. },
  29. BinaryExpression(path) {
  30. const {
  31. node
  32. } = path;
  33. if (node.operator === operator) {
  34. path.replaceWith(build(node.left, node.right));
  35. }
  36. }
  37. };
  38. return visitor;
  39. }