-
Notifications
You must be signed in to change notification settings - Fork 27
Conversation
Arrays with non-dicts are not processed by the normalizer thus the error. If the flags children where dictionaries you would have to add ot to the "PromotedPropertyList" setting in the ToNoder object in the driver so flags turns into a full children node of DeclarationLists. But I'm think that worked only for arrays of dicts (nodes). In this case, with the array values being just string, the right solution would be to do it using a ToNode callback in the ToNode object to convert them. Check: https://github.com/bblfsh/php-driver/blob/master/driver/normalizer/tonode.go |
Something like this?
What is your opinion about handling non-node arrays on sdk level? Maybe it should be presented in UAST the same as in original AST? Like:
instead of
|
Could be done, but properties other than locations, internalType and roles are not part of the spec, so they could be lost to code analysis (at least not language specific ones). We could think of a way to incorporate them and do a proposal. |
Hm. Actually from my point of view it looks more like a bug. Consider AST to UAST: looks pretty inconsistent. I updated PR to make it |
I only see now one problem with this PR: the If you've time, could you experiment with this? If not I'll play with this after I finish my current PR. |
It shouldn't break anything. But I'll add some tests tomorrow to prove it. Thanks! P.S. "map[..]" is weird in my opinion too |
Oh. I see why it's I see 2 possible solutions:
func toPropValue(o interface{}) (string, error) {
var v string
t := reflect.TypeOf(o)
switch t.Kind() {
case reflect.Map, reflect.Slice, reflect.Array:
b, err := json.Marshal(v)
if err != nil {
return "", err
}
return string(b), nil
default:
return fmt.Sprint(o), nil
}
}
type PropValue struct {
Value string
Array []PropValue
Map map[string]PropValue
} And provide helpers to receive value. But it will require changing of proto uast consumers. Please share your opinion! (better in separate issue #214) But this PR actually isn't really about how you represent values internally or how do you pass them further. This PR makes consistent input for sdk. Please consider merging it. P.S. I will be happy to send separate PR with change of serialization but it definitely requires more discussion. |
I'm merging, even trough the stringuized format is not very helpful as the linked issue show. |
Thank you! Value of this PR is driver developers don't need to make ugly hack like this: https://github.com/bblfsh/typescript-driver/blob/master/driver/normalizer/tonode.go#L27 just to be compatible with sdk |
Yes, but with regard to creating a driver, remember that something semantically important shouldn't be only represented as a property since then it can't have roles applied and such (I don't know enough typescript to know if that's the case there). |
Example of real AST (typescript):
Now driver always return:
Please, guide me how to fix it if current solution is wrong.
Thanks!