@babel/plugin-proposal-pipeline-operator
Advanced tools
Comparing version 7.16.7 to 7.17.6
@@ -10,5 +10,17 @@ "use strict"; | ||
const topicReferenceReplacementVisitor = { | ||
TopicReference(path) { | ||
path.replaceWith(_core.types.cloneNode(this.topicVariable)); | ||
const topicReferenceVisitor = { | ||
exit(path, state) { | ||
if (path.isTopicReference()) { | ||
state.topicReferences.push(path); | ||
} else { | ||
if (state.topicReferences.length === 0 && !state.sideEffectsBeforeFirstTopicReference && !path.isPure()) { | ||
state.sideEffectsBeforeFirstTopicReference = true; | ||
} | ||
} | ||
}, | ||
"ClassBody|Function"(_, state) { | ||
if (state.topicReferences.length === 0) { | ||
state.sideEffectsBeforeFirstTopicReference = true; | ||
} | ||
} | ||
@@ -29,16 +41,26 @@ | ||
const topicVariable = scope.generateUidIdentifierBasedOnNode(node); | ||
const pipeBodyPath = path.get("right"); | ||
scope.push({ | ||
id: topicVariable | ||
}); | ||
if (pipeBodyPath.node.type === "TopicReference") { | ||
pipeBodyPath.replaceWith(_core.types.cloneNode(topicVariable)); | ||
} else { | ||
pipeBodyPath.traverse(topicReferenceReplacementVisitor, { | ||
topicVariable | ||
}); | ||
path.replaceWith(node.left); | ||
return; | ||
} | ||
const visitorState = { | ||
topicReferences: [], | ||
sideEffectsBeforeFirstTopicReference: pipeBodyPath.isFunction() | ||
}; | ||
pipeBodyPath.traverse(topicReferenceVisitor, visitorState); | ||
if (visitorState.topicReferences.length === 1 && (!visitorState.sideEffectsBeforeFirstTopicReference || path.scope.isPure(node.left, true))) { | ||
visitorState.topicReferences[0].replaceWith(node.left); | ||
path.replaceWith(node.right); | ||
return; | ||
} | ||
const topicVariable = scope.generateUidIdentifierBasedOnNode(node); | ||
scope.push({ | ||
id: topicVariable | ||
}); | ||
visitorState.topicReferences.forEach(path => path.replaceWith(_core.types.cloneNode(topicVariable))); | ||
path.replaceWith(_core.types.sequenceExpression([_core.types.assignmentExpression("=", _core.types.cloneNode(topicVariable), node.left), node.right])); | ||
@@ -45,0 +67,0 @@ } |
{ | ||
"name": "@babel/plugin-proposal-pipeline-operator", | ||
"version": "7.16.7", | ||
"version": "7.17.6", | ||
"description": "Transform pipeline operator into call expressions", | ||
@@ -21,3 +21,3 @@ "repository": { | ||
"@babel/helper-plugin-utils": "^7.16.7", | ||
"@babel/plugin-syntax-pipeline-operator": "^7.16.7" | ||
"@babel/plugin-syntax-pipeline-operator": "^7.17.0" | ||
}, | ||
@@ -28,3 +28,3 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.16.7", | ||
"@babel/core": "^7.17.5", | ||
"@babel/helper-plugin-test-runner": "^7.16.7" | ||
@@ -31,0 +31,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10255
247