tscore.js
function resolveReference(x, isModule) {
	if (x instanceof TReference) {
        if (isBuiltin(x.name))
            return new TBuiltin(x.name)
		if (x.resolution)
			return x.resolution
		if (x.resolving)
			throw new TypeError("Cyclic reference involving " + x)
		x.resolving = true
		var t = lookupInScope(x.scope, x.name, isModule)
		if (!t) {
            t = new TQualifiedReference(x.name) // XXX: for now assume global reference
			// throw new TypeError("Unresolved type: " + x.name)
		}
		t = resolveReference(t, isModule)
		x.resolution = t;
		return t;
	} else if (x instanceof TMember) {
		if (x.resolution)
			return x.resolution
		if (x.resolving)
			throw new TypeError("Cyclic reference involving " + x)
		x.resolving = true
		var base = resolveReference(x.base, true)
		var t = resolveReference(lookupInType(base, x.name, isModule), isModule)
		x.resolution = t
		return t;
    } else if (x instanceof TTypeQuery) {
        if (x.resolution)
            return x.resolution;
        if (x.resolving)
            throw new TypeError("Cyclic reference involving " + x)
        x.resolving = true
        var t = lookupPrtyInScope(x.scope, x.names[0])
        if (!t)
            throw new TypeError("Name not found: " + x.names[0])
        t = resolveReference(t)
        for (var i=1; i<x.names.length; i++) {
            var prty = t.properties.get(x.names[i])
            var module = t.modules.get(x.names[i])
            var t = prty ? prty.type : module;
            if (!t)
                throw new TypeError("Name not found: " + x.names.slice(0,i).join('.'))
            t = resolveReference(t)
        }
        if (t instanceof TObject && !t.qname) {
            t = synthesizeName(t) // don't create aliasing
        }
        x.resolution = t;
        return t;
	} else {
		return x;
	}
}
function resolveReference(x, isModule) {
	if (x instanceof TReference) {
        if (isBuiltin(x.name))
            return new TBuiltin(x.name)
		if (x.resolution)
			return x.resolution
		if (x.resolving)
			throw new TypeError("Cyclic reference involving " + x)
		x.resolving = true
		var t = lookupInScope(x.scope, x.name, isModule)
		if (!t) {
            t = new TQualifiedReference(x.name) // XXX: for now assume global reference
			// throw new TypeError("Unresolved type: " + x.name)
		}
		t = resolveReference(t, isModule)
		x.resolution = t;
		return t;
	} else if (x instanceof TMember) {
		if (x.resolution)
			return x.resolution
		if (x.resolving)
			throw new TypeError("Cyclic reference involving " + x)
		x.resolving = true
		var base = resolveReference(x.base, true)
		var t = resolveReference(lookupInType(base, x.name, isModule), isModule)
		x.resolution = t
		return t;
    } else if (x instanceof TTypeQuery) {
        if (x.resolution)
            return x.resolution;
        if (x.resolving)
            throw new TypeError("Cyclic reference involving " + x)
        x.resolving = true
        var t = lookupPrtyInScope(x.scope, x.names[0])
        if (!t)
            throw new TypeError("Name not found: " + x.names[0])
        t = resolveReference(t)
        for (var i=1; i<x.names.length; i++) {
            var prty = t.properties.get(x.names[i])
            var module = t.modules.get(x.names[i])
            var t = prty ? prty.type : module;
            if (!t)
                throw new TypeError("Name not found: " + x.names.slice(0,i).join('.'))
            t = resolveReference(t)
        }
        if (t instanceof TObject && !t.qname) {
            t = synthesizeName(t) // don't create aliasing
        }
        x.resolution = t;
        return t;
	} else {
		return x;
	}
}
function resolveReference ( x , isModule ) { if ( x instanceof TReference ) { if ( isBuiltin ( x . name ) ) return new TBuiltin ( x . name ) if ( x . resolution ) return x . resolution if ( x . resolving ) throw new TypeError ( "Cyclic reference involving " + x ) x . resolving = true var t = lookupInScope ( x . scope , x . name , isModule ) if ( ! t ) { t = new TQualifiedReference ( x . name ) // XXX: for now assume global reference // throw new TypeError("Unresolved type: " + x.name) } t = resolveReference ( t , isModule ) x . resolution = t ; return t ; } else if ( x instanceof TMember ) { if ( x . resolution ) return x . resolution if ( x . resolving ) throw new TypeError ( "Cyclic reference involving " + x ) x . resolving = true var base = resolveReference ( x . base , true ) var t = resolveReference ( lookupInType ( base , x . name , isModule ) , isModule ) x . resolution = t return t ; } else if ( x instanceof TTypeQuery ) { if ( x . resolution ) return x . resolution ; if ( x . resolving ) throw new TypeError ( "Cyclic reference involving " + x ) x . resolving = true var t = lookupPrtyInScope ( x . scope , x . names [ 0 ] ) if ( ! t ) throw new TypeError ( "Name not found: " + x . names [ 0 ] ) t = resolveReference ( t ) for ( var i = 1 ; i < x . names . length ; i ++ ) { var prty = t . properties . get ( x . names [ i ] ) var module = t . modules . get ( x . names [ i ] ) var t = prty ? prty . type : module ; if ( ! t ) throw new TypeError ( "Name not found: " + x . names . slice ( 0 , i ) . join ( '.' ) ) t = resolveReference ( t ) } if ( t instanceof TObject && ! t . qname ) { t = synthesizeName ( t ) // don't create aliasing } x . resolution = t ; return t ; } else { return x ; } }
Resolves a TReference or TMember to a TQualifiedReference
Resolves a TReference or TMember to a TQualifiedReference