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

Fetch a value from this namespace, Return declaration rather than actual values. If not found and isRecursive is true, will continue search in super namespaces. If isRecursive is true, means this is not a 'memberget operator' search.

TODO: remove isPrivate check;

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';
  final externalStatic = '$id.$id';

  if (symbols.containsKey(id)) {
    final decl = symbols[id];
    if (decl == null) return null;
    if (decl is HTDeclaration) {
      if (decl.isPrivate && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      decl.resolve();
      return decl.value;
    } else {
      if (lexicon.isPrivate(id) && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      return decl;
    }
  } else if (symbols.containsKey(getter)) {
    final decl = symbols[getter];
    if (decl == null) return null;
    if (decl is HTDeclaration) {
      if (decl.isPrivate && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      decl.resolve();
      return decl.value;
    } else {
      if (lexicon.isPrivate(id) && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      return decl;
    }
  } else if (symbols.containsKey(externalStatic)) {
    final decl = symbols[externalStatic];
    if (decl == null) return null;
    if (decl is HTDeclaration) {
      if (decl.isPrivate && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      decl.resolve();
      return decl.value;
    } else {
      if (lexicon.isPrivate(id) && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      return decl;
    }
  }

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

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