astx
Version:
super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring
35 lines (28 loc) • 1.56 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = compileJSXExpressionContainerMatcher;
var _Placeholder = _interopRequireDefault(require("./Placeholder"));
function compileJSXExpressionContainerMatcher(path, compileOptions) {
var pattern = path.value;
var n = compileOptions.backend.t.namedTypes;
if (n.Identifier.check(pattern.expression)) {
var placeholderMatcher = (0, _Placeholder["default"])(path, pattern.expression.name, compileOptions, {
nodeType: ['JSX', 'StringLiteral'],
getCondition: function getCondition() {
return [function isJSXAttributeValue(path) {
var _path$parent;
return n.JSXAttribute.check((_path$parent = path.parent) === null || _path$parent === void 0 ? void 0 : _path$parent.value) && path.name === 'value';
}, function isJSXChild(path) {
var _path$parent2, _path$parent3, _path$parentPath;
return (n.JSXElement.check((_path$parent2 = path.parent) === null || _path$parent2 === void 0 ? void 0 : _path$parent2.value) || n.JSXFragment.check((_path$parent3 = path.parent) === null || _path$parent3 === void 0 ? void 0 : _path$parent3.value)) && ((_path$parentPath = path.parentPath) === null || _path$parentPath === void 0 ? void 0 : _path$parentPath.name) === 'children';
}].find(function (c) {
return c(path);
});
}
});
if (placeholderMatcher) return placeholderMatcher;
}
}