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

qmljsParser strangeness with anonymous functions

XMLWordPrintable

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

      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

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes