@openrewrite/rewrite 8.65.0-20251025-011321 → 8.65.0-20251025-081813
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -98,81 +98,45 @@ function applyRemovedElementPrefix(removedElement, nextElement, preserveRemovedC
|
|
|
98
98
|
}
|
|
99
99
|
const removedPrefix = removedElement.prefix;
|
|
100
100
|
const currentPrefix = nextElement.prefix;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (currentComments.length === 0) {
|
|
104
|
-
if (currentPrefix === removedPrefix) {
|
|
105
|
-
return nextElement;
|
|
106
|
-
}
|
|
107
|
-
// If preserving comments, transfer file header comments and use removed element's whitespace
|
|
108
|
-
if (preserveRemovedComments) {
|
|
109
|
-
const removedComments = removedPrefix.comments || [];
|
|
110
|
-
// Check if removed element has leading comments (not inline trailing comments)
|
|
111
|
-
// These are likely file headers and should be preserved
|
|
112
|
-
const removedWhitespace = removedPrefix.whitespace || '';
|
|
113
|
-
const hasLeadingNewlineBeforeComments = removedComments.length === 0 || /[\r\n]/.test(removedWhitespace);
|
|
114
|
-
// Transfer file header comments from removed element (non-inline comments only)
|
|
115
|
-
const commentsToTransfer = hasLeadingNewlineBeforeComments ? removedComments : [];
|
|
116
|
-
return (0, immer_1.produce)(nextElement, draft => {
|
|
117
|
-
draft.prefix = Object.assign(Object.assign({}, removedPrefix), { comments: commentsToTransfer.length > 0 ? commentsToTransfer : [] });
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
// When not preserving comments, preserve blank lines from the current prefix
|
|
121
|
-
const removedWhitespace = removedPrefix.whitespace || '';
|
|
122
|
-
const currentWhitespace = currentPrefix.whitespace || '';
|
|
123
|
-
const removedNewlines = (removedWhitespace.match(/\r?\n/g) || []).length;
|
|
124
|
-
const currentNewlines = (currentWhitespace.match(/\r?\n/g) || []).length;
|
|
125
|
-
// If the current element has more newlines (i.e., blank lines), preserve them
|
|
126
|
-
if (currentNewlines > removedNewlines) {
|
|
127
|
-
return nextElement;
|
|
128
|
-
}
|
|
129
|
-
// Use removed element's whitespace but don't transfer comments from removed middle elements
|
|
130
|
-
return (0, immer_1.produce)(nextElement, draft => {
|
|
131
|
-
draft.prefix = {
|
|
132
|
-
kind: removedPrefix.kind,
|
|
133
|
-
whitespace: removedWhitespace,
|
|
134
|
-
comments: []
|
|
135
|
-
};
|
|
136
|
-
});
|
|
101
|
+
if (currentPrefix === removedPrefix) {
|
|
102
|
+
return nextElement;
|
|
137
103
|
}
|
|
138
|
-
//
|
|
139
|
-
const
|
|
140
|
-
|
|
104
|
+
// Helper to count newlines in whitespace
|
|
105
|
+
const countNewlines = (ws) => ((ws === null || ws === void 0 ? void 0 : ws.match(/\r?\n/g)) || []).length;
|
|
106
|
+
// Helper to check if whitespace has leading newline (comments are on their own line, not inline)
|
|
107
|
+
const hasLeadingNewline = (ws) => /[\r\n]/.test(ws || '');
|
|
108
|
+
const removedWs = removedPrefix.whitespace || '';
|
|
109
|
+
const currentWs = currentPrefix.whitespace || '';
|
|
110
|
+
const removedComments = removedPrefix.comments || [];
|
|
111
|
+
const currentComments = currentPrefix.comments || [];
|
|
112
|
+
// Filter out inline trailing line comments from current element
|
|
141
113
|
let commentsToKeep = currentComments;
|
|
142
|
-
|
|
143
|
-
if (currentComments.length > 0) {
|
|
114
|
+
if (currentComments.length > 0 && !hasLeadingNewline(currentWs)) {
|
|
144
115
|
const firstComment = currentComments[0];
|
|
145
116
|
const commentText = firstComment.text || firstComment.message || '';
|
|
146
117
|
const isLineComment = commentText.includes('//') || firstComment.multiline === false;
|
|
147
|
-
if (isLineComment
|
|
148
|
-
// Only remove comments that are truly inline (no newline before them)
|
|
149
|
-
// Comments on their own line (with leading newline) are preserved as they're
|
|
150
|
-
// likely leading comments for the next element, not trailing comments from removed element
|
|
118
|
+
if (isLineComment) {
|
|
151
119
|
commentsToKeep = currentComments.slice(1);
|
|
152
120
|
}
|
|
153
121
|
}
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
|
|
159
|
-
const hasLeadingComments = removedComments.length === 0 || /[\r\n]/.test(removedWhitespace);
|
|
160
|
-
// Combine leading comments from removed element with filtered comments from current element
|
|
161
|
-
const allComments = hasLeadingComments ? [...removedComments, ...commentsToKeep] : commentsToKeep;
|
|
162
|
-
// When preserving comments, always use the removed element's whitespace
|
|
163
|
-
return (0, immer_1.produce)(nextElement, draft => {
|
|
164
|
-
draft.prefix = Object.assign(Object.assign({}, removedPrefix), { comments: allComments.length > 0 ? allComments : [] });
|
|
165
|
-
});
|
|
122
|
+
// Determine which comments to include in final prefix
|
|
123
|
+
let finalComments;
|
|
124
|
+
if (preserveRemovedComments && hasLeadingNewline(removedWs)) {
|
|
125
|
+
// Transfer leading comments from removed element
|
|
126
|
+
finalComments = [...removedComments, ...commentsToKeep];
|
|
166
127
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return (0, immer_1.produce)(nextElement, draft => {
|
|
170
|
-
draft.prefix = Object.assign(Object.assign({}, removedPrefix), { comments: commentsToKeep });
|
|
171
|
-
});
|
|
128
|
+
else {
|
|
129
|
+
finalComments = commentsToKeep;
|
|
172
130
|
}
|
|
173
|
-
//
|
|
131
|
+
// Determine which whitespace to use: preserve current if it has more blank lines
|
|
132
|
+
const shouldPreserveCurrentWhitespace = !preserveRemovedComments &&
|
|
133
|
+
countNewlines(currentWs) > countNewlines(removedWs);
|
|
174
134
|
return (0, immer_1.produce)(nextElement, draft => {
|
|
175
|
-
draft.prefix =
|
|
135
|
+
draft.prefix = {
|
|
136
|
+
kind: shouldPreserveCurrentWhitespace ? currentPrefix.kind : removedPrefix.kind,
|
|
137
|
+
whitespace: shouldPreserveCurrentWhitespace ? currentWs : removedWs,
|
|
138
|
+
comments: finalComments.length > 0 ? finalComments : []
|
|
139
|
+
};
|
|
176
140
|
});
|
|
177
141
|
}
|
|
178
142
|
//# sourceMappingURL=formatting-utils.js.map
|
|
@@ -1 +1 @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,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,SAAS,KAAK,KAAK,CAAC;QACrF,IAAI,aAAa,EAAE,CAAC;YAChB,cAAc,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC;IAED,sDAAsD;IACtD,IAAI,aAAoB,CAAC;IACzB,IAAI,uBAAuB,IAAI,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1D,iDAAiD;QACjD,aAAa,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,cAAc,CAAC,CAAC;IAC5D,CAAC;SAAM,CAAC;QACJ,aAAa,GAAG,cAAc,CAAC;IACnC,CAAC;IAED,iFAAiF;IACjF,MAAM,+BAA+B,GACjC,CAAC,uBAAuB;QACxB,aAAa,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAExD,OAAO,IAAA,eAAO,EAAC,WAAW,EAAE,KAAK,CAAC,EAAE;QAChC,KAAK,CAAC,MAAM,GAAG;YACX,IAAI,EAAE,+BAA+B,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI;YAC/E,UAAU,EAAE,+BAA+B,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;YACnE,QAAQ,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE;SAC1D,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
8.65.0-20251025-
|
|
1
|
+
8.65.0-20251025-081409
|
package/package.json
CHANGED
|
@@ -102,107 +102,52 @@ function applyRemovedElementPrefix<T extends J>(removedElement: J, nextElement:
|
|
|
102
102
|
|
|
103
103
|
const removedPrefix = removedElement.prefix;
|
|
104
104
|
const currentPrefix = nextElement.prefix;
|
|
105
|
-
const currentComments = currentPrefix.comments || [];
|
|
106
|
-
|
|
107
|
-
// If the next element has no comments, apply appropriate formatting
|
|
108
|
-
if (currentComments.length === 0) {
|
|
109
|
-
if (currentPrefix === removedPrefix) {
|
|
110
|
-
return nextElement;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// If preserving comments, transfer file header comments and use removed element's whitespace
|
|
114
|
-
if (preserveRemovedComments) {
|
|
115
|
-
const removedComments = removedPrefix.comments || [];
|
|
116
|
-
|
|
117
|
-
// Check if removed element has leading comments (not inline trailing comments)
|
|
118
|
-
// These are likely file headers and should be preserved
|
|
119
|
-
const removedWhitespace = removedPrefix.whitespace || '';
|
|
120
|
-
const hasLeadingNewlineBeforeComments = removedComments.length === 0 || /[\r\n]/.test(removedWhitespace);
|
|
121
105
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return produce(nextElement, draft => {
|
|
126
|
-
draft.prefix = {
|
|
127
|
-
...removedPrefix,
|
|
128
|
-
comments: commentsToTransfer.length > 0 ? commentsToTransfer : []
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
}
|
|
106
|
+
if (currentPrefix === removedPrefix) {
|
|
107
|
+
return nextElement;
|
|
108
|
+
}
|
|
132
109
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const currentWhitespace = currentPrefix.whitespace || '';
|
|
136
|
-
const removedNewlines = (removedWhitespace.match(/\r?\n/g) || []).length;
|
|
137
|
-
const currentNewlines = (currentWhitespace.match(/\r?\n/g) || []).length;
|
|
110
|
+
// Helper to count newlines in whitespace
|
|
111
|
+
const countNewlines = (ws: string | undefined) => (ws?.match(/\r?\n/g) || []).length;
|
|
138
112
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return nextElement;
|
|
142
|
-
}
|
|
113
|
+
// Helper to check if whitespace has leading newline (comments are on their own line, not inline)
|
|
114
|
+
const hasLeadingNewline = (ws: string | undefined) => /[\r\n]/.test(ws || '');
|
|
143
115
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
whitespace: removedWhitespace,
|
|
149
|
-
comments: []
|
|
150
|
-
};
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// The next element has comments - check if we need to remove inline/trailing line comments
|
|
155
|
-
const currentWhitespace = currentPrefix.whitespace || '';
|
|
156
|
-
const hasLeadingNewline = /[\r\n]/.test(currentWhitespace);
|
|
116
|
+
const removedWs = removedPrefix.whitespace || '';
|
|
117
|
+
const currentWs = currentPrefix.whitespace || '';
|
|
118
|
+
const removedComments = removedPrefix.comments || [];
|
|
119
|
+
const currentComments = currentPrefix.comments || [];
|
|
157
120
|
|
|
121
|
+
// Filter out inline trailing line comments from current element
|
|
158
122
|
let commentsToKeep = currentComments;
|
|
159
|
-
|
|
160
|
-
// Check for truly inline trailing line comments that should be removed
|
|
161
|
-
if (currentComments.length > 0) {
|
|
123
|
+
if (currentComments.length > 0 && !hasLeadingNewline(currentWs)) {
|
|
162
124
|
const firstComment: any = currentComments[0];
|
|
163
125
|
const commentText = firstComment.text || firstComment.message || '';
|
|
164
126
|
const isLineComment = commentText.includes('//') || firstComment.multiline === false;
|
|
165
|
-
|
|
166
|
-
if (isLineComment && !hasLeadingNewline) {
|
|
167
|
-
// Only remove comments that are truly inline (no newline before them)
|
|
168
|
-
// Comments on their own line (with leading newline) are preserved as they're
|
|
169
|
-
// likely leading comments for the next element, not trailing comments from removed element
|
|
127
|
+
if (isLineComment) {
|
|
170
128
|
commentsToKeep = currentComments.slice(1);
|
|
171
129
|
}
|
|
172
130
|
}
|
|
173
131
|
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
// Combine leading comments from removed element with filtered comments from current element
|
|
183
|
-
const allComments = hasLeadingComments ? [...removedComments, ...commentsToKeep] : commentsToKeep;
|
|
184
|
-
|
|
185
|
-
// When preserving comments, always use the removed element's whitespace
|
|
186
|
-
return produce(nextElement, draft => {
|
|
187
|
-
draft.prefix = {
|
|
188
|
-
...removedPrefix,
|
|
189
|
-
comments: allComments.length > 0 ? allComments : []
|
|
190
|
-
};
|
|
191
|
-
});
|
|
132
|
+
// Determine which comments to include in final prefix
|
|
133
|
+
let finalComments: any[];
|
|
134
|
+
if (preserveRemovedComments && hasLeadingNewline(removedWs)) {
|
|
135
|
+
// Transfer leading comments from removed element
|
|
136
|
+
finalComments = [...removedComments, ...commentsToKeep];
|
|
137
|
+
} else {
|
|
138
|
+
finalComments = commentsToKeep;
|
|
192
139
|
}
|
|
193
140
|
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
...removedPrefix,
|
|
199
|
-
comments: commentsToKeep
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
}
|
|
141
|
+
// Determine which whitespace to use: preserve current if it has more blank lines
|
|
142
|
+
const shouldPreserveCurrentWhitespace =
|
|
143
|
+
!preserveRemovedComments &&
|
|
144
|
+
countNewlines(currentWs) > countNewlines(removedWs);
|
|
203
145
|
|
|
204
|
-
// No comments left after filtering, use removed element's prefix entirely
|
|
205
146
|
return produce(nextElement, draft => {
|
|
206
|
-
draft.prefix =
|
|
147
|
+
draft.prefix = {
|
|
148
|
+
kind: shouldPreserveCurrentWhitespace ? currentPrefix.kind : removedPrefix.kind,
|
|
149
|
+
whitespace: shouldPreserveCurrentWhitespace ? currentWs : removedWs,
|
|
150
|
+
comments: finalComments.length > 0 ? finalComments : []
|
|
151
|
+
};
|
|
207
152
|
});
|
|
208
153
|
}
|