Commit Graph

22 Commits

Author SHA1 Message Date
Ulf Hermann 41bbf7e376 QML: Consider the semicolon as part of expression statements
When asked for lastSourceLocation() we should always return the
semicolon token. In order for that to work, the semicolon token needs to
be valid in all cases. In the case of object literals as expressions for
properties we neither accepted nor synthesized a semicolon as delimiter.
Add an optional semicolon that we can then also use as end of the
expression statement.

Furthermore, this triggered a silent rule conflict for ImportSpecifier, which
for some reason did not arise before:
IdentifierReference could resolve to both ImpordBinding and IdentifierName,
causing ambiguity in the grammar, and ultimately caused parse failues
when parsing an import statement.
This is now resolved by explicitly telling the parser to prefer
shifting.

Initial-patch-by: Ulf Hermann <ulf.hermann@qt.io>
Change-Id: Iaec29c452b577312248a17cb48f005f4fc0bd8c4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-11-18 14:01:44 +01:00
Simon Hausmann a06736cab7 Add basic type annotation support for QML functions to the grammar
Inspired by TypeScript syntax, allow optional type annotations in the
style of ": <name of type>" in for the parameters of functions and their
return type.

These annotations are not used at the moment, so by default we produce
an error message when encountering them in the AST.

In addition their usage is limited to functions declared in the QML
scope. All other uses attempt to produce readable syntax errors. So for
example this is okay:

    Item {
        function blah(param: string) string { ... }
    }

And this is not okay:

    // some file.js
    function blah(param: string) : string { ... }

Change-Id: I12d20b4e2ce92e01108132975a06cfd13ba4a254
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-07-09 16:52:01 +02:00
Fabian Kosmale 9b1f2a7d0e extend grammar for better version parsing support
Be more strict in parsing version numbers
This also makes it easier to access the version number in other places
using the Visitor interface, like (soon) the linter and avoids reparsing
the text twice.

Potential disadvantages: previously allowed import statements will
rejected at parse time, e.g.
import QtQuick 0b10

Potential further advantage: Weird import statements like
import QtQuick 0b10
will be rejected earlier

Change-Id: Ifcd187b79a90952bc964c688afa4ea9b158e5109
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-04 12:41:09 +02:00
Qt Forward Merge Bot 369f3e57b8 Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I59cb196ab17ed8504b33db01d827052eb6891efa
2019-06-06 01:00:05 +02:00
Ulf Hermann 51696d5e8d Parser: Accept templated readonly properties
Change-Id: I37d313e3156a44eb4487b1be007aa93ace18d882
Fixes: QTBUG-76018
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-31 16:30:09 +02:00
Friedemann Kleint 59410dd2f5 Tests: Fix warnings about comparing signed/unsigned
Fix warnings like:
qtestcase.h: In instantiation of 'bool QTest::qCompare(const T1&, const T2&, const char*, const char*, const char*, int) [with T1 = unsigned int; T2 = int]':
tst_qquickrectangle.cpp:137:1559:   required from here
qtestcase.h:423:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Change-Id: I1039e70a2933f196266512a1f5880ee409c1548b
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-04-08 08:39:30 +00:00
Ulf Hermann 73231fe953 Unify the JavaScript parsing recursion checks
We only need to check in one central location and we can allow for more
recursion. 4k recursions seem tolerable. A common default for stack
sizes is 8MB. Each recursion step takes up to 1k stack space in debug
mode. So, exhausting this would burn about half of the available stack
size. We don't report the exact source location in this case as finding
the source location may itself trigger a deep recursion.

Fixes: QTBUG-74087
Change-Id: I43e6e20b322f6035c7136a6f381230ec285c30ae
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-03-15 11:53:22 +00:00
Ulf Hermann 885e4af1f4 QML: Don't crash the parser on certain kinds of bad input
Fixes: QTBUG-72734
Change-Id: I92146ec517c6a26a67e13830618e137f2a3021c2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-02-18 07:24:08 +00:00
Lars Knoll c68dc99c92 Add support for arrow functions
Arrow parameter lists are tricky and require some reparsing
by the standard to avoid conflicts in the parser with
expression statements.

Add an IsArrowFunction flag to the CompiledData::Function. This
information is required in the runtime, when creating Function
objects, as it does influence their behaviour in subtle ways.

