instanceof won’t work because not all layers have the same constructor (can’t remember the exact names, but i think text layers are instanceof TextLayer, shape layers of ShapeLayer, layers with source of AVLayer, etc, something like that, and they also have distinct matchNames).
while (prop.parentProperty) is completely fine.
You could also replace by : while (prop.propertyDepth>0) (that’s what i use, but it’s not better).
For the path itself, i think that for children of a named group, using propertyIndex or matchName makes no difference.
For children of an indexed group, it really depends on the usage of your script, because matchName can’t work (most of the time all children have the same matchName, so it can’t be a reliable identifier), and between the time you identify the property and the time you use the path, the user may have changed its position in the property stack, hence propertyIndex can also be unreliable.
Last tip: you should use try{}catch(){} around the eval, because the property may be gone/invalid.
You could also avoid the use of eval by saving the path as an array of identifiers, not a string, and looping over the array entries to recover the property. Then no need of try/catch.
Hope that helps.
Xavier.