1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
8 | var _core = require("@babel/core");
|
---|
9 | var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
|
---|
10 | api.assertVersion("^7.0.0-0 || >8.0.0-alpha <8.0.0-beta");
|
---|
11 | return {
|
---|
12 | name: "transform-logical-assignment-operators",
|
---|
13 | manipulateOptions: (_, parser) => parser.plugins.push("logicalAssignment"),
|
---|
14 | visitor: {
|
---|
15 | AssignmentExpression(path) {
|
---|
16 | const {
|
---|
17 | node,
|
---|
18 | scope
|
---|
19 | } = path;
|
---|
20 | const {
|
---|
21 | operator,
|
---|
22 | left,
|
---|
23 | right
|
---|
24 | } = node;
|
---|
25 | const operatorTrunc = operator.slice(0, -1);
|
---|
26 | if (!_core.types.LOGICAL_OPERATORS.includes(operatorTrunc)) {
|
---|
27 | return;
|
---|
28 | }
|
---|
29 | const lhs = _core.types.cloneNode(left);
|
---|
30 | if (_core.types.isMemberExpression(left)) {
|
---|
31 | const {
|
---|
32 | object,
|
---|
33 | property,
|
---|
34 | computed
|
---|
35 | } = left;
|
---|
36 | const memo = scope.maybeGenerateMemoised(object);
|
---|
37 | if (memo) {
|
---|
38 | left.object = memo;
|
---|
39 | lhs.object = _core.types.assignmentExpression("=", _core.types.cloneNode(memo), object);
|
---|
40 | }
|
---|
41 | if (computed) {
|
---|
42 | const memo = scope.maybeGenerateMemoised(property);
|
---|
43 | if (memo) {
|
---|
44 | left.property = memo;
|
---|
45 | lhs.property = _core.types.assignmentExpression("=", _core.types.cloneNode(memo), property);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 | path.replaceWith(_core.types.logicalExpression(operatorTrunc, lhs, _core.types.assignmentExpression("=", left, right)));
|
---|
50 | }
|
---|
51 | }
|
---|
52 | };
|
---|
53 | });
|
---|
54 |
|
---|
55 | //# sourceMappingURL=index.js.map
|
---|