(comments []SyntheticComment, object *goja.Object)
| 743 | } |
| 744 | |
| 745 | func (b *Bindings) CommentGojaObject(comments []SyntheticComment, object *goja.Object) (*goja.Object, error) { |
| 746 | if len(comments) == 0 { |
| 747 | return object, nil |
| 748 | } |
| 749 | |
| 750 | commentF, err := b.f("addSyntheticComment") |
| 751 | if err != nil { |
| 752 | return nil, err |
| 753 | } |
| 754 | |
| 755 | // Group all comments that should be included into a JSDoc block. |
| 756 | jsDoc := make([]SyntheticComment, 0) |
| 757 | rest := make([]SyntheticComment, 0) |
| 758 | |
| 759 | for _, c := range comments { |
| 760 | if !c.DoNotFormat && c.Leading && c.SingleLine { |
| 761 | jsDoc = append(jsDoc, c) |
| 762 | continue |
| 763 | } |
| 764 | rest = append(rest, c) |
| 765 | } |
| 766 | |
| 767 | // JSDoc comments should be blocked together |
| 768 | node := object |
| 769 | if len(jsDoc) > 0 { |
| 770 | var jsDocComment strings.Builder |
| 771 | // JSDoc requires '/**' start and ' */' end. The default synthetic comment only places 1 '*'. |
| 772 | // So include the second '*', and start the comment line. |
| 773 | jsDocComment.WriteString("*\n *") |
| 774 | sep := "" |
| 775 | for _, cmt := range jsDoc { |
| 776 | jsDocComment.WriteString(sep) |
| 777 | jsDocComment.WriteString(convertDeprecation(cmt.Text)) |
| 778 | sep = "\n *" |
| 779 | } |
| 780 | jsDocComment.WriteString("\n ") |
| 781 | |
| 782 | res, err := commentF(goja.Undefined(), |
| 783 | node, |
| 784 | b.vm.ToValue(true), |
| 785 | b.vm.ToValue(false), |
| 786 | b.vm.ToValue(jsDocComment.String()), |
| 787 | b.vm.ToValue(true), |
| 788 | ) |
| 789 | if err != nil { |
| 790 | return nil, xerrors.Errorf("call addSyntheticComment for JSDoc: %w", err) |
| 791 | } |
| 792 | node = res.ToObject(b.vm) |
| 793 | } |
| 794 | |
| 795 | for _, c := range rest { |
| 796 | res, err := commentF(goja.Undefined(), |
| 797 | node, |
| 798 | b.vm.ToValue(c.Leading), |
| 799 | b.vm.ToValue(c.SingleLine), |
| 800 | b.vm.ToValue(c.Text), |
| 801 | b.vm.ToValue(c.TrailingNewLine), |
| 802 | ) |
no test coverage detected