Change-Id: I298801b091f98e30a9269d3c77d9ff94e519dabc
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-26 20:26:51 +00:00
Lars Knoll 19d3b7eb4c Don't try to verify the AST after parse errors
In preparation for the ES6 changes, where one or two files
won't parse correctly anymore.

Change-Id: Ie83e684761b2d7dcdec1d44f67006f60fb6e500c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-25 17:50:05 +00:00
Lars Knoll dad5d1cc82 Add support for ES6 template strings
This requires a bit of bookeeping in the lexer, as we can have
arbitrary expressions inside the ${...}. To make this work, keep
a stack of template states, in which we count the unclosed braces
to match up with the correct closing brace.

Implements support for `...`. Expressions of the type Foo`...`
and Foo()`...` will come in follow-up commits.

Change-Id: Ia332796cfb77895583d0093732e6f56c8b0662c9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-04-25 17:48:56 +00:00
Peter Hartmann 30dbe57521 QQmlComponent: Fix heap buffer overflow with bogus input
Change-Id: I8a725018a5aeb39df370f856cd77d887faa511e3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-05-03 14:49:55 +00:00
Jani Heikkinen 38ec3bd755 Updated license headers
From Qt 5.7 -> tools & applications are lisenced under GPL v3 with some
exceptions, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/

Updated license headers to use new GPL-EXCEPT header instead of LGPL21 one
(in those files which will be under GPL 3 with exceptions)

Change-Id: I04760a0801837cfc516d1c7c02d4f503f6bb70b6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-20 11:46:25 +00:00
Jani Heikkinen c5796292ad Update copyright headers
Qt copyrights are now in The Qt Company, so we could update the source
code headers accordingly. In the same go we should also fix the links to
point to qt.io.

Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9
Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
2015-02-12 10:28:11 +00:00
Jani Heikkinen e7ceacda70 Update license headers and add new licenses
- Renamed LICENSE.LGPL to LICENSE.LGPLv21
- Added LICENSE.LGPLv3 & LICENSE.GPLv2
- Removed LICENSE.GPL

Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0
Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
2014-08-25 11:28:46 +02:00
Erik Verbruggen 0f4617f9fb Remove unused field in test class.
Change-Id: Id9bfbd1c84acb59a669908e933ed1f63a4987526
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-03-19 01:57:45 +01:00
Sergio Ahumada 83deab8d1b Update copyright year in Digia's license headers
Change-Id: I6c3bd7bebe3d62d1cfd0fa6334544c9db8398c76
Reviewed-by: Akseli Salovaara <akseli.salovaara@digia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
2013-01-10 19:52:37 +01:00
Iikka Eklund 46010aa7a2 Change copyrights from Nokia to Digia
Change copyrights and license headers from Nokia to Digia

Change-Id: Ie7f5d49ed8235d7a7845ab68f99ad1c220e64d5c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2012-09-23 08:22:24 +02:00
J-P Nurmi 31d5249ae1 QtQml tests: remove QSKIP -> wrap within !QTEST_CROSS_COMPILED guards
Change-Id: I200bf6feb137e39061f144bdabd825dea70bd539
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2012-09-07 15:55:36 +02:00
Kurt Korbatits 5de103291d Fixed unittests skipping for cross_compile option
- qmlmin, qqmlparser, examples unittests to skip source dependent
  tests when cross_compile option used as content not available.

Change-Id: Ieaadeff0c303f0a633b8a3cc506a764ea995cf42
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
2012-03-29 00:35:32 +02:00
Kurt Korbatits 65764c0334 Changed qml tests to work from install directory
- Changed tests to use TESTDATA
- moved qqmlcontext to private test as it contains private header
- added check for cross_compile option to skip when sources not available

Change-Id: I0f68f58ffcb1b41b8e40a9851e3e003fe72ee2f9
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
2012-03-07 06:24:18 +01:00
Matthew Vogt b855240b78 Rename QDeclarative symbols to QQuick and QQml
Symbols beginning with QDeclarative are already exported
by the quick1 module.

Users can apply the bin/rename-qtdeclarative-symbols.sh
script to modify client code using the previous names of the
renamed symbols.

Task-number: QTBUG-23737
Change-Id: Ifaa482663767634931e8711a8e9bf6e404859e66
Reviewed-by: Martin Jones <martin.jones@nokia.com>
2012-02-24 04:51:31 +01:00