qmljs: correctly handle js string templates

In most cases we do want to visit the expressions in a function
template. Changing its accept0 would force those not wanting to visit
it to iterate on the templates (currently a linked list), so we add a
visit method explicitly visiting the expression in all the needed
places.

Fixes: QTCREATORBUG-21869
Change-Id: I47733544bfd32eec357810b97242608b8f7de572
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Fawzi Mohamed
2021-12-06 09:44:24 +01:00
parent 22ec44b5f3
commit a3b1dfd34a
19 changed files with 99 additions and 0 deletions

View File

@@ -158,6 +158,11 @@ public:
return true;
}
bool visit(TemplateLiteral *ast) override
{
Node::accept(ast->expression, this);
return true;
}
bool visit(VariableStatement *ast) override { test(ast); return true; }
bool visit(VariableDeclarationList *ast) override { test(ast); return true; }
bool visit(ExpressionStatement *ast) override { test(ast); return true; }

View File

@@ -31,6 +31,14 @@ ConnectionVisitor::ConnectionVisitor()
{
}
bool ConnectionVisitor::visit(QmlJS::AST::TemplateLiteral *ast)
{
m_expression.append(
qMakePair(QmlJS::AST::Node::Kind::Kind_StringLiteral, ast->value.toString()));
QmlJS::AST::Node::accept(ast->expression, this);
return true;
}
bool ConnectionVisitor::visit(QmlJS::AST::StringLiteral *ast)
{
m_expression.append(qMakePair(QmlJS::AST::Node::Kind::Kind_StringLiteral,

View File

@@ -37,6 +37,7 @@ class ConnectionVisitor : public QmlJS::AST::Visitor
public:
explicit ConnectionVisitor();
bool visit(QmlJS::AST::TemplateLiteral *ast) override;
bool visit(QmlJS::AST::StringLiteral *ast) override;
bool visit(QmlJS::AST::NumericLiteral *ast) override;
bool visit(QmlJS::AST::TrueLiteral *ast) override;

View File

@@ -148,6 +148,12 @@ protected:
return true;
}
bool visit(AST::TemplateLiteral *node) override
{
AST::Node::accept(node->expression, this);
return true;
}
bool visit(AST::IdentifierExpression *node) override
{
if (node->name != m_typeName)

View File

@@ -99,6 +99,12 @@ bool FirstDefinitionFinder::visit(QmlJS::AST::UiObjectDefinition *ast)
return true;
}
bool FirstDefinitionFinder::visit(QmlJS::AST::TemplateLiteral *ast)
{
QmlJS::AST::Node::accept(ast->expression, this);
return true;
}
void FirstDefinitionFinder::throwRecursionDepthError()
{
qWarning("Warning: Hit maximum recursion depth while visiting the AST in FirstDefinitionFinder");

View File

@@ -42,6 +42,7 @@ protected:
bool visit(QmlJS::AST::UiObjectBinding *ast) override;
bool visit(QmlJS::AST::UiObjectDefinition *ast) override;
bool visit(QmlJS::AST::TemplateLiteral *ast) override;
void throwRecursionDepthError() override;

View File

@@ -279,6 +279,13 @@ protected:
--_depth;
}
bool visit(AST::TemplateLiteral *ast) override
{
// avoid? finds function declarations in templates
AST::Node::accept(ast->expression, this);
return true;
}
bool visit(AST::FunctionExpression *) override
{
return false;
@@ -398,6 +405,12 @@ protected:
return true;
}
bool visit(AST::TemplateLiteral *ast) override
{
AST::Node::accept(ast->expression, this);
return true;
}
bool visit(AST::FunctionDeclaration *ast) override
{
_ranges.append(createRange(ast));

View File

@@ -118,6 +118,12 @@ protected:
return false;
}
bool visit(AST::TemplateLiteral *el) override
{
Node::accept(el->expression, this);
return true;
}
bool visit(AST::UiObjectBinding *node) override
{
if (node->qualifiedId
@@ -398,6 +404,12 @@ protected:
return true;
}
bool visit(AST::TemplateLiteral *el) override
{
Node::accept(el->expression, this);
return true;
}
bool visit(AST::FunctionDeclaration *node) override
{
return visit(static_cast<FunctionExpression *>(node));
@@ -557,6 +569,12 @@ protected:
return true;
}
bool visit(AST::TemplateLiteral *el) override
{
Node::accept(el->expression, this);
return true;
}
bool visit(UiScriptBinding *node) override
{
return !checkBindingName(node->qualifiedId);

View File

@@ -127,6 +127,12 @@ protected:
return handleLocationAst(ast);
}
bool visit(AST::TemplateLiteral *ast) override
{
AST::Node::accept(ast->expression, this);
return true;
}
void throwRecursionDepthError() override
{
qWarning("Warning: Hit maximum recursion depth when visiting the AST in AstPath");