@babel/plugin-proposal-pipeline-operator
Advanced tools
Comparing version 7.22.5 to 8.0.0-alpha.0
@@ -1,10 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _core = require("@babel/core"); | ||
import { types as t } from "@babel/core"; | ||
function isConciseArrowExpression(node) { | ||
return _core.types.isArrowFunctionExpression(node) && _core.types.isExpression(node.body) && !node.async; | ||
return t.isArrowFunctionExpression(node) && t.isExpression(node.body) && !node.async; | ||
} | ||
@@ -20,3 +14,3 @@ const buildOptimizedSequenceExpression = ({ | ||
const pipelineLeft = path.node.left; | ||
const assign = _core.types.assignmentExpression("=", _core.types.cloneNode(placeholder), pipelineLeft); | ||
const assign = t.assignmentExpression("=", t.cloneNode(placeholder), pipelineLeft); | ||
const expressionIsArrow = isConciseArrowExpression(calledExpression); | ||
@@ -29,3 +23,3 @@ if (expressionIsArrow) { | ||
} = calledExpression; | ||
if (params.length === 1 && _core.types.isIdentifier(params[0])) { | ||
if (params.length === 1 && t.isIdentifier(params[0])) { | ||
param = params[0]; | ||
@@ -36,24 +30,23 @@ } else if (params.length > 0) { | ||
if (optimizeArrow && !param) { | ||
return _core.types.sequenceExpression([pipelineLeft, calledExpression.body]); | ||
return t.sequenceExpression([pipelineLeft, calledExpression.body]); | ||
} else if (param) { | ||
path.scope.push({ | ||
id: _core.types.cloneNode(placeholder) | ||
id: t.cloneNode(placeholder) | ||
}); | ||
path.get("right").scope.rename(param.name, placeholder.name); | ||
return _core.types.sequenceExpression([assign, calledExpression.body]); | ||
return t.sequenceExpression([assign, calledExpression.body]); | ||
} | ||
} else if (_core.types.isIdentifier(calledExpression, { | ||
} else if (t.isIdentifier(calledExpression, { | ||
name: "eval" | ||
})) { | ||
const evalSequence = _core.types.sequenceExpression([_core.types.numericLiteral(0), calledExpression]); | ||
const evalSequence = t.sequenceExpression([t.numericLiteral(0), calledExpression]); | ||
call.callee = evalSequence; | ||
} | ||
path.scope.push({ | ||
id: _core.types.cloneNode(placeholder) | ||
id: t.cloneNode(placeholder) | ||
}); | ||
return _core.types.sequenceExpression([assign, call]); | ||
return t.sequenceExpression([assign, call]); | ||
}; | ||
var _default = buildOptimizedSequenceExpression; | ||
exports.default = _default; | ||
export default buildOptimizedSequenceExpression; | ||
//# sourceMappingURL=buildOptimizedSequenceExpression.js.map |
@@ -1,9 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _core = require("@babel/core"); | ||
var _buildOptimizedSequenceExpression = require("./buildOptimizedSequenceExpression"); | ||
import { types as t } from "@babel/core"; | ||
import buildOptimizedSequenceExpression from "./buildOptimizedSequenceExpression.js"; | ||
const fsharpVisitor = { | ||
@@ -22,4 +16,4 @@ BinaryExpression(path) { | ||
const placeholder = scope.generateUidIdentifierBasedOnNode(left); | ||
const call = right.type === "AwaitExpression" ? _core.types.awaitExpression(_core.types.cloneNode(placeholder)) : _core.types.callExpression(right, [_core.types.cloneNode(placeholder)]); | ||
const sequence = (0, _buildOptimizedSequenceExpression.default)({ | ||
const call = right.type === "AwaitExpression" ? t.awaitExpression(t.cloneNode(placeholder)) : t.callExpression(right, [t.cloneNode(placeholder)]); | ||
const sequence = buildOptimizedSequenceExpression({ | ||
placeholder, | ||
@@ -32,5 +26,4 @@ call, | ||
}; | ||
var _default = fsharpVisitor; | ||
exports.default = _default; | ||
export default fsharpVisitor; | ||
//# sourceMappingURL=fsharpVisitor.js.map |
@@ -1,8 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _core = require("@babel/core"); | ||
import { types as t } from "@babel/core"; | ||
const topicReferenceVisitor = { | ||
@@ -53,10 +47,9 @@ exit(path, state) { | ||
}); | ||
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])); | ||
visitorState.topicReferences.forEach(path => path.replaceWith(t.cloneNode(topicVariable))); | ||
path.replaceWith(t.sequenceExpression([t.assignmentExpression("=", t.cloneNode(topicVariable), node.left), node.right])); | ||
} | ||
} | ||
}; | ||
var _default = visitor; | ||
exports.default = _default; | ||
export default visitor; | ||
//# sourceMappingURL=hackVisitor.js.map |
215
lib/index.js
@@ -1,20 +0,199 @@ | ||
"use strict"; | ||
import { declare } from '@babel/helper-plugin-utils'; | ||
import syntaxPipelineOperator from '@babel/plugin-syntax-pipeline-operator'; | ||
import { types } from '@babel/core'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
var _pluginSyntaxPipelineOperator = require("@babel/plugin-syntax-pipeline-operator"); | ||
var _minimalVisitor = require("./minimalVisitor"); | ||
var _hackVisitor = require("./hackVisitor"); | ||
var _fsharpVisitor = require("./fsharpVisitor"); | ||
var _smartVisitor = require("./smartVisitor"); | ||
function isConciseArrowExpression(node) { | ||
return types.isArrowFunctionExpression(node) && types.isExpression(node.body) && !node.async; | ||
} | ||
const buildOptimizedSequenceExpression = ({ | ||
call, | ||
path, | ||
placeholder | ||
}) => { | ||
const { | ||
callee: calledExpression | ||
} = call; | ||
const pipelineLeft = path.node.left; | ||
const assign = types.assignmentExpression("=", types.cloneNode(placeholder), pipelineLeft); | ||
const expressionIsArrow = isConciseArrowExpression(calledExpression); | ||
if (expressionIsArrow) { | ||
let param; | ||
let optimizeArrow = true; | ||
const { | ||
params | ||
} = calledExpression; | ||
if (params.length === 1 && types.isIdentifier(params[0])) { | ||
param = params[0]; | ||
} else if (params.length > 0) { | ||
optimizeArrow = false; | ||
} | ||
if (optimizeArrow && !param) { | ||
return types.sequenceExpression([pipelineLeft, calledExpression.body]); | ||
} else if (param) { | ||
path.scope.push({ | ||
id: types.cloneNode(placeholder) | ||
}); | ||
path.get("right").scope.rename(param.name, placeholder.name); | ||
return types.sequenceExpression([assign, calledExpression.body]); | ||
} | ||
} else if (types.isIdentifier(calledExpression, { | ||
name: "eval" | ||
})) { | ||
const evalSequence = types.sequenceExpression([types.numericLiteral(0), calledExpression]); | ||
call.callee = evalSequence; | ||
} | ||
path.scope.push({ | ||
id: types.cloneNode(placeholder) | ||
}); | ||
return types.sequenceExpression([assign, call]); | ||
}; | ||
const minimalVisitor = { | ||
BinaryExpression(path) { | ||
const { | ||
scope, | ||
node | ||
} = path; | ||
const { | ||
operator, | ||
left, | ||
right | ||
} = node; | ||
if (operator !== "|>") return; | ||
const placeholder = scope.generateUidIdentifierBasedOnNode(left); | ||
const call = types.callExpression(right, [types.cloneNode(placeholder)]); | ||
path.replaceWith(buildOptimizedSequenceExpression({ | ||
placeholder, | ||
call, | ||
path: path | ||
})); | ||
} | ||
}; | ||
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; | ||
} | ||
} | ||
}; | ||
const visitor = { | ||
BinaryExpression: { | ||
exit(path) { | ||
const { | ||
scope, | ||
node | ||
} = path; | ||
if (node.operator !== "|>") { | ||
return; | ||
} | ||
const pipeBodyPath = path.get("right"); | ||
if (pipeBodyPath.node.type === "TopicReference") { | ||
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(types.cloneNode(topicVariable))); | ||
path.replaceWith(types.sequenceExpression([types.assignmentExpression("=", types.cloneNode(topicVariable), node.left), node.right])); | ||
} | ||
} | ||
}; | ||
const fsharpVisitor = { | ||
BinaryExpression(path) { | ||
const { | ||
scope, | ||
node | ||
} = path; | ||
const { | ||
operator, | ||
left, | ||
right | ||
} = node; | ||
if (operator !== "|>") return; | ||
const placeholder = scope.generateUidIdentifierBasedOnNode(left); | ||
const call = right.type === "AwaitExpression" ? types.awaitExpression(types.cloneNode(placeholder)) : types.callExpression(right, [types.cloneNode(placeholder)]); | ||
const sequence = buildOptimizedSequenceExpression({ | ||
placeholder, | ||
call, | ||
path: path | ||
}); | ||
path.replaceWith(sequence); | ||
} | ||
}; | ||
const updateTopicReferenceVisitor = { | ||
PipelinePrimaryTopicReference(path) { | ||
path.replaceWith(types.cloneNode(this.topicId)); | ||
}, | ||
PipelineTopicExpression(path) { | ||
path.skip(); | ||
} | ||
}; | ||
const smartVisitor = { | ||
BinaryExpression(path) { | ||
const { | ||
scope | ||
} = path; | ||
const { | ||
node | ||
} = path; | ||
const { | ||
operator, | ||
left, | ||
right | ||
} = node; | ||
if (operator !== "|>") return; | ||
const placeholder = scope.generateUidIdentifierBasedOnNode(left); | ||
scope.push({ | ||
id: placeholder | ||
}); | ||
let call; | ||
if (types.isPipelineTopicExpression(right)) { | ||
path.get("right").traverse(updateTopicReferenceVisitor, { | ||
topicId: placeholder | ||
}); | ||
call = right.expression; | ||
} else { | ||
let callee = right.callee; | ||
if (types.isIdentifier(callee, { | ||
name: "eval" | ||
})) { | ||
callee = types.sequenceExpression([types.numericLiteral(0), callee]); | ||
} | ||
call = types.callExpression(callee, [types.cloneNode(placeholder)]); | ||
} | ||
path.replaceWith(types.sequenceExpression([types.assignmentExpression("=", types.cloneNode(placeholder), left), call])); | ||
} | ||
}; | ||
const visitorsPerProposal = { | ||
minimal: _minimalVisitor.default, | ||
hack: _hackVisitor.default, | ||
fsharp: _fsharpVisitor.default, | ||
smart: _smartVisitor.default | ||
minimal: minimalVisitor, | ||
hack: visitor, | ||
fsharp: fsharpVisitor, | ||
smart: smartVisitor | ||
}; | ||
var _default = (0, _helperPluginUtils.declare)((api, options) => { | ||
var index = declare((api, options) => { | ||
api.assertVersion(7); | ||
@@ -29,8 +208,8 @@ const { | ||
name: "proposal-pipeline-operator", | ||
inherits: _pluginSyntaxPipelineOperator.default, | ||
inherits: syntaxPipelineOperator, | ||
visitor: visitorsPerProposal[options.proposal] | ||
}; | ||
}); | ||
exports.default = _default; | ||
export { index as default }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _core = require("@babel/core"); | ||
var _buildOptimizedSequenceExpression = require("./buildOptimizedSequenceExpression"); | ||
import { types as t } from "@babel/core"; | ||
import buildOptimizedSequenceExpression from "./buildOptimizedSequenceExpression.js"; | ||
const minimalVisitor = { | ||
@@ -22,4 +16,4 @@ BinaryExpression(path) { | ||
const placeholder = scope.generateUidIdentifierBasedOnNode(left); | ||
const call = _core.types.callExpression(right, [_core.types.cloneNode(placeholder)]); | ||
path.replaceWith((0, _buildOptimizedSequenceExpression.default)({ | ||
const call = t.callExpression(right, [t.cloneNode(placeholder)]); | ||
path.replaceWith(buildOptimizedSequenceExpression({ | ||
placeholder, | ||
@@ -31,5 +25,4 @@ call, | ||
}; | ||
var _default = minimalVisitor; | ||
exports.default = _default; | ||
export default minimalVisitor; | ||
//# sourceMappingURL=minimalVisitor.js.map |
@@ -1,11 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _core = require("@babel/core"); | ||
import { types as t } from "@babel/core"; | ||
const updateTopicReferenceVisitor = { | ||
PipelinePrimaryTopicReference(path) { | ||
path.replaceWith(_core.types.cloneNode(this.topicId)); | ||
path.replaceWith(t.cloneNode(this.topicId)); | ||
}, | ||
@@ -35,3 +29,3 @@ PipelineTopicExpression(path) { | ||
let call; | ||
if (_core.types.isPipelineTopicExpression(right)) { | ||
if (t.isPipelineTopicExpression(right)) { | ||
path.get("right").traverse(updateTopicReferenceVisitor, { | ||
@@ -43,15 +37,14 @@ topicId: placeholder | ||
let callee = right.callee; | ||
if (_core.types.isIdentifier(callee, { | ||
if (t.isIdentifier(callee, { | ||
name: "eval" | ||
})) { | ||
callee = _core.types.sequenceExpression([_core.types.numericLiteral(0), callee]); | ||
callee = t.sequenceExpression([t.numericLiteral(0), callee]); | ||
} | ||
call = _core.types.callExpression(callee, [_core.types.cloneNode(placeholder)]); | ||
call = t.callExpression(callee, [t.cloneNode(placeholder)]); | ||
} | ||
path.replaceWith(_core.types.sequenceExpression([_core.types.assignmentExpression("=", _core.types.cloneNode(placeholder), left), call])); | ||
path.replaceWith(t.sequenceExpression([t.assignmentExpression("=", t.cloneNode(placeholder), left), call])); | ||
} | ||
}; | ||
var _default = smartVisitor; | ||
exports.default = _default; | ||
export default smartVisitor; | ||
//# sourceMappingURL=smartVisitor.js.map |
{ | ||
"name": "@babel/plugin-proposal-pipeline-operator", | ||
"version": "7.22.5", | ||
"version": "8.0.0-alpha.0", | ||
"description": "Transform pipeline operator into call expressions", | ||
@@ -20,17 +20,21 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "^7.22.5", | ||
"@babel/plugin-syntax-pipeline-operator": "^7.22.5" | ||
"@babel/helper-plugin-utils": "^8.0.0-alpha.0", | ||
"@babel/plugin-syntax-pipeline-operator": "^8.0.0-alpha.0" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0-0" | ||
"@babel/core": "^8.0.0-alpha.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.22.5", | ||
"@babel/helper-plugin-test-runner": "^7.22.5" | ||
"@babel/core": "^8.0.0-alpha.0", | ||
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
"node": "^16.20.0 || ^18.16.0 || >=20.0.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"type": "commonjs" | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "module" | ||
} |
@@ -5,3 +5,3 @@ # @babel/plugin-proposal-pipeline-operator | ||
See our website [@babel/plugin-proposal-pipeline-operator](https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator) for more information. | ||
See our website [@babel/plugin-proposal-pipeline-operator](https://babeljs.io/docs/babel-plugin-proposal-pipeline-operator) for more information. | ||
@@ -8,0 +8,0 @@ ## Install |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
50383
406
Yes
1
+ Added@babel/code-frame@8.0.0-alpha.13(transitive)
+ Added@babel/compat-data@8.0.0-alpha.13(transitive)
+ Added@babel/core@8.0.0-alpha.13(transitive)
+ Added@babel/generator@8.0.0-alpha.13(transitive)
+ Added@babel/helper-compilation-targets@8.0.0-alpha.13(transitive)
+ Added@babel/helper-plugin-utils@8.0.0-alpha.13(transitive)
+ Added@babel/helper-string-parser@8.0.0-alpha.13(transitive)
+ Added@babel/helper-validator-identifier@8.0.0-alpha.13(transitive)
+ Added@babel/helper-validator-option@8.0.0-alpha.13(transitive)
+ Added@babel/helpers@8.0.0-alpha.13(transitive)
+ Added@babel/parser@8.0.0-alpha.13(transitive)
+ Added@babel/plugin-syntax-pipeline-operator@8.0.0-alpha.13(transitive)
+ Added@babel/template@8.0.0-alpha.13(transitive)
+ Added@babel/traverse@8.0.0-alpha.13(transitive)
+ Added@babel/types@8.0.0-alpha.13(transitive)
+ Addedcaniuse-lite@1.0.30001680(transitive)
+ Addedelectron-to-chromium@1.5.57(transitive)
+ Addedglobals@15.12.0(transitive)
+ Addedjs-tokens@8.0.3(transitive)
+ Addedlru-cache@7.18.3(transitive)
+ Addedsemver@7.6.3(transitive)
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/compat-data@7.26.2(transitive)
- Removed@babel/core@7.26.0(transitive)
- Removed@babel/generator@7.26.2(transitive)
- Removed@babel/helper-compilation-targets@7.25.9(transitive)
- Removed@babel/helper-module-imports@7.25.9(transitive)
- Removed@babel/helper-module-transforms@7.26.0(transitive)
- Removed@babel/helper-plugin-utils@7.25.9(transitive)
- Removed@babel/helper-string-parser@7.25.9(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@babel/helper-validator-option@7.25.9(transitive)
- Removed@babel/helpers@7.26.0(transitive)
- Removed@babel/parser@7.26.2(transitive)
- Removed@babel/plugin-syntax-pipeline-operator@7.25.9(transitive)
- Removed@babel/template@7.25.9(transitive)
- Removed@babel/traverse@7.25.9(transitive)
- Removed@babel/types@7.26.0(transitive)
- Removedcaniuse-lite@1.0.30001679(transitive)
- Removedelectron-to-chromium@1.5.55(transitive)
- Removedglobals@11.12.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedlru-cache@5.1.1(transitive)
- Removedsemver@6.3.1(transitive)
- Removedyallist@3.1.1(transitive)
Updated@babel/plugin-syntax-pipeline-operator@^8.0.0-alpha.0