Make use of array helper functions#16226
Conversation
| } | ||
| return result; | ||
| } | ||
| return flatMap(getJSDocs(node), doc => |
There was a problem hiding this comment.
This isn't exactly identical to before since we now check for SyntaxKind.JSDocComment instead of SyntaxKind.JSDocParameterTag. I think it makes more sense this way though, since the cast doc as JSDoc isn't valid if all we know is that it's not an @param tag. @sandersn
There was a problem hiding this comment.
If the tests pass then this is a good change. I tried writing it with flatMap originally but other parts of the implementation didn't work, and I forgot to change it back afterward.
I still think it's weird that the return type of mapfn is U | U[] though.
| if (!destEmitNode) destEmitNode = {}; | ||
| if (leadingComments) destEmitNode.leadingComments = addRange(leadingComments.slice(), destEmitNode.leadingComments); | ||
| if (trailingComments) destEmitNode.trailingComments = addRange(trailingComments.slice(), destEmitNode.trailingComments); | ||
| if (leadingComments) destEmitNode.leadingComments = concatenate(leadingComments, destEmitNode.leadingComments); |
There was a problem hiding this comment.
The reason I used slice was I always wanted to be sure leadingComments and trailingComments were unique arrays on an emit node, in case they are modified later. Now it is possible for someone to change the leading/trailing comments of a cloned node and it will affect the leading/trailing comments of the source node (though its not a likely scenario).
There was a problem hiding this comment.
That interface is internal, but it does look like .leadingComments is potentially mutable due to addSyntheticLeadingComment.
No description provided.