fix: [Angular] fix logic used for parsing objects provided as input to useObjectWrapper #1490
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is propsed fix to issue: 1410
The logic responsible for parsing an input to the method was incorrect. It used ',' comma as object separator. This gave weird results for any other constructs that would use comma, like arrays. Besides, this logic should probably be used only when input actually has spread operator in it.
Regardless from object detection logic, I'm not convinced if logic responsible for concatenation
${spreadOutObjects.join(', ')}, ${otherObjs.join(', ')}
was correct.spreadOutObjects
collects objects that use spread operator.otherObjs
collect the rest of the objects from input. When we concatenate them using the initial logic, I believe we are completely mixing the order of objects, as there is no guarantee thatspreadOutObjects
in the original input, where at the begining. What if they were spread out somewhere else, in some nested object, of some complicated input? I believe this would either completely malform the object or in best case change the object structure.Now, about the propsed solution. As I understand, the whole purpose of this method is to get rid of
...
spread operator from syntax, as angular won't accept it.I tried to approach this problem in recursive way(to fix initial way of detecting objects - instead of using comma as object separator, try to figure start bracket and end bracket), but it is tricky, as regex are not good with recursive problems and even when I extracted recursion to separate method, it still was tricky for some complicated examples. And then I switched the approach - in the end, why do we need to detect separate objects? Our goal is to get rid of
...
from the string. So we can simply get rid of the...
and then deal with potential consequences:someField: ...someObject
-> remove...
and we are donesomeField: {...someObject}
-> remove...
and we are left with {object} resultsomeField: {...{nestedDeeper: true }}
-> remove...
and we are left with {{ something: true }} resultI believe those cases will cover every possible variations on different levels of nesting. So after removing
...
we just have to cleanup what's left.I prepared the PR using remarks from CONTRIBUTING.md file, however, I noticed that even without my changes there are tests failing in the
core
package(?).