UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _core = require("@babel/core");
9
10const topicReferenceReplacementVisitor = {
11 TopicReference(path) {
12 path.replaceWith(_core.types.cloneNode(this.topicVariable));
13 }
14
15};
16var _default = {
17 BinaryExpression: {
18 exit(path) {
19 const {
20 scope,
21 node
22 } = path;
23
24 if (node.operator !== "|>") {
25 return;
26 }
27
28 const topicVariable = scope.generateUidIdentifierBasedOnNode(node);
29 const pipeBodyPath = path.get("right");
30 scope.push({
31 id: topicVariable
32 });
33
34 if (pipeBodyPath.node.type === "TopicReference") {
35 pipeBodyPath.replaceWith(_core.types.cloneNode(topicVariable));
36 } else {
37 pipeBodyPath.traverse(topicReferenceReplacementVisitor, {
38 topicVariable
39 });
40 }
41
42 path.replaceWith(_core.types.sequenceExpression([_core.types.assignmentExpression("=", _core.types.cloneNode(topicVariable), node.left), node.right]));
43 }
44
45 }
46};
47exports.default = _default;
\No newline at end of file