memberGet method

  1. @override
dynamic memberGet(
  1. String id, {
  2. bool isPrivate = false,
  3. String? from,
  4. bool isRecursive = true,
  5. bool ignoreUndefined = false,
  6. bool asDeclaration = false,
})
override

HTInstanceNamespace overrided HTNamespace's memberGet, with a new named parameter isRecursive. If isRecursive is false, then it won't continue to try fetching variable from enclosed namespace.

Implementation

@override
dynamic memberGet(
  String id, {
  bool isPrivate = false,
  String? from,
  bool isRecursive = true,
  bool ignoreUndefined = false,
  bool asDeclaration = false,
}) {
  final getter = '${InternalIdentifier.getter}$id';

  if (isRecursive) {
    HTInstanceNamespace? curNamespace = runtimeInstanceNamespace;
    while (curNamespace != null) {
      if (curNamespace.symbols.containsKey(id) ||
          curNamespace.symbols.containsKey(getter)) {
        final value =
            instance.memberGet(id, from: from, cast: curNamespace.classId);
        if (value is HTFunction &&
            value.category != FunctionCategory.literal) {
          value.instance = instance;
          value.namespace = this;
        }
        return value;
      } else {
        curNamespace = curNamespace.next;
      }
    }
  } else {
    if (symbols.containsKey(id)) {
      final value = instance.memberGet(id, from: from, cast: classId);
      if (value is HTFunction && value.category != FunctionCategory.literal) {
        value.instance = instance;
        value.namespace = this;
      }
      return value;
    }
  }

  if (isRecursive && closure != null) {
    return closure!.memberGet(id, from: from, isRecursive: isRecursive);
  }

  if (!ignoreUndefined) {
    throw HTError.undefined(id);
  }
}