     (lookupInMap @scopes[i], name) or
       i > 0 and (@_declarationInScope i - 1, name) or
       undefined # throw "Could not find declaration for #{name}"
+
+  _scopeOfDeclared: (i, name) ->
+    (lookupInMap @scopes[i], name) and @scopes[i] or
+      i > 0 and (@_scopeOfDeclared i - 1, name) or
+      undefined
 
   isCurrentlyDeclared: (name) ->
     !!(lookupInMap @_scope(), name)

  closeScope: ->
    closedScope = @scopes.pop()
    @savedScopes[closedScope.index] =
      parent: @scopes[@scopes.length - 1].index
      definitions: cloneMap closedScope

  currentScopeIndex: ->


  _currentDefinition: ->
    @_scope().definition

  _currentDeferrableDefinition: ->
    (def = @_scope().definition) and def.deferrable and def

  _definition: ->
    @_definitionAtScope @scopes.length - 1
