diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp
index bdc0749063390adeb30da85b2520729ea735ee89..5557f6317a077fa7e0c86dc898a5335f6b38b296 100644
--- a/src/libs/qmljs/qmljsbind.cpp
+++ b/src/libs/qmljs/qmljsbind.cpp
@@ -203,6 +203,11 @@ QStringList Bind::includedScripts() const
     return _includedScripts;
 }
 
+QStringList Bind::localImports() const
+{
+    return _localImports;
+}
+
 ObjectValue *Bind::switchObjectValue(ObjectValue *newObjectValue)
 {
     ObjectValue *oldObjectValue = _currentObjectValue;
@@ -216,13 +221,37 @@ ObjectValue *Bind::scopeChainAt(Document::Ptr currentDocument, const Snapshot &s
     Bind *currentBind = 0;
     QList<Bind *> binds;
 
-    Snapshot::const_iterator end = snapshot.end();
-    for (Snapshot::const_iterator iter = snapshot.begin(); iter != end; ++iter) {
-        Document::Ptr doc = *iter;
-        Bind *newBind = new Bind(doc, snapshot, interp);
-        binds += newBind;
-        if (doc == currentDocument)
-            currentBind = newBind;
+    QSet<QString> processed;
+    QStringList todo;
+
+    QMultiHash<QString, Document::Ptr> documentByPath;
+    foreach (Document::Ptr doc, snapshot)
+        documentByPath.insert(doc->path(), doc);
+
+    todo.append(currentDocument->path());
+
+    // Bind the reachable documents.
+    while (! todo.isEmpty()) {
+        const QString path = todo.takeFirst();
+
+        if (processed.contains(path))
+            continue;
+
+        processed.insert(path);
+
+        QStringList localImports;
+        foreach (Document::Ptr doc, documentByPath.values(path)) {
+            Bind *newBind = new Bind(doc, snapshot, interp);
+            binds += newBind;
+
+            localImports += newBind->localImports();
+
+            if (doc == currentDocument)
+                currentBind = newBind;
+        }
+
+        localImports.removeDuplicates();
+        todo += localImports;
     }
 
     LinkImports linkImports;
@@ -397,6 +426,12 @@ bool Bind::visit(UiImport *ast)
             namespaceObject->setProperty(object->qmlTypeName(), object);
         }
 #endif // NO_DECLARATIVE_BACKEND
+    } else if (ast->fileName) {
+        QString path = _doc->path();
+        path += QLatin1Char('/');
+        path += ast->fileName->asString();
+        path = QDir::cleanPath(path);
+        _localImports.append(path);
     }
 
     return false;
diff --git a/src/libs/qmljs/qmljsbind.h b/src/libs/qmljs/qmljsbind.h
index ec6f1c38f8f85f074be7cbf6d7b20b8bc111e371..95dcbab11085cb349d7d3dab12aedc42eb7a2e08 100644
--- a/src/libs/qmljs/qmljsbind.h
+++ b/src/libs/qmljs/qmljsbind.h
@@ -51,6 +51,7 @@ public:
     virtual ~Bind();
 
     QStringList includedScripts() const;
+    QStringList localImports() const;
 
     // ### TODO: This methods should go. Bind each document after parsing, link later.
     static Interpreter::ObjectValue *scopeChainAt(Document::Ptr currentDocument,
@@ -95,6 +96,7 @@ private:
     QHash<AST::UiObjectDefinition *, Interpreter::ObjectValue *> _qmlObjectDefinitions;
     QHash<AST::UiObjectBinding *, Interpreter::ObjectValue *> _qmlObjectBindings;
     QStringList _includedScripts;
+    QStringList _localImports;
 
     friend class LinkImports;
     friend class Link;