Details
-
Task
-
Resolution: Unresolved
-
P2: Important
-
None
Description
At the moment it is possible to import ES modules from within .qml files by using the ".mjs" extension:
import "MyModule.mjs" as MyModule MouseArea { onClicked: MyModule.blah(); }
This mechanism replaces the previous import of ".js" files in QML using proprietary syntax (".pragma library") with a JavaScript language compliant way of importing and exporting API within JavaScript modules.
The old syntax also permitted for the import of QML modules and accessing QML types, using proprietary syntax:
.import QtQuick 2.0 as QQ // can use QQ.Item.SomeEnumValue here, for example
In order for ES modules to fully replace the old import mechanism, we need the ability to
import QML modules. The standard ES Module import syntax is tailored towards the import of other modules from file-like resources:
import * as Blah from "./foo.mjs" import { blub } from "./baz.mjs"
In order to implement support for QML module imports, we need a way to distinguish a file resource from a versioned QML module specification. One possible way of doing that
would be to use "@" prefix similar to what nodejs was considering:
import * as QQ from "@QtQuick 2.0" import { QtObject } from "@QtQml 2.4" ...
Once we have this, we can complete the transition and update all our examples and documentation.
Attachments
Issue Links
- duplicates
-
QTBUG-79027 Can't import QML module from .mjs module
-
- Closed
-
- resulted from
-
QTBUG-47735 ECMAScript 7 Support
-
- Closed
-