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

Initial support for accessing attached properties in-scope. #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stephenmdangelo
Copy link
Member

This is to help support: qmlweb/qmlweb#297

Lots of tests fail, but I'm pretty sure that's just because all of the source is regenerated (though I believe still functionally equivalent). QmlWeb tests that fail are any that reference things like Qt and Imported, as there is no $QmlWebGetAttachedObject defined.

I'm mostly interested in any comments about this approach in general. It's currently including a copy of UglifyJS's process.js, with all of the node require/export stuff removed (I couldn't sort out a nice way to put that into replacements.js).

@@ -117,6 +117,24 @@ function qmlweb_parse($TEXT, document_type, exigent_mode) {
token_error(S.token, "Unexpected token " + S.token.type + " " + S.token.val + ", expected " + type + " " + val);
};

function qml_get_attached_object(type, val) {
if (type === "name" && qml_is_element(val)) {
return "$QmlWebGetAttachedObject('" + val + "')";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be on the parser side. Parser should just provide a consumable AST.

@ChALkeR
Copy link
Member

ChALkeR commented Aug 11, 2016

This adds a code generator to rebuild js functions code, correct?

I am not sure this is the correct way (or even the repo) for that. I will need to think about this a bit. The initial plan was to have a codegen separately, but this in fact does relate to the parser, not a complete codegen.

Could you also link me to an example why this is needed?

@stephenmdangelo
Copy link
Member Author

This adds a code generator to rebuild js functions code, correct?

Yes, it takes the one from UglifyJS.

I am not sure this is the correct way (or even the repo) for that. I will need to think about this a bit. The initial plan was to have a codegen separately, but this in fact does relate to the parser, not a complete codegen.

Yeah, it's admittedly a hack (I don't even know if I can make this entirely transparent to completely arbitrary JS code that references capitalized variables). I'd love to hear some other ideas of how this could be done. I feel like we could make a babel plugin or something, but that would likely force the use of gulp-qmlweb, removing the ability to serve up QML files directly (or use Qt.createQmlObject, all the stuff being discussed in qmlweb/qmlweb#303).

Could you also link me to an example why this is needed?

Here is an example of why this is required: https://github.com/stephenmdangelo/playground/tree/master/qml/scoped_attached_properties

I'm less interested in being able to support qualified imports of QtQuick, but for custom attached properties (e.g. I'd like to add a custom attached property for QmlWeb that allows one to add CSS classes to an element. I've hacked that together for my own purposes via objectName).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants