source: imaps-frontend/node_modules/@babel/plugin-transform-exponentiation-operator/lib/index.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _helperPluginUtils = require("@babel/helper-plugin-utils");
8var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
9 api.assertVersion("^7.0.0-0 || >8.0.0-alpha <8.0.0-beta");
10 const {
11 types: t,
12 template
13 } = api;
14 function build(left, right) {
15 return t.callExpression(t.memberExpression(t.identifier("Math"), t.identifier("pow")), [left, right]);
16 }
17 function maybeMemoize(node, scope) {
18 if (scope.isStatic(node)) {
19 return {
20 assign: node,
21 ref: t.cloneNode(node)
22 };
23 }
24 if (scope.path.isPattern()) {
25 return null;
26 }
27 const id = scope.generateUidIdentifierBasedOnNode(node);
28 scope.push({
29 id
30 });
31 return {
32 assign: t.assignmentExpression("=", t.cloneNode(id), node),
33 ref: t.cloneNode(id)
34 };
35 }
36 return {
37 name: "transform-exponentiation-operator",
38 visitor: {
39 AssignmentExpression(path) {
40 const {
41 node,
42 scope
43 } = path;
44 if (node.operator !== "**=") return;
45 if (t.isMemberExpression(node.left)) {
46 let member1;
47 let member2;
48 const object = maybeMemoize(node.left.object, scope);
49 if (!object) {
50 path.replaceWith(template.expression.ast`(() => ${path.node})()`);
51 return;
52 }
53 const {
54 property,
55 computed
56 } = node.left;
57 if (computed) {
58 const prop = maybeMemoize(property, scope);
59 member1 = t.memberExpression(object.assign, prop.assign, true);
60 member2 = t.memberExpression(object.ref, prop.ref, true);
61 } else {
62 member1 = t.memberExpression(object.assign, property, false);
63 member2 = t.memberExpression(object.ref, t.cloneNode(property), false);
64 }
65 path.replaceWith(t.assignmentExpression("=", member1, build(member2, node.right)));
66 } else {
67 path.replaceWith(t.assignmentExpression("=", node.left, build(t.cloneNode(node.left), node.right)));
68 }
69 },
70 BinaryExpression(path) {
71 const {
72 node
73 } = path;
74 if (node.operator === "**") {
75 path.replaceWith(build(node.left, node.right));
76 }
77 }
78 }
79 };
80});
81
82//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.