UNPKG

@akala/core

Version:
48 lines 1.7 kB
import { Expression } from './expression.js'; import { ExpressionType } from './expression-type.js'; /** * Represents a member expression, which accesses a property of an object. * @template T - The type of the source object expression. * @template TMember - The type of the member name (a key of T). * @template U - The type of the member value (T[TMember]). */ export class MemberExpression extends Expression { source; member; optional; /** * Gets the type identifier for this expression. * @returns {ExpressionType.MemberExpression} The expression type constant */ get type() { return ExpressionType.MemberExpression; } /** * Indicates the length/size associated with the member expression (used for array expressions) */ $$length; /** * Initializes a new instance of the MemberExpression class. * @param {TypedExpression<T>} source - The source expression. * @param {TypedExpression<TMember>} member - The member expression. * @param {boolean} optional - Indicates whether the member is optional. */ constructor(source, member, optional) { super(); this.source = source; this.member = member; this.optional = optional; } /** * Accepts a visitor. * @param {ExpressionVisitor} visitor - The visitor to accept. * @returns {TypedExpression<U>} The result of the visit. */ accept(visitor) { return visitor.visitMember(this); } toString() { if (this.source) return this.source.toString() + '.' + this.member.toString(); return this.member.toString(); } } //# sourceMappingURL=member-expression.js.map