Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop qmlobjdef alternative alias #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ function qmlweb_parse($TEXT, document_type, exigent_mode) {
return expr;
}

function qml_is_element(str) {
return str[0].toUpperCase() == str[0];
function qml_is_element(name) {
if (typeof name === "string") {
return name[0].toUpperCase() === name[0];
}
return qml_is_element(name[1]) && name[2][0].toUpperCase() === name[2][0];
}

function qmlblock() {
Expand All @@ -202,16 +205,8 @@ function qmlweb_parse($TEXT, document_type, exigent_mode) {
expect(":");
if (!is("name"))
unexpected();
var objName = S.token.value;
next();
if (is("punc", ".")) {
next();
if (!is("name"))
unexpected();
var propName = S.token.value;
next();
}
return as("qmlaliasdef", name, objName, propName);
statement.in_qmlpropdef = true;
return as_statement("qmlpropdef", name, type);
}
if (is("punc", ":")) {
next();
Expand Down Expand Up @@ -273,24 +268,13 @@ function qmlweb_parse($TEXT, document_type, exigent_mode) {
return qmlsignaldef();
}
} else if (S.token.type == "name") {
var propname = S.token.value;
next();
if (propname == "property" && (S.token.type == "name" || S.token.value == "var")) {
return qmlpropdef();
} else if (is("punc", ".")) { // property statement
// anchors, fonts etc, a.b: statement;
// Can also be Component.onCompleted: ...
// Assume only one subproperty
if (S.token.value == "property" && (S.token.type == "name" || S.token.value == "var")) {
next();
var subname = S.token.value;
next();
/* Check for ModuleQualifier.QMLElement */
if (qml_is_element(subname)) {
return as("qmlelem", propname + "." + subname, undefined, qmlblock());
}
expect(":");
return as_statement("qmlobjdef", propname, subname);
} else if (qml_is_element(propname)) {
return qmlpropdef();
}

var propname = subscripts(as_name(), false);
if (qml_is_element(propname)) {
// Element
var onProp;
if (is("name", "on")) {
Expand Down
5 changes: 5 additions & 0 deletions tests/qml/Alias.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import QtQuick 2.0

Item {
property alias childX: child.x
property alias textFontPointSize: text.font.pointSize

Item {
id: child
x: 125
}

Text {
id: text
}
}
57 changes: 54 additions & 3 deletions tests/qml/Alias.qml.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,42 @@
null,
[
[
"qmlaliasdef",
"qmlpropdef",
"childX",
"child",
"x"
"alias",
[
"stat",
[
"dot",
[
"name",
"child"
],
"x"
]
],
"child.x\n "
],
[
"qmlpropdef",
"textFontPointSize",
"alias",
[
"stat",
[
"dot",
[
"dot",
[
"name",
"text"
],
"font"
],
"pointSize"
]
],
"text.font.pointSize\n\n "
],
[
"qmlelem",
Expand Down Expand Up @@ -50,6 +82,25 @@
"125\n "
]
]
],
[
"qmlelem",
"Text",
null,
[
[
"qmlprop",
"id",
[
"stat",
[
"name",
"text"
]
],
"text\n "
]
]
]
]
]
Expand Down
11 changes: 7 additions & 4 deletions tests/qml/Children.qml.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@
"30\n "
],
[
"qmlobjdef",
"border",
"width",
"qmlprop",
[
"dot",
"border",
"width"
],
[
"stat",
[
Expand All @@ -177,4 +180,4 @@
]
]
]
]
]
File renamed without changes.
99 changes: 99 additions & 0 deletions tests/qml/Drag.qml.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[
"toplevel",
[
[
"qmlimport",
"QtQuick",
2,
"",
true
]
],
[
"qmlelem",
"Rectangle",
null,
[
[
"qmlprop",
"width",
[
"stat",
[
"num",
100
]
],
"100\n "
],
[
"qmlprop",
"height",
[
"stat",
[
"num",
100
]
],
"100\n\n "
],
[
"qmlprop",
[
"dot",
[
"dot",
"Drag",
"hotSpot"
],
"x"
],
[
"stat",
[
"binary",
"/",
[
"name",
"width"
],
[
"num",
2
]
]
],
"width / 2\n "
],
[
"qmlprop",
[
"dot",
[
"dot",
"Drag",
"hotSpot"
],
"y"
],
[
"stat",
[
"binary",
"/",
[
"name",
"height"
],
[
"num",
2
]
]
],
"height / 2\n"
]
]
]
]
8 changes: 6 additions & 2 deletions tests/qml/ImportsNamed.qml.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
],
[
"qmlelem",
"DOM.Div",
[
"dot",
"DOM",
"Div"
],
null,
[]
]
]
]
11 changes: 7 additions & 4 deletions tests/qml/Properties.qml.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
"'green'\n "
],
[
"qmlobjdef",
"border",
"width",
"qmlprop",
[
"dot",
"border",
"width"
],
[
"stat",
[
Expand Down Expand Up @@ -140,4 +143,4 @@
]
]
]
]
]