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

qmlformat: Unnecessary replacement of 'let' with 'var', leading to inline write errors

    XMLWordPrintable

Details

    • 84dd339e2e (qt/qtdeclarative/dev) 5c597dd0b8 (qt/qtdeclarative/6.3) 7c5570ca8c (qt/qtdeclarative/6.4) 5c597dd0b8 (qt/qtdeclarative/6.3.2) 5c597dd0b8 (qt/tqtc-qtdeclarative/6.3) 5c597dd0b8 (qt/tqtc-qtdeclarative/6.3.2), 13760c8d4 (tqtc/lts-6.2)

    Description

      Original code

      import QtQml
      
      QtObject {
          function foo() {
              for (let i = 0; i < 5; ++i)
                  console.log(i);
          }
      }
      

       

      Problem 1

      qmlformat wants to change 'let' to 'var' for no good reason. 'let' has block scope while 'var' does not.

      import QtQml
      
      QtObject {
          function foo() {
              for (var i = 0; i < 5; ++i)
                  console.log(i);
          }
      }
      

       

       

      Problem 2

      Inline formatting (`qmlformat -i main.qml`) fails with

      qt.qmldom.writeOut: reparsed writeOut of /home/dev/main.qml has changes: - .components[""][0].objects[0].methods["foo"][0].body.astRelocatableDump value("<StatementList>\n <ForStatement forToken=\"for\" lparenToken=\"(\" rparenToken=\")\">\n <VariableDeclarationList commaToken=\"\">\n <PatternElement identifierToken=\"i\" bindingIdentifier=\"i\" type=\"5\" scope=\"2\" isForDeclaration=\"false\">\n <NumericLiteral value=\"0\" literalToken=\"0\">\n </NumericLiteral>\n </PatternElement>\n </VariableDeclarationList>\n <BinaryExpression op=\"15\" operatorToken=\"<\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n <NumericLiteral value=\"5\" literalToken=\"5\">\n </NumericLiteral>\n </BinaryExpression>\n <PreIncrementExpression incrementToken=\"++\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </PreIncrementExpression>\n <ExpressionStatement>\n <CallExpression lparenToken=\"(\" rparenToken=\")\">\n <FieldMemberExpression name=\"log\" dotToken=\".\" identifierToken=\"log\">\n <IdentifierExpression name=\"console\" identiferToken=\"console\">\n </IdentifierExpression>\n </FieldMemberExpression>\n <ArgumentList commaToken=\"\" isSpreadElement=\"false\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </ArgumentList>\n </CallExpression>\n </ExpressionStatement>\n </ForStatement>\n</StatementList>\n") + .components[""][0].objects[0].methods["foo"][0].body.astRelocatableDump value("<StatementList>\n <ForStatement forToken=\"for\" lparenToken=\"(\" rparenToken=\")\">\n <VariableDeclarationList commaToken=\"\">\n <PatternElement identifierToken=\"i\" bindingIdentifier=\"i\" type=\"5\" scope=\"1\" isForDeclaration=\"false\">\n <NumericLiteral value=\"0\" literalToken=\"0\">\n </NumericLiteral>\n </PatternElement>\n </VariableDeclarationList>\n <BinaryExpression op=\"15\" operatorToken=\"<\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n <NumericLiteral value=\"5\" literalToken=\"5\">\n </NumericLiteral>\n </BinaryExpression>\n <PreIncrementExpression incrementToken=\"++\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </PreIncrementExpression>\n <ExpressionStatement>\n <CallExpression lparenToken=\"(\" rparenToken=\")\">\n <FieldMemberExpression name=\"log\" dotToken=\".\" identifierToken=\"log\">\n <IdentifierExpression name=\"console\" identiferToken=\"console\">\n </IdentifierExpression>\n </FieldMemberExpression>\n <ArgumentList commaToken=\"\" isSpreadElement=\"false\">\n <IdentifierExpression name=\"i\" identiferToken=\"i\">\n </IdentifierExpression>\n </ArgumentList>\n </CallExpression>\n </ExpressionStatement>\n </ForStatement>\n</StatementList>\n") 
      
      qt.qmldom.writeOut: failure reformatting  "main.qml"
      "Error while writing"
      

       

      This error only occurs with the 'let' -> 'var' change, not with other types of changes. It should disappear when Problem 1 is fixed.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-105361
          # Subject Branch Project Status CR V

          Activity

            People

              fabiankosmale Fabian Kosmale
              skoh-qt Sze Howe Koh
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes