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 _pluginSyntaxLogicalAssignmentOperators = require("@babel/plugin-syntax-logical-assignment-operators");
|
9 | var _core = require("@babel/core");
|
10 | var _default = (0, _helperPluginUtils.declare)(api => {
|
11 | api.assertVersion(7);
|
12 | return {
|
13 | name: "proposal-logical-assignment-operators",
|
14 | inherits: _pluginSyntaxLogicalAssignmentOperators.default,
|
15 | visitor: {
|
16 | AssignmentExpression(path) {
|
17 | const {
|
18 | node,
|
19 | scope
|
20 | } = path;
|
21 | const {
|
22 | operator,
|
23 | left,
|
24 | right
|
25 | } = node;
|
26 | const operatorTrunc = operator.slice(0, -1);
|
27 | if (!_core.types.LOGICAL_OPERATORS.includes(operatorTrunc)) {
|
28 | return;
|
29 | }
|
30 | const lhs = _core.types.cloneNode(left);
|
31 | if (_core.types.isMemberExpression(left)) {
|
32 | const {
|
33 | object,
|
34 | property,
|
35 | computed
|
36 | } = left;
|
37 | const memo = scope.maybeGenerateMemoised(object);
|
38 | if (memo) {
|
39 | left.object = memo;
|
40 | lhs.object = _core.types.assignmentExpression("=", _core.types.cloneNode(memo),
|
41 | object);
|
42 | }
|
43 | if (computed) {
|
44 | const memo = scope.maybeGenerateMemoised(property);
|
45 | if (memo) {
|
46 | left.property = memo;
|
47 | lhs.property = _core.types.assignmentExpression("=", _core.types.cloneNode(memo),
|
48 | property);
|
49 | }
|
50 | }
|
51 | }
|
52 | path.replaceWith(_core.types.logicalExpression(
|
53 | operatorTrunc, lhs, _core.types.assignmentExpression("=", left, right)));
|
54 | }
|
55 | }
|
56 | };
|
57 | });
|
58 | exports.default = _default;
|
59 |
|
60 |
|