diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-04-09 17:42:06 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2021-04-13 19:19:56 +0200 |
commit | 5f7ecce23321f499b1b002c32a27c63815535baa (patch) | |
tree | 4e1e23e18cacd4e0d9883fc0f581a77cd3df56e6 /src/qml/parser/qqmljsast_p.h | |
parent | 9b0069d94a5b725923e303ccdb3d7739088e06fc (diff) |
Implement optional chaining
This change implements optional chaining (https://github.com/tc39/proposal-optional-chaining) by adding a new type of optional lookup with an offset to the end of a chain.
If `undefined` or `null` is encountered during an access marked as optional, we jump to that end offset.
Features:
- Full support for all kinds of optional chain
- With some codegen overhead but zero overhead during normal non-optional FieldMemberExpression resolution
- Properly retains this contexts and does not need to resolve anything twice (this has been an issue previously)
- No extra AST structures, just flags for existing ones
[ChangeLog][QtQml] Added support for optional chaining (https://github.com/tc39/proposal-optional-chaining)
Fixes: QTBUG-77926
Change-Id: I9a41cdc4ca272066c79c72b9b22206498a546843
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/parser/qqmljsast_p.h')
-rw-r--r-- | src/qml/parser/qqmljsast_p.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index 6836579209..d32595429e 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -460,6 +460,7 @@ public: ExpressionNode() {} ExpressionNode *expressionCast() override; + bool containsOptionalChain() const; AST::FormalParameterList *reparseAsFormalParameterList(MemoryPool *pool); @@ -1198,6 +1199,7 @@ public: ExpressionNode *expression; SourceLocation lbracketToken; SourceLocation rbracketToken; + bool isOptional = false; }; class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression @@ -1222,6 +1224,7 @@ public: QStringView name; SourceLocation dotToken; SourceLocation identifierToken; + bool isOptional = false; }; class QML_PARSER_EXPORT TaggedTemplate : public LeftHandSideExpression @@ -1314,6 +1317,7 @@ public: ArgumentList *arguments; SourceLocation lparenToken; SourceLocation rparenToken; + bool isOptional = false; }; class QML_PARSER_EXPORT ArgumentList: public Node |