Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-22326

Creator breaks JavaScript code when auto-formatting QML or JS files.

    XMLWordPrintable

Details

    • All
    • 3d21c7fdc3b70a7c0dfecec8b88beb99d03c517e

    Description

      QtCreator's auto-formatting function for QML/JS code (Tools -> QML/JS -> Reformat File) breaks JavaScript code, whether embedded in QML files or in a separate JavaScript file. This happens on Linux and Windows with the QtCreator version from the official installer.

      4 errors occur since at least version 4.8, up to the most recent 4.9:

      1. Function arguments are "merged" into one word, i.e. commas and spaces between them removed.
      2. Variables declared in for-loops are removed.
      3. In pure JavaScript files, the ".pragma library" directive is removed.
      4. Pragma directives (.pragma library and pragma Singleton) are removed or broken.

      Example:

      Before:

      function pointOnCircle(center, radius, angleDeg) {
          for(var i=0; i < 10; ++i)
              console.log("test", i)
      
          var x = center.x + (radius * Math.cos(deg2Rad(angleDeg - 90)))
          var y = center.y + (radius * Math.sin(deg2Rad(angleDeg - 90)))
          return Qt.point(x, y)
      }
      
      function deg2Rad(deg) {
          return deg * Math.PI / 180
      }

      After auto-formatting:

      function pointOnCircle(centerradiusangleDeg) {
          for (; i < 10; ++i)
              console.log("test", i)
      
          var x = center.x + (radius * Math.cos(deg2Rad(angleDeg - 90)))
          var y = center.y + (radius * Math.sin(deg2Rad(angleDeg - 90)))
          return Qt.point(x, y)
      }
      
      function deg2Rad(deg) {
          return deg * Math.PI / 180
      }
      

      Attachments

        Issue Links

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

          Activity

            People

              ulherman Ulf Hermann
              coderr Julian
              Votes:
              8 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes