source: trip-planner-front/node_modules/@babel/plugin-proposal-logical-assignment-operators/lib/index.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _helperPluginUtils = require("@babel/helper-plugin-utils");
9
10var _pluginSyntaxLogicalAssignmentOperators = require("@babel/plugin-syntax-logical-assignment-operators");
11
12var _core = require("@babel/core");
13
14var _default = (0, _helperPluginUtils.declare)(api => {
15 api.assertVersion(7);
16 return {
17 name: "proposal-logical-assignment-operators",
18 inherits: _pluginSyntaxLogicalAssignmentOperators.default,
19 visitor: {
20 AssignmentExpression(path) {
21 const {
22 node,
23 scope
24 } = path;
25 const {
26 operator,
27 left,
28 right
29 } = node;
30 const operatorTrunc = operator.slice(0, -1);
31
32 if (!_core.types.LOGICAL_OPERATORS.includes(operatorTrunc)) {
33 return;
34 }
35
36 const lhs = _core.types.cloneNode(left);
37
38 if (_core.types.isMemberExpression(left)) {
39 const {
40 object,
41 property,
42 computed
43 } = left;
44 const memo = scope.maybeGenerateMemoised(object);
45
46 if (memo) {
47 left.object = memo;
48 lhs.object = _core.types.assignmentExpression("=", _core.types.cloneNode(memo), object);
49 }
50
51 if (computed) {
52 const memo = scope.maybeGenerateMemoised(property);
53
54 if (memo) {
55 left.property = memo;
56 lhs.property = _core.types.assignmentExpression("=", _core.types.cloneNode(memo), property);
57 }
58 }
59 }
60
61 path.replaceWith(_core.types.logicalExpression(operatorTrunc, lhs, _core.types.assignmentExpression("=", left, right)));
62 }
63
64 }
65 };
66});
67
68exports.default = _default;
Note: See TracBrowser for help on using the repository browser.