ifc-expressions
Version:
Parsing and evaluation of IFC expressions
37 lines (36 loc) • 1.42 kB
JavaScript
import { FuncArg } from "../FuncArg.js";
import { ExprEvalTypeErrorObj, isExprEvalSuccess, } from "../../ExprEvalResult.js";
import { ExprKind, isNullish } from "../../../IfcExpression.js";
export class FuncArgBase extends FuncArg {
constructor(required, name, defaultValue) {
super(required, name, defaultValue);
}
transformValue(callingExpr, invocationValue) {
if (isExprEvalSuccess(invocationValue)) {
return this.errorIfNullish(this.transformForTypeCheck(callingExpr, invocationValue), callingExpr);
}
return this.errorIfNullish(this.transformForError(callingExpr, invocationValue), callingExpr);
}
errorIfNullish(result, callingExpr) {
if (isNullish(result)) {
return new ExprEvalTypeErrorObj(ExprKind.FUNCTION_ARGUMENTS, `Cannot obtain value of argument ${this.name}`, callingExpr.getTextSpan());
}
return result;
}
/**
* Override to type-check the successfully evaluated invocationValue.
* @protected
*/
transformForTypeCheck(callingExpr, invocationValue) {
return invocationValue;
}
/**
* Override to transform the error result obtained from evaluating the invocation value.
* @param invocationValue
* @protected
*/
transformForError(callingExpr, invocationValue) {
return invocationValue;
}
}
//# sourceMappingURL=FuncArgBase.js.map