Skip to content

Conversation

smacker
Copy link
Collaborator

@smacker smacker commented Aug 5, 2019

Fix: #215

Signed-off-by: Maxim Sukharev max@smacker.ru


This change is Reviewable

//
// for values (strings, ints, bool) we have to keep the wrapping node
// otherwise it's not a tree and uast-viewer wouldn't be able to display it
if (Array.isArray(rootNode.n) && rootNode.n.every(c => c.id)) {
Copy link
Member

Choose a reason for hiding this comment

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

Probably I'm missing something as I don't know much this part, but I don't understand this. In this condition, you're checking that rootNode.n is an array and that each is element has an id property that I guess is a proxy for checking that each element is a node. So this part:

// in case when all the results are nodes we can ignore wrapper node
// and display only results for better UI/UX.

is clear. The part that I don't understand is:

// for values (strings, ints, bool) we have to keep the wrapping node
// otherwise it's not a tree and uast-viewer wouldn't be able to display it

Shouldn't you return rootNode.n if this rootNode.n.every(c => c.id) it's not true?

if (Array.isArray(rootNode.n)) {
    if (rootNode.n.every(c => c.id)) {
        return rootNode.n.map(c => c.id);
    } else {
        return rootNode.n;
    }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this function returns root ids, not nodes.
If all the results are nodes it would return ids of them.
Otherwise, it would return null and default root id (of the wrapper) would be used.

Copy link
Member

Choose a reason for hiding this comment

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

oh ok! Thanks for the explanation!

//
// for values (strings, ints, bool) we have to keep the wrapping node
// otherwise it's not a tree and uast-viewer wouldn't be able to display it
if (Array.isArray(rootNode.n) && rootNode.n.every(c => c.id)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible that c.id is 0, making it false? Would it be safer something like every(c => c.id !== undefined)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, it's not possible. When we transform uast to flat json indexing starts with 1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

applied the suggestion in case the transformer logic would change in the future. 👍

Fix: #215

Signed-off-by: Maxim Sukharev <max@smacker.ru>
@smacker smacker merged commit 73f2105 into bblfsh:master Aug 8, 2019
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.

No UAST is rendered for a valid query
3 participants