aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljs.g
Commit message (Collapse)AuthorAgeFilesLines
...
* Required properties: Allow required default propertiesFabian Kosmale2020-01-291-0/+25
| | | | | | | | | This was already possible from C++, this change adds the required changes to the grammar to allow declaring required default properties in QML. Change-Id: I76cb4d70e573bf161676da8295ab257fe95ed4ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Long live QML inline componentsFabian Kosmale2020-01-231-24/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | [ChangeLog][QtQml] It is now possible to declare new QML components in a QML file via the component keyword. They can be used just as if they were declared in another file, with the only difference that the type name needs to be prefixed with the name of the containing type outside of the file were the inline component has been declared. Notably, inline components are not closures: In the following example, the output would be 42 // MyItem.qml Item { property int i: 33 component IC: Item { Component.onCompleted: console.log(i) } } // user.qml Item { property int i: 42 MyItem.IC {} } Fixes: QTBUG-79382 Change-Id: I6a5ffc43f093a76323f435cfee9bab217781b8f5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qml/parser: Implement nullish coalescingMaximilian Goldstein2019-12-051-4/+40
| | | | | | | | | | Implements the '??' operator as specified in https://github.com/tc39/proposal-nullish-coalescing. Also adds a few tests. Task-number: QTBUG-77926 Change-Id: I3993450c192d11bf1ade0662d945c1553b4c6976 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add (and ignore for now) type assertions to QMLUlf Hermann2019-11-271-0/+14
| | | | | | | | | | You can write "(something as Foo)" to give hints to any tools that you expect something to be a Foo at this place. This is not a conversion and ignored at runtime for now. Eventually the compiler will verify that the type assertions are plausible and error out if they aren't. Change-Id: I21c8705bb387f7ab2cbc153293dbf477663afe87 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Consider the semicolon as part of expression statementsUlf Hermann2019-11-181-4/+20
| | | | | | | | | | | | | | | | | | | | | | 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>
* Remove QQmlJS::AST::UiImport::versionTokenUlf Hermann2019-10-101-8/+1
| | | | | | | | It was incorrectly parsed in case of "as Foo", and it was mostly unused. Change-Id: Ie833a8eb247108cb7bcd6ca3e6f3e5df614461cf Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Introduce required properties to QMLFabian Kosmale2019-09-091-2/+15
| | | | | | | | | | | | | | | | | | | [ChangeLog][QtQml] "required" is now a (contextual) keyword in QML, and users can mark properties with it to specify that those properties must be set when the component gets instantiated. This can be done either declaratively via standard property bindings from QML, or imperatively by using the functions to set initial properties (QQmlCompoent::setInitalProperties and related functions in C++, Qt.createObject, Loader.setSource,... in QML/JS). Logic has been added to QQmlComponent::create and the various QQmlIncubator classes to verify that the required properties were set. If properties marked as required are not set, a warning will be printed at runtime, and the component will not be created. Change-Id: I8e38227fc8f173b053b689c1597dc7fd40e835e7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* qqmljs.g: deduplicate rulesFabian Kosmale2019-09-061-76/+32
| | | | | Change-Id: I9b6a9f95b838bbbf015c7619ae3a8828836e4178 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2019-09-051-7/+12
|\ | | | | | | Change-Id: Icc46cb06ac1dbe7097d11bc0db5813eb39fbf758
| * Allow semicolon after property declarationFabian Kosmale2019-09-031-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | Most of the rules already had Semicolon at the end, however it was missing for UiScriptStatement, list properties and UiObjectInitializer. This change fixes the regression from 5.11.3 to 5.12.0, and keeps the behavior consistent. Fixes: QTBUG-77954 Change-Id: I45ef35fab399e3f971444b96d4a9ec6a99e29e09 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | qqmljs.g: reduce number of conflictsFabian Kosmale2019-09-031-34/+37
| | | | | | | | | | | | | | | | | | | | | | | | First, let the lexer create a T_FUNCTION_STAR token for "function *", which makes the job of the parser significantly easier. Then, by using GeneratorDeclaration instead of GeneratorExpression, we can avoid the conflicts between UiObjectMember and PrimaryExpression Change-Id: Ib08918e3977ed1a80cdea0948da80bf37886f7de Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* | qqmljs.g: reduce number of conflictsFabian Kosmale2019-08-291-0/+1
|/ | | | | | | | | | | | | Use right associativity to tell the parser to shift directly when encountering an else statement. This is the wanted behavior, as the "else" should be associated with the last "if" statement. This removes one more shift/reduce conflict in the grammar. See also https://stackoverflow.com/a/12734499 (qlalr behaves like Bison/Yacc here). Change-Id: Id29f00b5a2862fdb3399e4c8a183eda2ed328ba4 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Support top level generator functionsFabian Kosmale2019-07-231-0/+8
| | | | | | | | | | | | | Extends grammar to support generator functions in QML components and adjusts codegen accordingly The corresponding test case must be blacklisted in tst_qmlmin, as qmlmin cannot handle yield statements Fixes: QTBUG-77096 Change-Id: I47d45dd56289cdf073b41932a585259d3052de04 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* QML Grammar: deduplicate semicolon rulesFabian Kosmale2019-07-151-52/+29
| | | | | | | | | | There were quite a few rules which were essentially the same, only differing in whether they matched T_SEMICOLON or T_AUTOMATIC_SEMICOLON By introducing a new rule, we can match both at the same time Change-Id: I46391e310e44ffa8bea03304a9c0726ffc872211 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix parsing of qml signals with multiple new-style type parametersSimon Hausmann2019-07-101-5/+17
| | | | | | | | | | | Amends 0844d1db03410ac88b4ce6b16f68a073b030b248. The modified examples show that the rule of multiple parameters was missing (with the colon) and the single entry colon rule must also come first in order to identify the use correctly. Change-Id: Ic625e2d4b7b0282e6f2289c8be347c36fe81e4c5 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add support for type script QML signal parameter declarationsSimon Hausmann2019-07-091-0/+11
| | | | | | | | | | | | | | | | We support signal(int param) but we should also support signal(param: int) for consistency with the syntax now supported for functions. Change-Id: Ic064bbaac45024d3663562819f3c1f3f4a918a56 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Allow all basic QML types for type annotationsSimon Hausmann2019-07-091-0/+9
| | | | | | | | In particular this permits the JS reserved keywords such as "int" or "double". Change-Id: Ice29e3696d8cba2121ef487cd0b099dd8b082022 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add basic type annotation support for QML functions to the grammarSimon Hausmann2019-07-091-50/+163
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* extend grammar for better version parsing supportFabian Kosmale2019-07-041-5/+34
| | | | | | | | | | | | | | | | | | 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>
* Simplify errors and diagnosticsUlf Hermann2019-06-141-15/+27
| | | | | | | | | | | | | | | | We only need two classes to describe all possible diagnostics: * A low-level private POD DiagnosticMessage. This is easily copied and passed around internally. It doesn't need to adhere to a stable API and it doesn't carry any extra baggage. * The high-level public QQmlError with its stable interface. This can internally also use a DiagnosticMessage as storage. Change-Id: I52be88d9b5d9855a661b8032b01eedb43a0fb0b3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-06-061-0/+45
|\ | | | | | | Change-Id: I59cb196ab17ed8504b33db01d827052eb6891efa
| * Parser: Accept templated readonly propertiesUlf Hermann2019-05-311-0/+45
| | | | | | | | | | | | Change-Id: I37d313e3156a44eb4487b1be007aa93ace18d882 Fixes: QTBUG-76018 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-05-261-4/+0
|\| | | | | | | Change-Id: I208cd36d2b7add94f36e4d86cf0c790a1e4a7e86
| * Don't add local for anonymous function's "name"Ulf Hermann2019-05-211-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | Instead, populate their "name" property directly from the surrounding object pattern if applicable, without adding locals. This fixes some ecmascript tests where functions were assigned to the key "eval" in an object. The JS engine then rejected that because you shouldn't use eval in strict mode. That should be close enough to test for regressions. Fixes: QTBUG-75880 Change-Id: Iacc45a3f7b0eb90cddc6ecf6d2bada616d2cf355 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Eliminate QT_QML_BEGIN_NAMESPACE and QT_QML_END_NAMESPACEShawn Rutledge2019-03-221-4/+4
|/ | | | | | | These are equivalent to the usual namespace macros. Change-Id: I3891397511e29694fe508414e77eb8483b877e03 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Unify the JavaScript parsing recursion checksUlf Hermann2019-03-151-9/+1
| | | | | | | | | | | | | 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>
* QML: Don't crash the parser on certain kinds of bad inputUlf Hermann2019-02-181-2/+6
| | | | | | Fixes: QTBUG-72734 Change-Id: I92146ec517c6a26a67e13830618e137f2a3021c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* JS: Limit expression and statement nesting levelErik Verbruggen2018-11-291-1/+9
| | | | | | | | | This is to prevent extremely deeply nested expressions and statements make the code-generator run out of (native) stack space. Task-number: QTBUG-71087 Change-Id: I8e1a20a361bff3e49101e535754546475a63ca18 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Pass the raw string value to template literalsLars Knoll2018-11-021-2/+17
| | | | | | | | They are required for spec compliance of tagged templates. Change-Id: I8ef8e2314843f07a02d204394400f3f3894f8f91 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* JS: Fix stack buffer overflow in the QML/JS parserLars Knoll2018-10-181-15/+10
| | | | | | Task-number: QTBUG-71083 Change-Id: I7a06a01871c2ae0b3162699189c4e836c36d7759 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Correctly create methods for functions in object literalsLars Knoll2018-08-311-2/+2
| | | | | | | | | | Methods behave slightly different than normal functions as they have a home object and define how super property access is being done. To implement this correctly, we need to create these methods during object initialization time. Change-Id: Ib3f670c8790b882c6472de786938ca4f0b73f66f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix the class name property of default exported classesSimon Hausmann2018-08-161-0/+8
| | | | | Change-Id: I171e571a336a15c27881999a10ffe3c52e92d816 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix the name of anonymous generators and function declarationsSimon Hausmann2018-08-151-5/+12
| | | | | | | | | | | | | | | | | | The spec says in 14.4.12 that an anonymous generator declaration can only occur as part of the export declaration. The same applies to anonymous function declarations in 14.1.20. It is only in the default export declaration rule that we can detect that we have an anonymous declaration/generator, so that is where we implement the step of setting "default" as the function name. It is safe to use an empty string in GeneratorDeclaration_Default and FunctionDeclaration_Default because that rule is only referenced from HoistableDeclaration_Default, which in turn is only referenced from ExportDeclaration. Change-Id: Ibd341b941f67cbcc727da4df23af04af313b6251 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix usage of const in for declarationsSimon Hausmann2018-08-151-0/+2
| | | | | | | | | | | | | | | We correctly produce a syntax error for a const declaration that is without an initialize, such as const x; but we have to make an exception if it's part of a for declaration, such as for (const x of [1, 2, 3]) Change-Id: Iab86d73f2edc1f3deaf62f0f43f8b04789696b65 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Simplify ES module body handlingSimon Hausmann2018-08-141-10/+13
| | | | | | | | | Now that ImportDeclaration and ExportDeclaration are also statements in the AST, we can get rid of the ModuleItemList in the AST. We keep it in the grammar, but map it to a statement list. Change-Id: I4cab29fe9b075e88454fe3b194126f728000856a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix support for default exports in modulesSimon Hausmann2018-08-101-1/+9
| | | | | | | | | | | Default export declarations require a binding setup step at run-time, so we hook it into the ESModule's statement list to make it visible to the code gen visitor. We also reserve local slot zero for the default export. Change-Id: Ie064caad0422b92cfdadbd7d94db72a05e95c0cc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix grammar for ES modulesLars Knoll2018-08-021-1/+3
| | | | | | | | | | | | * Always parse 'import' as a keyword, as it is now one in Qml and ES. * Always parse 'as' as keyword but allow it as identifier using the same trick as for the other keywords. This fixes basic import statements such as import "foo.mjs" as bar but still allows funny variations such as import "foo.mjs" as as. Change-Id: I76a600aab90c1b5c07d079bf11b0a78742d44c53 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix typoLars Knoll2018-08-011-4/+4
| | | | | Change-Id: Iad064b97010548304e37ad6592712d585d2885a3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Smaller grammar cleanupLars Knoll2018-08-011-16/+2
| | | | | Change-Id: Ic0b70e9b2c6f656a8abdf408013201625045ac65 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Simplify parsing of pragma directivesLars Knoll2018-08-011-42/+9
| | | | | | | | We only support 'pragma Singleton' currently, so there is no need to parse the right hand side of pragma as a member expression. Change-Id: Ic0dcbedb52cb58db2fd1cc099f14fd399b7162e3 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Build AST nodes when parsing ES6 modulesSimon Hausmann2018-07-311-1/+244
| | | | | | | | | | | | | This introduces the structures in the AST that allow for the extraction of imports, exports as well as location of tokens. The ModuleItemList as entry point is special with regards to the statements (so not import/export declarations) in the sense that the statement list contained in ModuleItemList::item is not linked yet between different ModuleItemList instances. Change-Id: If553a6ebaf53d5f3cf755c8327d3fe0ea7db68c2 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix naming of classes in class expressionsLars Knoll2018-07-031-0/+16
| | | | | | | | As with function expressions, class expressions also get an implicitly defined name if they are directly assigned to a named variable. Change-Id: I5fda9d74c1c299107f15b82245333b54ca6d8917 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Properly distinguish between class expressions and declarationsLars Knoll2018-06-261-2/+21
| | | | | | | | Introduce both types in the AST, and handle them properly in the code generator. Change-Id: I754ac0976de69009bdb8b203d890e4ec0ad03b30 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix string memory leak in JavaScript ASTSimon Hausmann2018-06-251-8/+8
| | | | | | | | | | | | | Commit 02252ae08d introduced a QString member in a JS memory pool class, which leaks unfortunately as the pool is not designed to call destructors of allocated types. Typically strings in the AST are derived from input and therefore a QStringRef is fine. The bindingIdentifier in the PatterElement however is sometimes synthesized, so a separate storage for dynamically allocated strings in the memory pool allows for using QStringRef again. Change-Id: I94d090df653d784c554452722b3b759031e4735b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix const expressions containing destructuring patternsLars Knoll2018-06-211-1/+0
| | | | | | | | Don't throw a syntax error when encountering a destructuring pattern. Change-Id: I93250a2963d2d50ff61d725229e1b51be17689e9 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix handling of elisions in destructuring expressionsLars Knoll2018-06-211-2/+10
| | | | | | | | We need to iterator over elisions at the end, as those could trigger side effects by calling iterator.next() Change-Id: Ieb5fa3562b6e60fdf179fa228510b2eeaaf9da30 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Fix more test failures for destructuring expressionsLars Knoll2018-06-211-3/+6
| | | | | | | | Fix parsing of var { x = function(){} } = ... Change-Id: I524e39c7a556c392a5359eafc445b59020ccadf2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Correctly set the name of anonymous functions in most casesLars Knoll2018-06-211-0/+6
| | | | | | | | If the anonymous function is bound to an identifier, set the name to the identifier. Change-Id: Idbb3170210e6f91cca3c9bd36b2b6ddcb3a50c7b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Allow a trailing comma in parameter listsLars Knoll2018-06-211-8/+19
| | | | | | | | This got changed in ES8, but let's already take this in now, as there are quite a few tests checking this behavior. Change-Id: I73f86b8fd8a681881bcc9cc3132bef1589d5194f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* The first branch in a ( ? : ) operator can always include the in keywordLars Knoll2018-05-281-1/+1
| | | | | | | Fix the grammar to be compliant with the spec in this case. Change-Id: I5740c9427db6f5c6c2551d4e23f1f14070e497fb Reviewed-by: Robin Burchell <robin.burchell@crimson.no>