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

qmljsParser strangeness with anonymous functions

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • 6.10
    • 6.1, 6.2
    • QML: Tooling
    • None

    Description

      There is an ambiguity with functions and UIObjects, for this reason the normal FunctionDeclaration was split in FunctionDeclaration_Default (with anonymous function) and FunctionDeclaration, that then continues in the HoistableStatemen and HoistableStatement_Default rules.
      As consequence of that parsing of an anonymous function (or a function containing it) fails with parseStatement, parseExpression, parseScript.
      The parsing in the UiBinding works though, but for example requires a space after the function keyword (and the AST token contains the space!).
      I am not yet sure how the fix this, it crops up when I reformat the expression in the Dom and reparse just the modified expression.
      For example tests/auto/qml/qmlformat/data/Example1.qml, but

      Item {
       a: function (){ return 42; }()
      }

      is a more compact example. With the space the parser can parse it (function() fails), but the DOM fails then the subsequent parse of the ScriptExpression without the context,
      Currently I detect the failure and keep the old AST printing a warning, but a proper fix should be done.

      By the way a js resource with

      function foo(){
        return function (){ return 420; }();
      }
      

      works

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              fawzi Fawzi Mohamed
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes