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

Add support for QML module imports in ES Modules

    XMLWordPrintable

    Details

    • Technical Risk:
      Normal

      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 tailed 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

              Assignee:
              qt.team.quick.subscriptions Qt Quick and Widgets Team
              Reporter:
              shausman Simon Hausmann
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes