Skip to content

Commit

Permalink
Fix parsing of unary expressions.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Roberto Raggi authored and Qt by Nokia committed Nov 14, 2011
1 parent 2ad0e19 commit fff130e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/declarative/qml/parser/qdeclarativejslexer.cpp
Expand Up @@ -106,7 +106,7 @@ Lexer::Lexer(Engine *engine)
, _restrictedKeyword(false)
, _terminator(false)
, _followsClosingBrace(false)
, _delimited(false)
, _delimited(true)
, _qmlMode(true)
{
if (engine)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -185,6 +185,7 @@ int Lexer::lex()
switch (_tokenKind) {
case T_LBRACE:
case T_SEMICOLON:
case T_COLON:
_delimited = true;
break;

Expand Down
@@ -0,0 +1,9 @@
import QtQuick 2.0

Item {

Component.onCompleted:
++bar

property int bar: 0
}
Expand Up @@ -227,6 +227,7 @@ private slots:
void revision();

void automaticSemicolon();
void unaryExpression();

private:
static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
Expand Down Expand Up @@ -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()
{
Expand Down

0 comments on commit fff130e

Please sign in to comment.