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

migrate to using vastly in mavoscript #1003

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

migrate to using vastly in mavoscript #1003

wants to merge 3 commits into from

Conversation

adamjanicki2
Copy link
Collaborator

No description provided.

Copy link

netlify bot commented Dec 5, 2023

Deploy Preview for getmavo ready!

Name Link
🔨 Latest commit f4e7293
🔍 Latest deploy log https://app.netlify.com/sites/getmavo/deploys/65a3fcac97a69600087c9db2
😎 Deploy Preview https://deploy-preview-1003--getmavo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -628,7 +604,7 @@ var _ = Mavo.Script = {
return `${nameSerialized}(${argsSerialized.join(", ")})`;
},
"ConditionalExpression": node => `${_.serialize(node.test, node)}? ${_.serialize(node.consequent, node)} : ${_.serialize(node.alternate, node)}`,
"MemberExpression": (node, parent) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I deleted this because it was an unused variable


if (typeof ret == "object" && ret?.type) {
node = ret;
Vastly.parents.set(node, parent);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I originally wanted to write this function as:

serialize: (node) => {
    Vastly.parents.setAll(node);
    return Vastly.serialize(node);
},

However, due to serializers needing to pass a parent argument back into serialize, we have to do

serialize: (node, parent) => {
    if (parent) {
        Vastly.parents.set(node, parent);
    }
    return Vastly.serialize(node);
},

Copy link
Member

Choose a reason for hiding this comment

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

But is that parent argument used? It seems to be primarily used to set the parent, which we already do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's what I thought too, but it fails the majority of the serialize tests when implented like that, I'm still working on trying to figure out why that's the case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will update once I figure it out

Copy link
Member

Choose a reason for hiding this comment

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

Which tests does it fail?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, so it seems all related to it rewriting Mavo functions to use get() as well, so e.g. instead of $fn.eq() you get $fn.get($fn, "eq"), which happens here. So you need to verify that what you're doing is actually setting parents, cause them not being set properly would be my top guess (or maybe they're not properly set after transformations).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@LeaVerou Coming back to this bug, it seems the root cause is that serializers mutate the node, meaning the parents originally set by vastly are no longer correct, an example is here.

I think having

if (parent) {
        Vastly.parents.set(node, parent);
}

isn't the worst solution, but I'll try to think of a way around it

Copy link
Member

Choose a reason for hiding this comment

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

Note that what a lot of this logic does is trying to find the topmost variable, which you already have a function for!
Then, it's rewriting to prepend with $fn, which seems useful enough in itself that might be worth including in vastly (in a more generic form). E.g. we'll definitely need this for rewriting data variables to branch off $data as well, and for rewriting where calls (to branch off a function call with the possible alternatives). If this is handled by vastly, parents can be adjusted by vastly and calling code doesn't have to care about maintaining parent pointers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll create an issue for it over in vastly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@LeaVerou
Copy link
Member

LeaVerou commented Dec 5, 2023

Nit: The filename should be vastly.global.js not Vastly.global.js

@adamjanicki2
Copy link
Collaborator Author

Going to come back to this now

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

Successfully merging this pull request may close these issues.

None yet

2 participants