aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
Commit message (Collapse)AuthorAgeFilesLines
* Correctly create methods for functions in object literalsLars Knoll2018-08-313-2/+5
| | | | | | | | | | 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-152-0/+3
| | | | | | | | | | | | | | | 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>
* Cleanup RegExpObjectLars Knoll2018-08-152-1/+3
| | | | | | | | | | | Move properties from RegExpObject to getters in RegExp.prototype to be compliant with the JS spec. Implement support for the sticky flags ('y') and correctly parse the flags in the RegExp constructor. Change-Id: I5cf05d14e8139cf30d46235b8d466fb96084fcb7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Simplify ES module body handlingSimon Hausmann2018-08-144-99/+16
| | | | | | | | | 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 module dependency handlingSimon Hausmann2018-08-143-26/+13
| | | | | | | | | | | | | | | | | | | | | The evaluation of a module can have side-effects by modifying the global object or objects in it. Therefore even a seemingly empty import such as import "./foo.js" needs to be listed in the module requests. It's also important that they are evaluated in the order of declaration. Therefore we collect all module requests separately - even those that don't have import variables to process. This patch also ensures that the export and import declarations are visited in the correct order, by unifying both AST nodes to be hooked into the statement list. The fact that we connect the module list items into a statement list is solely an artifact of re-using defineFunction() which takes a StatementList as body. Change-Id: I75dc357b2aecfc324d9a9fe66952eff1ec1dfd8a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix multi variable module import listsSimon Hausmann2018-08-141-1/+1
| | | | | | | | Select the correct head when finishing the linked list for ImportList AST nodes. Change-Id: I34ae2ccfd0e969dbd92ce2458de019bb02046aa5 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix support for default exports in modulesSimon Hausmann2018-08-103-12/+31
| | | | | | | | | | | 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>
* Enable unicode regular expressionsLars Knoll2018-08-102-1/+3
| | | | | | | Add support for the 'u' flag for regular expressions. Change-Id: I409054eaa9c50183619752d14f2638f5a38c0ea7 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Add initial basic support for ES6 modulesSimon Hausmann2018-08-092-1/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The entry point from the parsing perspective into modules is not QV4::Script but QV4::ExecutionEngine::compileModule. For convenience, the ESModule AST node gets a body, which is the statement list connected between the ModuleItemList items that are not import/export declarations. The QV4::Module allocates a call context where the exported variables are stored as named locals. This will also become the module namespace object. The imports in turn is an array of value pointers that point into the locals array of the context of the imported modules. The default module loading in ExecutionEngine assumes the accessibility of module urls via QFile (so local file system or resource). This is what qmljs also uses and QJSEngine as well via public API in the future. The test runner compiles the modules manually and injects them, because they need to be compiled together with the test harness code. The QML type loader will the mechanism for injection in the future for module imports from .qml files. Change-Id: I93be9cfe54c651fdbd08c5e1d22d58f47284e54f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix grammar for ES modulesLars Knoll2018-08-023-5/+7
| | | | | | | | | | | | * 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-015-96/+12
| | | | | | | | 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-315-1/+891
| | | | | | | | | | | | | 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>
* Merge remote-tracking branch 'origin/5.11' into devQt Forward Merge Bot2018-07-162-1/+23
|\ | | | | | | | | | | | | | | Conflicts: src/quick/items/qquickloader.cpp tests/auto/quick/qquickanimations/tst_qquickanimations.cpp Change-Id: I0cb9f637d24ccd0ecfb50c455cc210119f744b02
| * Fix conversion of numeric literals in the AST to stringsSimon Hausmann2018-07-132-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | After commit 91f3687ee51db83d9018bd61c3fbc736c6e9912e in qtbase, QString::number includes a zero padding in the exponent that breaks compliance with the ECMAScript tests. Instead of QString::number, we have to use a QLocale instance that turns off the padding of the exponent. Change-Id: Ib8c63bc501cadca026c52359006628f6c271ba6d Task-number: QTBUG-69432 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* | Fix naming of classes in class expressionsLars Knoll2018-07-033-1/+46
| | | | | | | | | | | | | | | | 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-265-2/+49
| | | | | | | | | | | | | | | | 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-254-16/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 array destructuring nested in a rest elementLars Knoll2018-06-211-18/+18
| | | | | | | | | | Change-Id: I3a8c15fe221bff04a3b9b21ed8c0b06c04770a3d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix more issues with destructuringLars Knoll2018-06-212-25/+23
| | | | | | | | | | | | | | | | | | | | Fix destructuring targets that are complex lhs expressions. There are still some failures remaining, but this fixes another larger chunk of test cases. Change-Id: Icf08f42d7c70d4e81be5d5d2e27ebe6249d25467 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix handling of elisions in destructuring expressionsLars Knoll2018-06-213-14/+13
| | | | | | | | | | | | | | | | 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>
* | Fix multi line string literals using backquotesLars Knoll2018-05-261-1/+1
| | | | | | | | | | | | Task-number: QTBUG-67476 Change-Id: Ia8c6863ad35c8a92298e5dffd750d17628200573 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Unify AST for the different 'for' statementsLars Knoll2018-05-115-46/+5
| | | | | | | | | | Change-Id: I70ca83b0ce933d64dad4984a236e48592e989742 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Improve for-in and for-of supportLars Knoll2018-05-112-14/+25
| | | | | | | | | | | | | | | | | | | | | | | | Create a Block scope per iteration as defined in the ES spec. So closures created inside the loop will remember the iteration variable at that loop iteration. Add support for destructuring of the left hand side expression or declaration. Change-Id: Id06ef94e2a4b93646827da4f6ce922eb436e5a31 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Unify ForeachStatement and LocalForeachStatement in the ASTLars Knoll2018-05-115-52/+18
| | | | | | | | | | | | | | | | This saves quite some duplicated code, but requires a bit of care when iterating over the AST. Change-Id: Ic530de4be8b36b4079c9d544b4b77982c3b8be60 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Support destructuring inside catch()Lars Knoll2018-05-113-6/+21
| | | | | | | | | | Change-Id: Ib60b56ac6a7111446e01235564a4cf92ad8ad025 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add some basic support for for-of loopsLars Knoll2018-05-094-13/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | The support is basically at the same level as for for-in at the moment. Currently unimplemented: * Destructuring * Proper lexical scoping * calling iterator.throw()/return() when required Change-Id: If193ce0b054c4315fc16b7e174334a31b2730dcf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add Generator supportLars Knoll2018-05-031-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Add support for ES6 generators. Those are currently always executed in the interpreter (we never JIT them), to simplify the initial implementation. Most functionality, except for 'yield *' expressions are supported. 'yield *' will have to wait until we support for(... of ...) Change-Id: I7c059d1e3b301cbcb79e3746b4bec346738fd426 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Cosmetic cleanupLars Knoll2018-05-031-5/+3
| | | | | | | | | | Change-Id: Idbd34a8c87a52ec78d5680bfab0a75d1430bb0b0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix handling of yield expression in the parserLars Knoll2018-05-031-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | yield is an expression and as such does not have to be followed by a semicolon, so don't require one. This triggered another bug, where we had a conflict between the empty StatementListOpt rule and all other rules that had an ExpressionStatementLookahead (which is also an empty rule). Change-Id: I37a94e534e5b4b6629155ddb4344d6daa2b864ec Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | QmlJS: Do not use realloc for QStringRefOrgad Shaneh2018-05-031-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It has a non-default copy ctor. This is in fact a false positive, since the copy ctor just explicitly copies all the members... Detected by GCC8. qqmljsparser.cpp: In member function ‘void QmlJS::Parser::reallocateStack()’: qqmljsparser.cpp:68:104: warning: ‘void* realloc(void*, size_t)’ moving an object of non-trivially copyable type ‘class QStringRef’; use ‘new’ and ‘delete’ instead [-Wclass-memaccess] Change-Id: Ica88740006374d83f25e20a3af58de524b552ce9 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Fix some parse errorsLars Knoll2018-05-031-3/+3
| | | | | | | | | | | | | | | | The parser was throwing a syntax error on 'function* X() {}' because of a shift-reduce conflict that wasn't properly reported by qlalr. Change-Id: Ifa55a569178e347346d49acd08c702f692e327dd Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Make qqmljs.g accessible in Qt CreatorSimon Hausmann2018-05-021-0/+2
| | | | | | | | | | | | | | | | Adding the grammar back to OTHER_FILES after it was removed with commit 1ea05eb7755e9e39f79ab982afa5c652f755d3e2. Change-Id: Ic291ac70c6d3ba7b68f4167ff993cdfed2c3ef69 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* | Correctly set source location when converting BindingPatternsLars Knoll2018-05-022-1/+2
| | | | | | | | | | Change-Id: I89973ef22fc0eeb67dd3f8219e7b4d6fa02ddaf0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fixup bug in the parser when generating ObjectLiteralsLars Knoll2018-05-021-2/+5
| | | | | | | | | | Change-Id: I0b7979db7aa6c39ff08b7b6cc08dfa635e97846d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Correctly iterate over the base of a TaggedTemplateLars Knoll2018-05-021-0/+1
| | | | | | | | | | Change-Id: I2ff1d238998e752c75e9136c1d392b407ea57fec Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix destructuring of arrow function parametersLars Knoll2018-05-023-31/+54
| | | | | | | | | | Change-Id: I64b49ae77ecd81eafb320cda04a1a7bf4b2dc90c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Properly set names of most anonymous functionsLars Knoll2018-05-023-1/+54
| | | | | | | | | | | | | | | | In ES6, anonymous functions assigned to a variable/property with a known name, inherit the name of that variable/property. Change-Id: I79479b9358b24d610e3e696eb19fe0ec4aee15d1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Support destructuring assignmentsLars Knoll2018-04-274-25/+234
| | | | | | | | | | | | | | | | Not everything works yet, but basic destructuring assignments do. Change-Id: I5f74691fd6458092ecfde9d1a8a802f99fc57b9e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add support for destructuring variable declarationsLars Knoll2018-04-271-1/+0
| | | | | | | | | | Change-Id: Ia7f894fb61cfa760e253963ab4815d98103cfd9b Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Use a PatternElement for VariableDeclarationsLars Knoll2018-04-275-68/+40
| | | | | | | | | | | | | | Required to get proper destructuring working. Change-Id: I99fc20a9f1bace1fe3981d88ce5466f9c8d98245 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Rework the AST for Literals and destructuring expressionsLars Knoll2018-04-275-567/+326
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Array/ObjectLiterals and destructuring expressions are syntactically very similar. In some cases (when using a destructuring expression as the lhs of an assigment), the parser needs to convert the literal into a destructuring expression. To support these, use the same data structures for both in the AST. Those Patterns can be converted with little additional work from a Literal to an AssignmentPattern and be used in all places where we need destructuring in addition to literals. Change-Id: I177599b46eab0f6e8cb2a40c3b3b11ed00a07d6a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>