From fff130ee6c4b4a06d0f90fa8ed8c3a6c4218035f Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Thu, 10 Nov 2011 16:36:54 +0100 Subject: [PATCH] Fix parsing of unary expressions. Prohibit the lexer to synthesize a semicolon token after the colon-sign of a binding declaration. The parser internally was rewriting the following bindings Component.onCompleted: ++foo as Component.onCompleted: ; ++foo Task-number: QTBUG-21310 Change-Id: I0558d17fd81b5abac81fb990502d49767ea40730 Reviewed-by: Christian Kamm Reviewed-by: Aaron Kennedy --- src/declarative/qml/parser/qdeclarativejslexer.cpp | 5 +++-- .../data/unaryExpression.qml | 9 +++++++++ .../tst_qdeclarativeecmascript.cpp | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/unaryExpression.qml diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp index ba4298d..9b9af38 100644 --- a/src/declarative/qml/parser/qdeclarativejslexer.cpp +++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp @@ -106,7 +106,7 @@ Lexer::Lexer(Engine *engine) , _restrictedKeyword(false) , _terminator(false) , _followsClosingBrace(false) - , _delimited(false) + , _delimited(true) , _qmlMode(true) { if (engine) @@ -156,7 +156,7 @@ void Lexer::setCode(const QString &code, int lineno, bool qmlMode) _restrictedKeyword = false; _terminator = false; _followsClosingBrace = false; - _delimited = false; + _delimited = true; } void Lexer::scanChar() @@ -185,6 +185,7 @@ int Lexer::lex() switch (_tokenKind) { case T_LBRACE: case T_SEMICOLON: + case T_COLON: _delimited = true; break; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/unaryExpression.qml b/tests/auto/declarative/qdeclarativeecmascript/data/unaryExpression.qml new file mode 100644 index 0000000..0d40bec --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/unaryExpression.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + + Component.onCompleted: +++bar + + property int bar: 0 +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 492ed73..11e33be 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -227,6 +227,7 @@ private slots: void revision(); void automaticSemicolon(); + void unaryExpression(); private: static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); @@ -5050,6 +5051,13 @@ void tst_qdeclarativeecmascript::automaticSemicolon() QVERIFY(object != 0); } +void tst_qdeclarativeecmascript::unaryExpression() +{ + QDeclarativeComponent component(&engine, TEST_FILE("unaryExpression.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); +} + // Makes sure that a binding isn't double re-evaluated when it depends on the same variable twice void tst_qdeclarativeecmascript::doubleEvaluate() { -- 1.7.2.5