'Return the scope for the given position in this buffer.
"line" is 1-based.
See CitadelBuffer.scoperef_from_pos() for details.
JavaScript has two differences here:
- <variable>\'s are scopes if they have child tags. This CIX
technique is used in JavaScript to define customized object
instances.
- Currently a JavaScript "class" line range may not include its
methods in some cases.
function Foo() {
Foo.prototype.bar = function() {
Class "Foo" has a line range that does not include method "bar".
c.f. test javascript/cpln/intermixed_class_definitions'

def scoperef_from_blob_and_line(self, blob, line):

    DEBUG = False
    if DEBUG:
        print ('scoperef_from_pos:    look    for    line    %d    in    %r' % (line, blob))
    best_fit_lpath = None
    for (scope, lpath) in _walk_js_scopes(blob):
        start = int(scope.get('line'))
        end = int(scope.get('lineend', start))
        if DEBUG:
            print ('scoperef_from_pos:                scope    %r    (%r-%r)?' % (scope, start, end)),
        if (line < start):
            if DEBUG:
                print 'no,    before    start'
            continue
        elif (line > end):
            if DEBUG:
                print 'no,    after    end'
            continue
        elif (line <= end):
            if DEBUG:
                print 'yes,    could    be'
            best_fit_lpath = lpath
        else:
            if DEBUG:
                print 'no,    passed    end'
            if (best_fit_lpath is not None):
                break
    if (best_fit_lpath is not None):
        return (blob, best_fit_lpath)
    else:
        return (blob, [])
