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

JS module API doesn't work within JavaScript

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.0.0
    • 5.0.0
    • None
    • QtDeclarative sha 0507afe3fc13640fbf7d1a79c6699337b31498fc, Feb 28 2012.

    Description

      Running following code gives error "file.js:1: SyntaxError: Unexpected token .".

      .import MyModule 1.0
      
      console.log(MyModule.moduleAPI ? "MyModule is working" : "MyModule is not working")
      

      Importing the same module inside namespace results in error "file.js:3: ReferenceError: Can't find variable: Module":

      .import MyModule 1.0 as Module
      
      console.log(Module.MyModule.moduleAPI ? "MyModule is working" : "MyModule is not working")
      

      Same JS module API import, without initial dot ".", works within QML source file.

      import QtQuick 2.0
      import MyModule 1.0
      
      Item { Component.onCompleted: console.log(MyModule.moduleAPI ? "MyModule is working" : "MyModule is not working") }
      

      MyModule qmldir file contains "MyModule 1.0 MyModule.js". Attached example code as MyModule.tar.gz to reproduce the issue.

      Attachments

        1. MyModule.tar.gz
          0.5 kB
          Joona Petrell

        Issue Links

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

          Activity

            People

              mvogt Matthew Vogt (closed Nokia identity) (Inactive)
              jpetrell Joona Petrell
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes