'Resolve the given alias
@param namelist {seq of str} The path to the alias to resolve
@param scope {JSObject} The starting scope; defaults to the current scope
@returns {tuple of scope, {seq of str}} The scope and namelist for the
(recursively) resolved namelist; alternatively, tuple (None, None)
if the alias could not be resolved (e.g. not an alias)'

def _resolveAlias(self, namelist, scope=None):

    if (not namelist):
        return (None, None)
    namelist = namelist[:]
    if (scope is None):
        scope = self.currentScope
    (lastScope, lastNamelist) = (scope, namelist[:])
    log.debug('_resolveAlias:    Resolving    alias    %r    in    scope    %r', namelist, scope.name)
    aliasDepth = 0
    found = False
    while namelist:
        log.debug('_resolveAlias:    Looking    for    %r    in    scope    %r', namelist, scope.name)
        namesDict = getattr(scope, 'variables', None)
        if (not namesDict):
            log.debug('_resolveAlias:    scope    %r    has    no    variables', scope.name)
            break
        name = namelist.pop(0)
        foundVar = namesDict.get(name)
        if (foundVar is None):
            log.debug('_resolveAlias:    scope    %r    does    not    have    variable    %r', scope.name, name)
            break
        if (isinstance(foundVar, JSAlias) and (aliasDepth < 10)):
            lastScope = scope = foundVar.scope
            namelist = (foundVar.target + namelist)
            if namelist[(-1)].endswith('()'):
                namelist[(-1)] = namelist[(-1)][:(-2)]
            lastNamelist = namelist[:]
            aliasDepth += 1
            log.debug('_resolveAlias:    found    alias    %r    on    %r;    new    names    %r', foundVar.name, scope.name, namelist)
        else:
            scope = foundVar
    log.debug('_resolveAlias:    finished    resolve:    scope    %r    namelist    %r    depth    %r', lastScope.name, lastNamelist, aliasDepth)
    if (aliasDepth == 0):
        return (None, None)
    return (lastScope, lastNamelist)
