source: trip-planner-front/node_modules/@babel/plugin-proposal-nullish-coalescing-operator/lib/index.js@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 1.8 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 _pluginSyntaxNullishCoalescingOperator = require("@babel/plugin-syntax-nullish-coalescing-operator");
11
12var _core = require("@babel/core");
13
14var _default = (0, _helperPluginUtils.declare)((api, {
15 loose = false
16}) => {
17 var _api$assumption;
18
19 api.assertVersion(7);
20 const noDocumentAll = (_api$assumption = api.assumption("noDocumentAll")) != null ? _api$assumption : loose;
21 return {
22 name: "proposal-nullish-coalescing-operator",
23 inherits: _pluginSyntaxNullishCoalescingOperator.default,
24 visitor: {
25 LogicalExpression(path) {
26 const {
27 node,
28 scope
29 } = path;
30
31 if (node.operator !== "??") {
32 return;
33 }
34
35 let ref;
36 let assignment;
37
38 if (scope.isStatic(node.left)) {
39 ref = node.left;
40 assignment = _core.types.cloneNode(node.left);
41 } else if (scope.path.isPattern()) {
42 path.replaceWith(_core.template.ast`(() => ${path.node})()`);
43 return;
44 } else {
45 ref = scope.generateUidIdentifierBasedOnNode(node.left);
46 scope.push({
47 id: _core.types.cloneNode(ref)
48 });
49 assignment = _core.types.assignmentExpression("=", ref, node.left);
50 }
51
52 path.replaceWith(_core.types.conditionalExpression(noDocumentAll ? _core.types.binaryExpression("!=", assignment, _core.types.nullLiteral()) : _core.types.logicalExpression("&&", _core.types.binaryExpression("!==", assignment, _core.types.nullLiteral()), _core.types.binaryExpression("!==", _core.types.cloneNode(ref), scope.buildUndefinedNode())), _core.types.cloneNode(ref), node.right));
53 }
54
55 }
56 };
57});
58
59exports.default = _default;
Note: See TracBrowser for help on using the repository browser.