memberSet method

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

Fetch a declaration from this namespace, if not found and isRecursive is true, will continue search in super namespaces, then assign the value to that declaration. If isRecursive is true, means this is not a 'memberset operator' search.

Implementation

@override
bool memberSet(
  String id,
  dynamic value, {
  String? from,
  bool isRecursive = true,
  bool ignoreUndefined = false,
  bool defineIfAbsent = false,
}) {
  final setter = '${InternalIdentifier.setter}$id';
  if (symbols.containsKey(id)) {
    final decl = symbols[id];
    if (decl is HTDeclaration) {
      if (decl.isPrivate && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      decl.resolve();
      decl.value = value;
    } else {
      if (lexicon.isPrivate(id) && from != null && !from.startsWith(fullName)) {
        throw HTError.privateMember(id);
      }
      symbols[id] = value;
    }
    return true;
  } else if (symbols.containsKey(setter)) {
    final decl = symbols[setter];
    if (decl is! HTDeclaration) return false;
    if (decl.isPrivate && from != null && !from.startsWith(fullName)) {
      throw HTError.privateMember(id);
    }
    decl.resolve();
    final HTFunction setterFunc = decl as HTFunction;
    setterFunc.call(positionalArgs: [value]);
    return true;
  }

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

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