qmljs: reformat inline components

Fixes: QTCREATORBUG-25381
Change-Id: I472105cd6436d4d0ae7369880c332b8f4a2321ad
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Fawzi Mohamed
2021-02-23 08:38:51 +01:00
parent c57f6a703b
commit 0ff75a721f
4 changed files with 28 additions and 0 deletions

View File

@@ -218,6 +218,12 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
default: leave(true); continue;
} break;
case component_start:
switch (kind) {
case Identifier: turnInto(StateType::component_name); break;
default: leave(true); continue;
} break;
case property_name:
turnInto(property_maybe_initializer);
break;
@@ -957,6 +963,8 @@ CodeFormatter::TokenKind CodeFormatter::extendedTokenKind(const QmlJS::Token &to
return Property;
if (text == QLatin1String("readonly"))
return Readonly;
if (text == QLatin1String("component"))
return Component;
if (text == QLatin1String("required"))
return Required;
if (text == QLatin1String("on"))

View File

@@ -109,6 +109,8 @@ public: // must be public to make Q_GADGET introspection work
property_list_open, // after 'list' as a type
property_name, // after the type
property_maybe_initializer, // after the identifier
component_start, // after component
component_name, // after component Name
enum_start, // after 'enum'
@@ -239,6 +241,7 @@ protected:
List,
Property,
Required,
Component,
Readonly,
Question,

View File

@@ -598,6 +598,15 @@ protected:
return false;
}
bool visit(UiInlineComponent *ast) override
{
out(ast->componentToken);
out(" ");
out(ast->name.toString());
out(": ");
return true;
}
bool visit(UiObjectDefinition *ast) override
{
accept(ast->qualifiedTypeNameId);

View File

@@ -0,0 +1,8 @@
import QtQuick 2.15
Item {
component CustomText: Text {
color: "red"
text: "Test Text"
}
}