diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-01 11:01:50 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-01 22:04:40 +0000 |
commit | 5d38f9641bf8f867491c434fd2f00d2ccb0de984 (patch) | |
tree | acfbbfc8543e3d7840a03dd26efb683fa8b2136f | |
parent | f3f1660247d4cd4fac36c394368111338aef6fa8 (diff) |
CMake: Include upper case .js and .mjs files in qmldir
You can use them as singletons.
Fixes: QTBUG-100326
Change-Id: I8e07600657bd43ba8376279ffe39cfa5d3213c38
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit bf38043b6107cb10bca4be78ecc8bbc20338a61b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 11 | ||||
-rw-r--r-- | tests/auto/qml/qmlbasicapp/BasicExtension/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/auto/qml/qmlbasicapp/BasicExtension/ESModule.mjs | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlbasicapp/BasicExtension/Less.js | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmlbasicapp/BasicExtension/lowerCase.js | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlbasicapp/BasicExtension/lowerCaseModule.mjs | 1 | ||||
-rw-r--r-- | tests/auto/qml/qmlbasicapp/main.qml | 2 | ||||
-rw-r--r-- | tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp | 8 |
8 files changed, 21 insertions, 8 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index b370c2c596..494f0e2336 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -1465,17 +1465,16 @@ function(qt6_target_qml_sources target) get_source_file_property(qml_file_typename ${qml_file_src} QT_QML_SOURCE_TYPENAME) if (NOT qml_file_typename) get_filename_component(qml_file_ext ${qml_file_src} EXT) - if (NOT qml_file_ext STREQUAL ".js" AND NOT qml_file_ext STREQUAL ".mjs") - get_filename_component(qml_file_typename ${qml_file_src} NAME_WE) - endif() + get_filename_component(qml_file_typename ${qml_file_src} NAME_WE) endif() # Do not add qmldir entries for lowercase names. Those are not components. if (qml_file_typename AND qml_file_typename MATCHES "^[A-Z]") - if (qml_file_ext AND NOT qml_file_ext STREQUAL ".qml" AND NOT qml_file_ext STREQUAL ".ui.qml") + if (qml_file_ext AND NOT qml_file_ext STREQUAL ".qml" AND NOT qml_file_ext STREQUAL ".ui.qml" + AND NOT qml_file_ext STREQUAL ".js" AND NOT qml_file_ext STREQUAL ".mjs") message(AUTHOR_WARNING - "${qml_file_src} has a file extension different from .qml and .ui.qml. " - "This leads to unexpected component names." + "${qml_file_src} has a file extension different from .qml, .ui.qml, .js, " + "and .mjs. This leads to unexpected component names." ) endif() diff --git a/tests/auto/qml/qmlbasicapp/BasicExtension/CMakeLists.txt b/tests/auto/qml/qmlbasicapp/BasicExtension/CMakeLists.txt index 3a1074bf53..a08c71a294 100644 --- a/tests/auto/qml/qmlbasicapp/BasicExtension/CMakeLists.txt +++ b/tests/auto/qml/qmlbasicapp/BasicExtension/CMakeLists.txt @@ -13,4 +13,7 @@ qt6_add_qml_module(additional_qml_module Extension.qml More.ui.qml Less.js + ESModule.mjs + lowerCase.js + lowerCaseModule.mjs ) diff --git a/tests/auto/qml/qmlbasicapp/BasicExtension/ESModule.mjs b/tests/auto/qml/qmlbasicapp/BasicExtension/ESModule.mjs new file mode 100644 index 0000000000..e1424dc501 --- /dev/null +++ b/tests/auto/qml/qmlbasicapp/BasicExtension/ESModule.mjs @@ -0,0 +1 @@ +export function eee() { return "eee" } diff --git a/tests/auto/qml/qmlbasicapp/BasicExtension/Less.js b/tests/auto/qml/qmlbasicapp/BasicExtension/Less.js index 585b645dca..a808d7be27 100644 --- a/tests/auto/qml/qmlbasicapp/BasicExtension/Less.js +++ b/tests/auto/qml/qmlbasicapp/BasicExtension/Less.js @@ -1 +1 @@ -function bar() {} +function bar() { return "bar" } diff --git a/tests/auto/qml/qmlbasicapp/BasicExtension/lowerCase.js b/tests/auto/qml/qmlbasicapp/BasicExtension/lowerCase.js new file mode 100644 index 0000000000..9d90c9c6f1 --- /dev/null +++ b/tests/auto/qml/qmlbasicapp/BasicExtension/lowerCase.js @@ -0,0 +1 @@ +function a() { return "a" } diff --git a/tests/auto/qml/qmlbasicapp/BasicExtension/lowerCaseModule.mjs b/tests/auto/qml/qmlbasicapp/BasicExtension/lowerCaseModule.mjs new file mode 100644 index 0000000000..f35813109c --- /dev/null +++ b/tests/auto/qml/qmlbasicapp/BasicExtension/lowerCaseModule.mjs @@ -0,0 +1 @@ +export function fff() { return "fff" } diff --git a/tests/auto/qml/qmlbasicapp/main.qml b/tests/auto/qml/qmlbasicapp/main.qml index dc572d29af..a01b56d35d 100644 --- a/tests/auto/qml/qmlbasicapp/main.qml +++ b/tests/auto/qml/qmlbasicapp/main.qml @@ -58,4 +58,6 @@ Clock { // this class is defined in QML (Clock.qml) minutes: time.minute property Extension extension // from BasicExtension property More more: More {} + property string fromESModule: ESModule.eee() + property string fromJSFile: Less.bar() } diff --git a/tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp b/tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp index 4d62fc46b6..2fd7ef634b 100644 --- a/tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp +++ b/tests/auto/qml/qmlbasicapp/tst_qmlbasicapp.cpp @@ -61,6 +61,9 @@ void tst_basicapp::loadComponent() QObject *more = qvariant_cast<QObject*>(o->property("more")); QVERIFY(more); QCOMPARE(more->objectName(), QStringLiteral("ui.qml")); + + QCOMPARE(o->property("fromESModule").toString(), QStringLiteral("eee")); + QCOMPARE(o->property("fromJSFile").toString(), QStringLiteral("bar")); } void tst_basicapp::resourceFiles() @@ -133,7 +136,10 @@ void tst_basicapp::qmldirContents() QVERIFY(qmldir.open(QIODevice::ReadOnly)); const QByteArray contents = qmldir.readAll(); QVERIFY(contents.contains("More 1.0 More.ui.qml")); - QVERIFY(!contents.contains("Less.js")); + QVERIFY(contents.contains("Less.js")); + QVERIFY(contents.contains("ESModule.mjs")); + QVERIFY(!contents.contains("lowerCase.js")); + QVERIFY(!contents.contains("lowerCaseModule.mjs")); } } |