aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-07-01 10:45:46 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-09-04 12:22:35 +0200
commitee295affc6210cb71a242f7e119e7a4f95b75fc3 (patch)
treec134ea5405839d1e16e1daed3b1d37ee3d224e70
parent0df4d8aa9ed849af00fb056dcc7af87ea1e90f20 (diff)
qmlformat: Fix template literals
Fixes: QTBUG-85317 Change-Id: I52589b681690a55f7bba7d7d9c675dc22ffa1587 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 9df9059a4b88676c7352db92391de2c268550fc0)
-rw-r--r--tests/auto/qml/qmlformat/data/verbatimString.formatted.qml3
-rw-r--r--tests/auto/qml/qmlformat/data/verbatimString.qml3
-rw-r--r--tests/auto/qml/qmlmin/tst_qmlmin.cpp3
-rw-r--r--tools/qmlformat/dumpastvisitor.cpp6
4 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlformat/data/verbatimString.formatted.qml b/tests/auto/qml/qmlformat/data/verbatimString.formatted.qml
index fa7fbbe32b..84abe38f88 100644
--- a/tests/auto/qml/qmlformat/data/verbatimString.formatted.qml
+++ b/tests/auto/qml/qmlformat/data/verbatimString.formatted.qml
@@ -1,4 +1,7 @@
Item {
property string verbatim1: 'A "verbatim" string!'
property string verbatim2: "A 'verbatim' string\u2757"
+ property string verbatim3: `400 + 300 is ${400 + 300}.
+
+mutliline`
}
diff --git a/tests/auto/qml/qmlformat/data/verbatimString.qml b/tests/auto/qml/qmlformat/data/verbatimString.qml
index 15b080a87b..fa16b97dca 100644
--- a/tests/auto/qml/qmlformat/data/verbatimString.qml
+++ b/tests/auto/qml/qmlformat/data/verbatimString.qml
@@ -1,4 +1,7 @@
Item {
property string verbatim1: 'A "verbatim" string!'
property string verbatim2: "A 'verbatim' string\u2757"
+property string verbatim3: `400 + 300 is ${400 + 300}.
+
+mutliline`
} \ No newline at end of file
diff --git a/tests/auto/qml/qmlmin/tst_qmlmin.cpp b/tests/auto/qml/qmlmin/tst_qmlmin.cpp
index 24e926ffb3..cc028d979f 100644
--- a/tests/auto/qml/qmlmin/tst_qmlmin.cpp
+++ b/tests/auto/qml/qmlmin/tst_qmlmin.cpp
@@ -137,6 +137,9 @@ void tst_qmlmin::initTestCase()
invalidFiles << "tests/auto/qml/qqmllanguage/data/requiredProperties.2.qml";
// generatorFunction.qml is not invalid per se, but the minifier cannot handle yield statements
invalidFiles << "tests/auto/qml/qqmlecmascript/data/generatorFunction.qml";
+ // minifer can't handle template strings properly
+ invalidFiles << "tests/auto/qml/qmlformat/data/verbatimString.qml";
+ invalidFiles << "tests/auto/qml/qmlformat/data/verbatimString.formatted.qml";
#endif
}
diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp
index c92d25787f..19bf3d6717 100644
--- a/tools/qmlformat/dumpastvisitor.cpp
+++ b/tools/qmlformat/dumpastvisitor.cpp
@@ -418,6 +418,12 @@ QString DumpAstVisitor::parseExpression(ExpressionNode *expression)
return "--"+parseExpression(cast<PreDecrementExpression *>(expression)->expression);
case Node::Kind_NumericLiteral:
return QString::number(cast<NumericLiteral *>(expression)->value);
+ case Node::Kind_TemplateLiteral: {
+ auto firstSrcLoc = cast<TemplateLiteral *>(expression)->firstSourceLocation();
+ auto lastSrcLoc = cast<TemplateLiteral *>(expression)->lastSourceLocation();
+ return m_engine->code().mid(static_cast<int>(firstSrcLoc.begin()),
+ static_cast<int>(lastSrcLoc.end() - firstSrcLoc.begin()));
+ }
case Node::Kind_StringLiteral: {
auto srcLoc = cast<StringLiteral *>(expression)->firstSourceLocation();
return m_engine->code().mid(static_cast<int>(srcLoc.begin()),