clone method

Environment clone()

Creates a new Environment instance that is a deep copy of the current instance.

This method creates a new Environment instance with a deep copy of the current variable stack. This ensures that any changes made to the new instance do not affect the original instance.

Returns: A new Environment instance that is a deep copy of the current instance.

Implementation

Environment clone() {
  // Deep copy the variable stack
  final clonedVariableStack = _variableStack
      .map((scope) => Map<String, dynamic>.from(scope))
      .toList();
  // Shallow copy the filters (assuming filters are immutable)
  // final clonedFilters = Map<String, FilterFunction>.from(_filters);
  return Environment._clone(clonedVariableStack /*, clonedFilters*/);
}