UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

29 lines (28 loc) 1.3 kB
import { FuncArg } from "../FuncArg.js"; import { ExprEvalTypeErrorObj, isExprEvalSuccess, } from "../../ExprEvalResult.js"; import { ExprKind } from "../../ExprKind.js"; import { isNullish } from "../../../IfcExpression.js"; import { Types } from "../../../type/Types.js"; export class FuncArgUnion extends 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) => !isNullish(r)) .filter((r) => isExprEvalSuccess(r)); if (successResults.length === 0) { return new ExprEvalTypeErrorObj(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.or(...this.options.map((o) => o.getType())); } } //# sourceMappingURL=FuncArgUnion.js.map