UNPKG

1.42 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 updateTopicReferenceVisitor = {
11 PipelinePrimaryTopicReference(path) {
12 path.replaceWith(_core.types.cloneNode(this.topicId));
13 },
14
15 PipelineTopicExpression(path) {
16 path.skip();
17 }
18
19};
20const smartVisitor = {
21 BinaryExpression(path) {
22 const {
23 scope
24 } = path;
25 const {
26 node
27 } = path;
28 const {
29 operator,
30 left,
31 right
32 } = node;
33 if (operator !== "|>") return;
34 const placeholder = scope.generateUidIdentifierBasedOnNode(left);
35 scope.push({
36 id: placeholder
37 });
38 let call;
39
40 if (_core.types.isPipelineTopicExpression(right)) {
41 path.get("right").traverse(updateTopicReferenceVisitor, {
42 topicId: placeholder
43 });
44 call = right.expression;
45 } else {
46 let callee = right.callee;
47
48 if (_core.types.isIdentifier(callee, {
49 name: "eval"
50 })) {
51 callee = _core.types.sequenceExpression([_core.types.numericLiteral(0), callee]);
52 }
53
54 call = _core.types.callExpression(callee, [_core.types.cloneNode(placeholder)]);
55 }
56
57 path.replaceWith(_core.types.sequenceExpression([_core.types.assignmentExpression("=", _core.types.cloneNode(placeholder), left), call]));
58 }
59
60};
61var _default = smartVisitor;
62exports.default = _default;
\No newline at end of file