forked from qt-creator/qt-creator
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:
@@ -84,6 +84,12 @@ void JsonCheck::postVisit(Node *)
|
||||
analysis()->m_ranking += previous.m_ranking;
|
||||
}
|
||||
|
||||
bool JsonCheck::visit(AST::TemplateLiteral *ast)
|
||||
{
|
||||
Node::accept(ast->expression, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonCheck::visit(ObjectPattern *ast)
|
||||
{
|
||||
if (!proceedCheck(JsonValue::Object, ast->lbraceToken))
|
||||
|
||||
@@ -51,6 +51,7 @@ private:
|
||||
bool preVisit(AST::Node *) override;
|
||||
void postVisit(AST::Node *) override;
|
||||
|
||||
bool visit(AST::TemplateLiteral *ast) override;
|
||||
bool visit(AST::ObjectPattern *ast) override;
|
||||
bool visit(AST::ArrayPattern *ast) override;
|
||||
bool visit(AST::NullExpression *ast) override;
|
||||
|
||||
@@ -350,6 +350,12 @@ bool Bind::visit(UiInlineComponent *ast)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Bind::visit(AST::TemplateLiteral *ast)
|
||||
{
|
||||
Node::accept(ast->expression, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Bind::visit(PatternElement *ast)
|
||||
{
|
||||
if (ast->bindingIdentifier.isEmpty() || !ast->isVariableDeclaration())
|
||||
|
||||
@@ -82,6 +82,7 @@ protected:
|
||||
bool visit(AST::UiInlineComponent *ast) override;
|
||||
|
||||
// QML/JS
|
||||
bool visit(AST::TemplateLiteral *ast) override;
|
||||
bool visit(AST::FunctionDeclaration *ast) override;
|
||||
bool visit(AST::FunctionExpression *ast) override;
|
||||
bool visit(AST::PatternElement *ast) override;
|
||||
|
||||
@@ -809,6 +809,12 @@ bool Check::visit(UiObjectInitializer *)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Check::visit(AST::TemplateLiteral *ast)
|
||||
{
|
||||
Node::accept(ast->expression, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Check::endVisit(UiObjectInitializer *uiObjectInitializer)
|
||||
{
|
||||
Q_UNUSED(uiObjectInitializer)
|
||||
|
||||
@@ -77,6 +77,7 @@ protected:
|
||||
bool visit(AST::FunctionExpression *ast) override;
|
||||
bool visit(AST::UiObjectInitializer *) override;
|
||||
|
||||
bool visit(AST::TemplateLiteral *ast) override;
|
||||
bool visit(AST::BinaryExpression *ast) override;
|
||||
bool visit(AST::Block *ast) override;
|
||||
bool visit(AST::WithStatement *ast) override;
|
||||
|
||||
@@ -211,6 +211,12 @@ bool Evaluate::visit(AST::UiQualifiedId *ast)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Evaluate::visit(AST::TemplateLiteral *ast)
|
||||
{
|
||||
_result = _valueOwner->stringValue();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Evaluate::visit(AST::ThisExpression *)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -75,6 +75,7 @@ protected:
|
||||
bool visit(AST::UiQualifiedId *ast) override;
|
||||
|
||||
// QmlJS
|
||||
bool visit(AST::TemplateLiteral *ast) override;
|
||||
bool visit(AST::ThisExpression *ast) override;
|
||||
bool visit(AST::IdentifierExpression *ast) override;
|
||||
bool visit(AST::NullExpression *ast) override;
|
||||
|
||||
@@ -61,6 +61,12 @@ bool ScopeAstPath::preVisit(Node *node)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScopeAstPath::visit(AST::TemplateLiteral *node)
|
||||
{
|
||||
Node::accept(node->expression, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScopeAstPath::visit(UiPublicMember *node)
|
||||
{
|
||||
if (node && node->statement && node->statement->kind == node->Kind_Block
|
||||
|
||||
@@ -44,6 +44,7 @@ protected:
|
||||
using Visitor::visit;
|
||||
|
||||
bool preVisit(AST::Node *node) override;
|
||||
bool visit(AST::TemplateLiteral *node) override;
|
||||
bool visit(AST::UiPublicMember *node) override;
|
||||
bool visit(AST::UiScriptBinding *node) override;
|
||||
bool visit(AST::UiObjectDefinition *node) override;
|
||||
|
||||
Reference in New Issue
Block a user