You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
4 years ago
|
"use strict";
|
||
|
|
||
|
const { validateArguments } = require("@validatem/core");
|
||
|
const required = require("@validatem/required");
|
||
|
const either = require("@validatem/either");
|
||
|
|
||
|
const node = require("../ast-node");
|
||
|
const unreachable = require("../unreachable");
|
||
|
const tagAsType = require("../validators/tag-as-type");
|
||
|
|
||
|
module.exports = function (operations) {
|
||
|
const isExpression = require("../validators/operations/is-expression")(operations);
|
||
|
const isCondition = require("../validators/operations/is-condition")(operations);
|
||
|
|
||
|
return function not(_expression) {
|
||
|
let [ expression ] = validateArguments(arguments, {
|
||
|
expression: [ required, either([
|
||
|
[ isExpression, tagAsType("expression") ],
|
||
|
[ isCondition, tagAsType("condition") ],
|
||
|
])]
|
||
|
});
|
||
|
|
||
|
// FIXME: rename expression to something clearer, that indicates its relationship to conditions?
|
||
|
|
||
|
if (expression.type === "expression") {
|
||
|
return node({ type: "notExpression", expression: expression.value });
|
||
|
} else if (expression.type === "condition") {
|
||
|
return node({ type: "notCondition", condition: expression.value });
|
||
|
} else {
|
||
|
unreachable(`Invalid tagged type '${expression.type}'`);
|
||
|
}
|
||
|
};
|
||
|
};
|