Commit be9f974a authored by Denis Steckelmacher's avatar Denis Steckelmacher

Support single-line slots and slots associated with signals having a complex qualified identifier

"onWidthChanged: console.log(value)" and "Component.onLoad: doSomething()" are
now both supported.
parent 64b6788b
......@@ -857,31 +857,34 @@ bool DeclarationBuilder::visit(QmlJS::AST::UiScriptBinding* node)
}
}
// If a Javascript block is used as expression, open a context for it, so
// that variables declared in one block don't become visible to the other blocks
auto block = QmlJS::AST::cast<QmlJS::AST::Block*>(node->statement);
// Use ExpressionVisitor to find the signal/property bound
DeclarationPointer bindingDecl = findType(node->qualifiedId).declaration;
DUChainPointer<ClassFunctionDeclaration> signal;
// If a Javascript block is used as expression or if the script binding is a
// slot, open a subcontext so that variables declared in the binding are kept
// local, and the signal parameters can be visible to the slot
if ((
bindingDecl &&
(signal = bindingDecl.dynamicCast<ClassFunctionDeclaration>()) &&
signal->isSignal()
) ||
node->statement->kind == QmlJS::AST::Node::Kind_Block) {
if (block) {
openContext(
block,
m_session->locationsToInnerRange(block->lbraceToken, block->rbraceToken),
node->statement,
m_session->locationsToInnerRange(
node->statement->firstSourceLocation(),
node->statement->lastSourceLocation()
),
DUContext::Other
);
// If this script binding is a slot, import the parameters of its signal
DeclarationPointer bindingDecl = QmlJS::getDeclarationOrSignal(
QualifiedIdentifier(bindingName),
currentContext()
);
if (bindingDecl) {
auto signal = bindingDecl.dynamicCast<ClassFunctionDeclaration>();
if (signal && signal->isSignal() && signal->internalFunctionContext()) {
DUChainWriteLocker lock;
if (signal && signal->isSignal() && signal->internalFunctionContext()) {
DUChainWriteLocker lock;
currentContext()->addImportedParentContext(signal->internalFunctionContext());
}
currentContext()->addImportedParentContext(signal->internalFunctionContext());
}
}
......@@ -892,10 +895,8 @@ void DeclarationBuilder::endVisit(QmlJS::AST::UiScriptBinding* node)
{
QmlJS::AST::Visitor::endVisit(node);
// If the script binding opened a code block, close it
auto block = QmlJS::AST::cast<QmlJS::AST::Block*>(node->statement);
if (block) {
// If visit(UiScriptBinding) has opened a context, close it
if (currentContext()->type() == DUContext::Other) {
closeContext();
}
}
......
......@@ -51,13 +51,14 @@ Module {
}
/**
* "toString" : "void dataChanged (plugins::QModelIndex, plugins::QModelIndex, int)",
* "useCount" : 1
* "useCount" : 2
*/
Signal {
name: "dataChanged"
/**
* "toString" : "plugins::QModelIndex topLeft"
* "toString" : "plugins::QModelIndex topLeft",
* "useCount" : 1
*/
Parameter /* */ { name: "topLeft"; type: "QModelIndex" }
......@@ -92,9 +93,7 @@ Module {
*/
id: foo
onDataChanged: {
return;
}
onDataChanged: console.log(topLeft);
}
/**
......@@ -105,5 +104,9 @@ Module {
id: bar
rootItem.childCount: "foo"
AbstractItemModel.onDataChanged: {
return;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment