(ast, options)
| 111 | |
| 112 | const returnFalse = () => false; |
| 113 | function attachComments(ast, options) { |
| 114 | const { comments } = ast; |
| 115 | delete ast.comments; |
| 116 | |
| 117 | if (!isNonEmptyArray(comments) || !options.printer.canAttachComment) { |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | const tiesToBreak = []; |
| 122 | const { |
| 123 | printer: { |
| 124 | features: { experimental_avoidAstMutation: avoidAstMutation }, |
| 125 | handleComments = {}, |
| 126 | }, |
| 127 | originalText: text, |
| 128 | } = options; |
| 129 | const { |
| 130 | ownLine: handleOwnLineComment = returnFalse, |
| 131 | endOfLine: handleEndOfLineComment = returnFalse, |
| 132 | remaining: handleRemainingComment = returnFalse, |
| 133 | } = handleComments; |
| 134 | |
| 135 | const decoratedComments = comments.map((comment, index) => ({ |
| 136 | ...decorateComment(ast, comment, options), |
| 137 | comment, |
| 138 | text, |
| 139 | options, |
| 140 | ast, |
| 141 | isLastComment: comments.length - 1 === index, |
| 142 | // TODO: Move placement here |
| 143 | placement: undefined, |
| 144 | })); |
| 145 | |
| 146 | // For easier debug, save these to comment even `avoidAstMutation` |
| 147 | const attachPropertiesToComment = |
| 148 | process.env.NODE_ENV !== "production" || !avoidAstMutation; |
| 149 | |
| 150 | for (const [index, context] of decoratedComments.entries()) { |
| 151 | const { |
| 152 | comment, |
| 153 | precedingNode, |
| 154 | enclosingNode, |
| 155 | followingNode, |
| 156 | text, |
| 157 | options, |
| 158 | ast, |
| 159 | isLastComment, |
| 160 | } = context; |
| 161 | |
| 162 | const placement = isOwnLineComment(text, options, decoratedComments, index) |
| 163 | ? "ownLine" |
| 164 | : isEndOfLineComment(text, options, decoratedComments, index) |
| 165 | ? "endOfLine" |
| 166 | : "remaining"; |
| 167 | |
| 168 | let args; |
| 169 | if (avoidAstMutation) { |
| 170 | context.placement = placement; |
no test coverage detected
searching dependent graphs…