resolve method Null safety

Variable<T>? resolve(
  1. String name
)

Finds the variable with the given name, either within this scope or an ancestor.

Returns null if none has been found.

Implementation

Variable<T>? resolve(String name) {
  var v = _lookupCache.putIfAbsent(name, () {
    var variable = _variables.firstWhereOrNull((v) => v.name == name);

    if (variable != null) {
      return variable;
    } else if (_parent != null) {
      return _parent?.resolve(name);
    } else {
      return null;
    }
  });

  if (v == null) {
    _lookupCache.remove(name);
    return null;
  } else {
    return v;
  }
}