diff --git a/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.cpp b/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.cpp index 2e5d887254c5c8ccf8dabe79c88596fc85005f5e..1edac108ad2a0e2378c4b9910f1a83674655f8a2 100644 --- a/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.cpp +++ b/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.cpp @@ -54,13 +54,16 @@ FirstDefinitionFinder::FirstDefinitionFinder(const QString &text): \arg the offset of the object to search in \return the offset of the first object definition */ -quint32 FirstDefinitionFinder::operator()(quint32 offset) +qint32 FirstDefinitionFinder::operator()(quint32 offset) { m_offset = offset; m_firstObjectDefinition = 0; Node::accept(m_doc->qmlProgram(), this); + if (!m_firstObjectDefinition) + return -1; + return m_firstObjectDefinition->firstSourceLocation().offset; } diff --git a/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.h b/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.h index 867ed1006bae291ff733a9d97ef8c9f4c1a5b047..aaf00c754ceeeaefb5cb02cb1f829ac4dbdb0bce 100644 --- a/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.h +++ b/src/plugins/qmldesigner/designercore/filemanager/firstdefinitionfinder.h @@ -43,7 +43,7 @@ class FirstDefinitionFinder: protected QmlJS::AST::Visitor public: FirstDefinitionFinder(const QString &text); - quint32 operator()(quint32 offset); + qint32 operator()(quint32 offset); protected: using QmlJS::AST::Visitor::visit; diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index 6e3f387da5d2bb181394085f69fa8407a43ba26d..b6b4e3b64ff96e36373bc952046244c74f43d1d8 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -1397,6 +1397,10 @@ void TextToModelMerger::setupComponent(const ModelNode &node) if (componentText.contains("Component")) { //explicit component FirstDefinitionFinder firstDefinitionFinder(componentText); int offset = firstDefinitionFinder(0); + if (offset < 0) { + node.variantProperty("__component_data").setValue(QLatin1String("")); + return; //No object definition found + } ObjectLengthCalculator objectLengthCalculator; unsigned length; if (objectLengthCalculator(componentText, offset, length)) {