astx
Version:
super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring
41 lines (29 loc) • 1.26 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = compileSpecialMatcher;
var _Optional = _interopRequireDefault(require("./Optional"));
var _Or = _interopRequireDefault(require("./Or"));
var _And = _interopRequireDefault(require("./And"));
var _CompilePathError = _interopRequireDefault(require("../util/CompilePathError"));
function compileSpecialMatcher(path, name, params, compileOptions) {
switch (name) {
case '$Maybe':
if (params.value.length !== 1) {
throw new _CompilePathError["default"]("$Maybe must be used with 1 type parameter", path);
}
return (0, _Optional["default"])(path, params.get(0), compileOptions);
case '$Or':
if (params.value.length < 2) {
throw new _CompilePathError["default"]("$Or must be called with at least 2 arguments", path);
}
return (0, _Or["default"])(path, params, compileOptions);
case '$And':
if (params.value.length < 2) {
throw new _CompilePathError["default"]("$And must be called with at least 2 arguments", path);
}
return (0, _And["default"])(path, params, compileOptions);
}
}