memberSet method

  1. @override
bool memberSet(
  1. String varName,
  2. dynamic varValue, {
  3. String? from,
  4. bool isRecursive = false,
  5. bool throws = true,
})
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 varName,
  dynamic varValue, {
  String? from,
  bool isRecursive = false,
  bool throws = true,
}) {
  if (symbols.containsKey(varName)) {
    final decl = symbols[varName]!;
    if (decl.isPrivate && from != null && !from.startsWith(fullName)) {
      throw HTError.privateMember(varName);
    }
    decl.resolve();
    decl.value = varValue;
    return true;
  } else if (importedSymbols.containsKey(varName)) {
    final decl = importedSymbols[varName]!;
    if (decl.isPrivate && from != null && !from.startsWith(fullName)) {
      throw HTError.privateMember(varName);
    }
    decl.resolve();
    decl.value = varValue;
    return true;
  } else if (isRecursive && (closure != null)) {
    return closure!
        .memberSet(varName, varValue, from: from, isRecursive: true);
  } else {
    if (throws) {
      throw HTError.undefined(varName);
    }
  }

  return false;
}