@openrewrite/rewrite 8.108.1 → 8.110.0

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.
@@ -14,13 +14,15 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import {create as produce, Draft} from "mutative";
17
- import {ElementRemovalFormatter, emptySpace, Expression, isIdentifier, isStringLiteral, J, singleSpace, Statement} from "../java";
17
+ import {ElementRemovalFormatter, emptySpace, Expression, isIdentifier, isStringLiteral, J, singleSpace, splitAtLineEnd, Statement} from "../java";
18
18
  import {randomId, UUID} from "../uuid";
19
19
  import {Cursor} from "../tree";
20
20
  import {isObjectBindingPattern, JS, moduleExportName} from "./tree";
21
21
  import {JavaScriptVisitor} from "./visitor";
22
22
  import {resolve, rootName} from "./scope";
23
- import {aliasing, moduleNameOf, movedBinding, newIdentifier, respecify, withMovedTypes, withoutStatement} from "./add-import";
23
+ import {
24
+ aliasing, moduleNameOf, movedBinding, newIdentifier, respecify, sameAttributes, withMovedTypes, withoutStatement
25
+ } from "./add-import";
24
26
  import {sameModule, spelledLike} from "./package-name";
25
27
 
26
28
  /**
@@ -182,7 +184,8 @@ export class RenameMemberSpellings<P> extends JavaScriptVisitor<P> {
182
184
  * export {Old} from "m" → export {New as Old} from "m2"
183
185
  * export {Old, X} from "m" → export {X} from "m"; export {New as Old} from "m2"
184
186
  * export {Old} from "m"; → export {Y, New as Old} from "m2"
185
- * export {Y} from "m2" (joins a re-export of the same kind, `export type` or not)
187
+ * export {Y} from "m2" (joins a re-export of the same kind, `export type` or not,
188
+ * with the same import attributes)
186
189
  *
187
190
  * A comment ending the line (`export {X} from "m"; // note`) stays on it, before the new statement.
188
191
  */
@@ -200,8 +203,11 @@ export class RenameMemberSpellings<P> extends JavaScriptVisitor<P> {
200
203
  }
201
204
  changed = true;
202
205
  const staying = new Set(elements.filter(e => !moving.has(e)));
203
- const target = statements.findIndex((s, j) =>
204
- j !== i && reExportFrom(s.element, this.to.module)?.typeOnly.element === declaration.typeOnly.element);
206
+ const target = statements.findIndex((s, j) => {
207
+ const into = j === i ? undefined : reExportFrom(s.element, this.to.module);
208
+ return into !== undefined && into.typeOnly.element === declaration.typeOnly.element &&
209
+ sameAttributes(into.attributes, declaration.attributes);
210
+ });
205
211
  if (target < 0 && staying.size === 0) {
206
212
  statements[i] = {...statements[i], element: this.respecified(withElements(declaration, elements.map(e => this.renamed(e))))};
207
213
  continue;
@@ -302,25 +308,6 @@ function reExportFrom(statement: J | undefined, module: string): JS.ExportDeclar
302
308
  ? declaration : undefined;
303
309
  }
304
310
 
305
- /**
306
- * The space after a statement, split where its line ends:
307
- * ` // note\n// next` → `line` ` // note`, `rest` `\n// next`. At the end of the file all of it is `line`.
308
- * `undefined` where no comment follows on the same line.
309
- */
310
- function splitAtLineEnd(space: J.Space, endsFile: boolean): {line: J.Space, rest: J.Space} | undefined {
311
- if (space.whitespace.includes("\n") || space.comments.length === 0) {
312
- return undefined;
313
- }
314
- const end = space.comments.findIndex(c => c.suffix.includes("\n"));
315
- if (end < 0) {
316
- return endsFile ? {line: space, rest: {...space, whitespace: "", comments: []}} : undefined;
317
- }
318
- return {
319
- line: {...space, comments: space.comments.slice(0, end + 1)},
320
- rest: {...space, whitespace: space.comments[end].suffix, comments: space.comments.slice(end + 1)}
321
- };
322
- }
323
-
324
311
  function clauseOf(declaration: JS.ExportDeclaration): JS.NamedExports {
325
312
  return declaration.exportClause as JS.NamedExports;
326
313
  }