Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-71389

Add support for QML module imports in ES Modules

    XMLWordPrintable

Details

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtqmlteam Qt Qml Team User
              shausman Simon Hausmann
              Votes:
              2 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes