in src/main/java/org/apache/sling/scripting/sightly/impl/compiler/optimization/UnusedVariableRemoval.java [67:94]
public void visit(VariableBinding.End variableBindingEnd) {
// Get the activity of the exiting variable
VariableActivity variableActivity = tracker.peek().getValue();
tracker.popVariable();
boolean emitBindingEnd = true;
if (variableActivity != null) {
// this was a tracked variable. Popping all the commands
// which were delayed for this variable
List<Command> commands = storedCommandsStack.pop();
// if the variable binding is emitted than this binding
// end must be emitted as well
emitBindingEnd = variableActivity.isUsed();
if (variableActivity.isUsed()) {
VariableBinding.Start variableBindingStart = variableActivity.getCommand();
// variable was used. we can let it pass through
emit(variableBindingStart);
// register the usage of all the variables that appear in the bound expression
registerUsage(variableBindingStart);
}
// write all the delayed commands
for (Command command : commands) {
emit(command);
}
}
if (emitBindingEnd) {
emit(variableBindingEnd);
}
}