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

Using class statement inside .mjs module leads to import failure

    XMLWordPrintable

    Details

    • Commits:
      6146021eb72a0aca5cc635b577b5e43b60824bc8 (qt/qtdeclarative/5.12)

      Description

      app.mjs:

      class Point {
          constructor(x = 0, y = 0) {
              this.x = x;
              this.y = y;
          }
          plus(other) {
              return new Point(this.x + other.x, this.y + other.y);
          }
          toString() {
              return `${this.constructor.name} { x: ${this.x}, y: ${this.y} }`;
          }
      }
      
      function main() {
          const p = new Point(1, 2);
          console.log('main()', p.plus(new Point(3, 4)));
      }
      
      export { main };
      

       
      main.qml:

      import QtQuick 2.12
      import QtQuick.Window 2.3
      import './app.mjs' as App
      
      Window {
          title: qsTr('ECMAScript 7 Test')
          width: 640
          height: 480
          Component.onCompleted: {
              App.main() // TypeError: Property 'main' of object TypeError: Type error is not a function
          }
      }
      

       

      Removing class from app.mjs make this example work.
      Moving class from app.mjs into separate module and importing it with import statement make this example work.
      Renaming app.mjs into app.js and removing export keyword make this example work too.

       

        Attachments

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

          Activity

            People

            Assignee:
            shausman Simon Hausmann
            Reporter:
            evg656e Evgeny
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes