beginScope method

void beginScope(
  1. int key, {
  2. dynamic isIsolated = false,
})

Begin a new scope for variables, represented by a DartBlockEnvironment object.

If isIsolated is false, the new environment is added as a child to the current environment.

Otherwise, the new environment is added as a child to the root environment, indicating that it has its own separate (isolated) scope. For example, a custom function would have its own isolated scope (environment), rather than being a child of the main function's environment.

Implementation

void beginScope(int key, {isIsolated = false}) {
  _blockHistory.add(_currentStatementBlockKey);

  var currentEnvironment = _getCurrentEnvironment();
  if (isIsolated) {
    environment.addChild(
      DartBlockEnvironment(key, parent: environment, children: []),
    );
  } else {
    currentEnvironment.addChild(
      DartBlockEnvironment(key, parent: currentEnvironment, children: []),
    );
  }

  _currentStatementBlockKey = key;
}