Fix parsing of unary expressions.
authorRoberto Raggi <roberto.raggi@nokia.com>
Thu, 10 Nov 2011 15:36:54 +0000 (16:36 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 14 Nov 2011 15:39:25 +0000 (16:39 +0100)
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 <christian.d.kamm@nokia.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/declarative/qml/parser/qdeclarativejslexer.cpp
tests/auto/declarative/qdeclarativeecmascript/data/unaryExpression.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp

index ba4298d..9b9af38 100644 (file)
@@ -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 (file)
index 0000000..0d40bec
--- /dev/null
@@ -0,0 +1,9 @@
+import QtQuick 2.0
+
+Item {
+
+    Component.onCompleted:
+++bar
+
+    property int bar: 0
+}
index 492ed73..11e33be 100644 (file)
@@ -227,6 +227,7 @@ private slots:
     void revision();
 
     void automaticSemicolon();
+    void unaryExpression();
 
 private:
     static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> 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()
 {