UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

33 lines (32 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FuncArgUnion = void 0; const FuncArg_js_1 = require("../FuncArg.js"); const ExprEvalResult_js_1 = require("../../ExprEvalResult.js"); const ExprKind_js_1 = require("../../ExprKind.js"); const IfcExpression_js_1 = require("../../../IfcExpression.js"); const Types_js_1 = require("../../../type/Types.js"); class FuncArgUnion extends FuncArg_js_1.FuncArg { constructor(...options) { super(options[0].required, options[0].name, options[0].defaultValue); this.options = options; } static of(required, name, constructors) { return new FuncArgUnion(...constructors.map((c) => new c(required, name))); } transformValue(callingExpr, invocationValue) { const successResults = this.options .map((o) => o.transformValue(callingExpr, invocationValue)) .filter((r) => !(0, IfcExpression_js_1.isNullish)(r)) .filter((r) => (0, ExprEvalResult_js_1.isExprEvalSuccess)(r)); if (successResults.length === 0) { return new ExprEvalResult_js_1.ExprEvalTypeErrorObj(ExprKind_js_1.ExprKind.FUNCTION_ARGUMENTS, `Argument ${this.name} is must be one of ${this.options}. The provided value, '${invocationValue}' is not allowed. `, callingExpr.getTextSpan()); } return successResults[0]; } getType() { return Types_js_1.Types.or(...this.options.map((o) => o.getType())); } } exports.FuncArgUnion = FuncArgUnion; //# sourceMappingURL=FuncArgUnion.js.map