diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-03-16 19:58:06 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-04-26 21:37:27 +0000 |
commit | a62101f2df57997158f69c2483323287fb018d26 (patch) | |
tree | 592f730de855b6f7c236da34bd5e23de9874015f /src/qml/parser | |
parent | 67ce06f2c0642fa0a9a4eb4f2239cb99a62d2040 (diff) |
Add partial support for computed property names
Computed property names currently work in object literals
and destructuring arguments.
Change-Id: I9dc5bc61b45139ef1836072695ea2fe1ce4994ae
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r-- | src/qml/parser/qqmljs.g | 9 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast.cpp | 10 | ||||
-rw-r--r-- | src/qml/parser/qqmljsast_p.h | 27 | ||||
-rw-r--r-- | src/qml/parser/qqmljsastfwd_p.h | 1 | ||||
-rw-r--r-- | src/qml/parser/qqmljsastvisitor_p.h | 3 |
5 files changed, 47 insertions, 3 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index efa4257aca..87b666b25f 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -1851,8 +1851,13 @@ ReservedIdentifier: T_EXTENDS; ReservedIdentifier: T_EXPORT; ComputedPropertyName: T_LBRACKET AssignmentExpression_In T_RBRACKET; -/. case $rule_number: { UNIMPLEMENTED; } ./ - +/. + case $rule_number: { + AST::ComputedPropertyName *node = new (pool) AST::ComputedPropertyName(sym(2).Expression); + node->propertyNameToken = loc(1); + sym(1).Node = node; + } break; +./ CoverInitializedName: IdentifierReference Initializer_In; diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp index a80b2d422e..b480cdf76c 100644 --- a/src/qml/parser/qqmljsast.cpp +++ b/src/qml/parser/qqmljsast.cpp @@ -1101,6 +1101,16 @@ void ArrayBindingPattern::accept0(Visitor *visitor) visitor->endVisit(this); } +void ComputedPropertyName::accept0(Visitor *visitor) +{ + if (visitor->visit(this)) { + accept(expression, visitor); + } + + visitor->endVisit(this); + +} + } } // namespace QQmlJS::AST QT_QML_END_NAMESPACE diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index 30f6011924..60a3fdf589 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -158,6 +158,7 @@ public: Kind_FunctionExpression, Kind_IdentifierExpression, Kind_IdentifierPropertyName, + Kind_ComputedPropertyName, Kind_IfStatement, Kind_LabelledStatement, Kind_LocalForEachStatement, @@ -752,7 +753,7 @@ public: SourceLocation rbraceToken; }; -class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName +class QML_PARSER_EXPORT IdentifierPropertyName : public PropertyName { public: QQMLJS_DECLARE_AST_NODE(IdentifierPropertyName) @@ -800,6 +801,30 @@ public: double id; }; +class QML_PARSER_EXPORT ComputedPropertyName : public PropertyName +{ +public: + QQMLJS_DECLARE_AST_NODE(ComputedPropertyName) + + ComputedPropertyName(ExpressionNode *expression) + : expression(expression) + { kind = K; } + + void accept0(Visitor *visitor) override; + + QString asString() const override { return QString(); } + + SourceLocation firstSourceLocation() const override + { return expression->firstSourceLocation(); } + + SourceLocation lastSourceLocation() const override + { return expression->lastSourceLocation(); } + +// attributes + ExpressionNode *expression; +}; + + class QML_PARSER_EXPORT ArrayMemberExpression: public ExpressionNode { public: diff --git a/src/qml/parser/qqmljsastfwd_p.h b/src/qml/parser/qqmljsastfwd_p.h index 89245f4884..7766927f8e 100644 --- a/src/qml/parser/qqmljsastfwd_p.h +++ b/src/qml/parser/qqmljsastfwd_p.h @@ -104,6 +104,7 @@ class PropertyName; class IdentifierPropertyName; class StringLiteralPropertyName; class NumericLiteralPropertyName; +class ComputedPropertyName; class ArrayMemberExpression; class FieldMemberExpression; class TaggedTemplate; diff --git a/src/qml/parser/qqmljsastvisitor_p.h b/src/qml/parser/qqmljsastvisitor_p.h index 1c11ee9c02..1e6ce8eaee 100644 --- a/src/qml/parser/qqmljsastvisitor_p.h +++ b/src/qml/parser/qqmljsastvisitor_p.h @@ -167,6 +167,9 @@ public: virtual bool visit(NumericLiteralPropertyName *) { return true; } virtual void endVisit(NumericLiteralPropertyName *) {} + virtual bool visit(ComputedPropertyName *) { return true; } + virtual void endVisit(ComputedPropertyName *) {} + virtual bool visit(ArrayMemberExpression *) { return true; } virtual void endVisit(ArrayMemberExpression *) {} |