@openrewrite/rewrite 8.69.0-20251205-151742 → 8.69.0-20251205-203346

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.
@@ -0,0 +1,25 @@
1
+ import { JavaScriptVisitor } from "./visitor";
2
+ import { J } from "../java";
3
+ import { Cursor, Tree } from "../tree";
4
+ import { TabsAndIndentsStyle } from "./style";
5
+ export declare class TabsAndIndentsVisitor<P> extends JavaScriptVisitor<P> {
6
+ private readonly tabsAndIndentsStyle;
7
+ private stopAfter?;
8
+ private readonly singleIndent;
9
+ constructor(tabsAndIndentsStyle: TabsAndIndentsStyle, stopAfter?: Tree | undefined);
10
+ protected preVisit(tree: J, _p: P): Promise<J | undefined>;
11
+ private setupCursorMessagesForTree;
12
+ private getParentIndentContext;
13
+ private computeMyIndent;
14
+ private computeIndentKind;
15
+ postVisit(tree: J, _p: P): Promise<J | undefined>;
16
+ private normalizeBlockEnd;
17
+ private normalizeJsxTagEnd;
18
+ visitContainer<T extends J>(container: J.Container<T>, p: P): Promise<J.Container<T>>;
19
+ visitLeftPadded<T extends J | J.Space | number | string | boolean>(left: J.LeftPadded<T>, p: P): Promise<J.LeftPadded<T> | undefined>;
20
+ visit<R extends J>(tree: Tree, p: P, parent?: Cursor): Promise<R | undefined>;
21
+ private setupAncestorIndents;
22
+ private isActualJNode;
23
+ private combineIndent;
24
+ }
25
+ //# sourceMappingURL=tabs-and-indents-visitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tabs-and-indents-visitor.d.ts","sourceRoot":"","sources":["../../src/javascript/tabs-and-indents-visitor.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAS,CAAC,EAAwC,MAAM,SAAS,CAAC;AAEzE,OAAO,EAAC,MAAM,EAAW,IAAI,EAAC,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,SAA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AC,oBAAoB;IA8C5B,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,aAAa;CAIxB"}
@@ -0,0 +1,257 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TabsAndIndentsVisitor = void 0;
13
+ /*
14
+ * Copyright 2025 the original author or authors.
15
+ * <p>
16
+ * Licensed under the Moderne Source Available License (the "License");
17
+ * you may not use this file except in compliance with the License.
18
+ * You may obtain a copy of the License at
19
+ * <p>
20
+ * https://docs.moderne.io/licensing/moderne-source-available-license
21
+ * <p>
22
+ * Unless required by applicable law or agreed to in writing, software
23
+ * distributed under the License is distributed on an "AS IS" BASIS,
24
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
+ * See the License for the specific language governing permissions and
26
+ * limitations under the License.
27
+ */
28
+ const tree_1 = require("./tree");
29
+ const visitor_1 = require("./visitor");
30
+ const java_1 = require("../java");
31
+ const immer_1 = require("immer");
32
+ const tree_2 = require("../tree");
33
+ class TabsAndIndentsVisitor extends visitor_1.JavaScriptVisitor {
34
+ constructor(tabsAndIndentsStyle, stopAfter) {
35
+ super();
36
+ this.tabsAndIndentsStyle = tabsAndIndentsStyle;
37
+ this.stopAfter = stopAfter;
38
+ if (this.tabsAndIndentsStyle.useTabCharacter) {
39
+ this.singleIndent = "\t";
40
+ }
41
+ else {
42
+ this.singleIndent = " ".repeat(this.tabsAndIndentsStyle.indentSize);
43
+ }
44
+ }
45
+ preVisit(tree, _p) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ this.setupCursorMessagesForTree(this.cursor, tree);
48
+ return tree;
49
+ });
50
+ }
51
+ setupCursorMessagesForTree(cursor, tree) {
52
+ const [parentMyIndent, parentIndentKind] = this.getParentIndentContext(cursor);
53
+ const myIndent = this.computeMyIndent(tree, parentMyIndent, parentIndentKind);
54
+ cursor.messages.set("myIndent", myIndent);
55
+ cursor.messages.set("indentKind", this.computeIndentKind(tree));
56
+ }
57
+ getParentIndentContext(cursor) {
58
+ var _a;
59
+ for (let c = cursor.parent; c != null; c = c.parent) {
60
+ const indent = c.messages.get("myIndent");
61
+ if (indent !== undefined) {
62
+ const kind = (_a = c.messages.get("indentKind")) !== null && _a !== void 0 ? _a : 'continuation';
63
+ return [indent, kind];
64
+ }
65
+ }
66
+ return ["", 'continuation'];
67
+ }
68
+ computeMyIndent(tree, parentMyIndent, parentIndentKind) {
69
+ var _a, _b, _c, _d;
70
+ if (tree.kind === java_1.J.Kind.IfElse || parentIndentKind === 'align') {
71
+ return parentMyIndent;
72
+ }
73
+ if (parentIndentKind === 'block') {
74
+ return parentMyIndent + this.singleIndent;
75
+ }
76
+ const hasNewline = ((_b = (_a = tree.prefix) === null || _a === void 0 ? void 0 : _a.whitespace) === null || _b === void 0 ? void 0 : _b.includes("\n")) ||
77
+ ((_d = (_c = tree.prefix) === null || _c === void 0 ? void 0 : _c.comments) === null || _d === void 0 ? void 0 : _d.some(c => c.suffix.includes("\n")));
78
+ return hasNewline ? parentMyIndent + this.singleIndent : parentMyIndent;
79
+ }
80
+ computeIndentKind(tree) {
81
+ switch (tree.kind) {
82
+ case java_1.J.Kind.Block:
83
+ case java_1.J.Kind.Case:
84
+ return 'block';
85
+ case tree_1.JS.Kind.CompilationUnit:
86
+ return 'align';
87
+ default:
88
+ return 'continuation';
89
+ }
90
+ }
91
+ postVisit(tree, _p) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ var _a, _b, _c;
94
+ if (this.stopAfter != null && (0, tree_2.isScope)(this.stopAfter, tree)) {
95
+ (_a = this.cursor) === null || _a === void 0 ? void 0 : _a.root.messages.set("stop", true);
96
+ }
97
+ const myIndent = this.cursor.messages.get("myIndent");
98
+ if (myIndent === undefined) {
99
+ return tree;
100
+ }
101
+ let result = tree;
102
+ if ((_c = (_b = result.prefix) === null || _b === void 0 ? void 0 : _b.whitespace) === null || _c === void 0 ? void 0 : _c.includes("\n")) {
103
+ result = (0, immer_1.produce)(result, draft => {
104
+ draft.prefix.whitespace = this.combineIndent(draft.prefix.whitespace, myIndent);
105
+ });
106
+ }
107
+ if (result.kind === java_1.J.Kind.Block) {
108
+ result = this.normalizeBlockEnd(result, myIndent);
109
+ }
110
+ else if (result.kind === tree_1.JS.Kind.JsxTag) {
111
+ result = this.normalizeJsxTagEnd(result, myIndent);
112
+ }
113
+ return result;
114
+ });
115
+ }
116
+ normalizeBlockEnd(block, myIndent) {
117
+ const effectiveLastWs = (0, java_1.lastWhitespace)(block.end);
118
+ if (!effectiveLastWs.includes("\n")) {
119
+ return block;
120
+ }
121
+ return (0, immer_1.produce)(block, draft => {
122
+ draft.end = (0, java_1.replaceLastWhitespace)(draft.end, ws => this.combineIndent(ws, myIndent));
123
+ });
124
+ }
125
+ normalizeJsxTagEnd(tag, myIndent) {
126
+ if (!tag.children || tag.children.length === 0) {
127
+ return tag;
128
+ }
129
+ const lastChild = tag.children[tag.children.length - 1];
130
+ if (lastChild.kind !== java_1.J.Kind.Literal || !lastChild.prefix.whitespace.includes("\n")) {
131
+ return tag;
132
+ }
133
+ return (0, immer_1.produce)(tag, draft => {
134
+ const lastChildDraft = draft.children[draft.children.length - 1];
135
+ lastChildDraft.prefix.whitespace = this.combineIndent(lastChildDraft.prefix.whitespace, myIndent);
136
+ });
137
+ }
138
+ visitContainer(container, p) {
139
+ const _super = Object.create(null, {
140
+ visitContainer: { get: () => super.visitContainer }
141
+ });
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ var _a;
144
+ const parentIndent = (_a = this.cursor.messages.get("myIndent")) !== null && _a !== void 0 ? _a : "";
145
+ const elementsIndent = container.before.whitespace.includes("\n")
146
+ ? parentIndent + this.singleIndent
147
+ : parentIndent;
148
+ const savedMyIndent = this.cursor.messages.get("myIndent");
149
+ this.cursor.messages.set("myIndent", elementsIndent);
150
+ let ret = yield _super.visitContainer.call(this, container, p);
151
+ if (savedMyIndent !== undefined) {
152
+ this.cursor.messages.set("myIndent", savedMyIndent);
153
+ }
154
+ if (ret.before.whitespace.includes("\n")) {
155
+ ret = (0, immer_1.produce)(ret, draft => {
156
+ draft.before.whitespace = this.combineIndent(draft.before.whitespace, elementsIndent);
157
+ });
158
+ }
159
+ if (ret.elements.length > 0) {
160
+ const effectiveLastWs = (0, java_1.lastWhitespace)(ret.elements[ret.elements.length - 1].after);
161
+ if (effectiveLastWs.includes("\n")) {
162
+ ret = (0, immer_1.produce)(ret, draft => {
163
+ const lastDraft = draft.elements[draft.elements.length - 1];
164
+ lastDraft.after = (0, java_1.replaceLastWhitespace)(lastDraft.after, ws => this.combineIndent(ws, parentIndent));
165
+ });
166
+ }
167
+ }
168
+ return ret;
169
+ });
170
+ }
171
+ visitLeftPadded(left, p) {
172
+ const _super = Object.create(null, {
173
+ visitLeftPadded: { get: () => super.visitLeftPadded }
174
+ });
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ var _a;
177
+ const ret = yield _super.visitLeftPadded.call(this, left, p);
178
+ if (ret === undefined || !ret.before.whitespace.includes("\n")) {
179
+ return ret;
180
+ }
181
+ const parentIndent = (_a = this.cursor.messages.get("myIndent")) !== null && _a !== void 0 ? _a : "";
182
+ return (0, immer_1.produce)(ret, draft => {
183
+ draft.before.whitespace = this.combineIndent(draft.before.whitespace, parentIndent + this.singleIndent);
184
+ });
185
+ });
186
+ }
187
+ visit(tree, p, parent) {
188
+ const _super = Object.create(null, {
189
+ visit: { get: () => super.visit }
190
+ });
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ var _a;
193
+ if (((_a = this.cursor) === null || _a === void 0 ? void 0 : _a.getNearestMessage("stop")) != null) {
194
+ return tree;
195
+ }
196
+ if (parent) {
197
+ this.cursor = new tree_2.Cursor(tree, parent);
198
+ this.setupAncestorIndents();
199
+ }
200
+ return yield _super.visit.call(this, tree, p);
201
+ });
202
+ }
203
+ setupAncestorIndents() {
204
+ const path = [];
205
+ let anchorCursor;
206
+ let anchorIndent = "";
207
+ for (let c = this.cursor.parent; c; c = c.parent) {
208
+ path.push(c);
209
+ const v = c.value;
210
+ if (this.isActualJNode(v) && !anchorCursor && v.prefix) {
211
+ const ws = (0, java_1.lastWhitespace)(v.prefix);
212
+ const idx = ws.lastIndexOf('\n');
213
+ if (idx !== -1) {
214
+ anchorCursor = c;
215
+ anchorIndent = ws.substring(idx + 1);
216
+ }
217
+ }
218
+ if (v.kind === tree_1.JS.Kind.CompilationUnit) {
219
+ if (!anchorCursor) {
220
+ anchorCursor = c;
221
+ anchorIndent = "";
222
+ }
223
+ break;
224
+ }
225
+ }
226
+ if (path.length === 0)
227
+ return;
228
+ path.reverse();
229
+ for (const c of path) {
230
+ const v = c.value;
231
+ if (!this.isActualJNode(v))
232
+ continue;
233
+ const savedCursor = this.cursor;
234
+ this.cursor = c;
235
+ if (c === anchorCursor) {
236
+ c.messages.set("myIndent", anchorIndent);
237
+ c.messages.set("indentKind", this.computeIndentKind(v));
238
+ }
239
+ else {
240
+ this.setupCursorMessagesForTree(c, v);
241
+ }
242
+ this.cursor = savedCursor;
243
+ }
244
+ }
245
+ isActualJNode(v) {
246
+ return ((0, java_1.isJava)(v) || (0, tree_1.isJavaScript)(v)) &&
247
+ v.kind !== java_1.J.Kind.Container &&
248
+ v.kind !== java_1.J.Kind.LeftPadded &&
249
+ v.kind !== java_1.J.Kind.RightPadded;
250
+ }
251
+ combineIndent(oldWs, newIndent) {
252
+ const lastNewline = oldWs.lastIndexOf("\n");
253
+ return oldWs.substring(0, lastNewline + 1) + newIndent;
254
+ }
255
+ }
256
+ exports.TabsAndIndentsVisitor = TabsAndIndentsVisitor;
257
+ //# sourceMappingURL=tabs-and-indents-visitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tabs-and-indents-visitor.js","sourceRoot":"","sources":["../../src/javascript/tabs-and-indents-visitor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,iCAA6C;AAC7C,uCAA4C;AAC5C,kCAAyE;AACzE,iCAA8B;AAC9B,kCAA8C;AAI9C,MAAa,qBAAyB,SAAQ,2BAAoB;IAG9D,YAA6B,mBAAwC,EAAU,SAAgB;QAC3F,KAAK,EAAE,CAAC;QADiB,wBAAmB,GAAnB,mBAAmB,CAAqB;QAAU,cAAS,GAAT,SAAS,CAAO;QAG3F,IAAI,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,CAAC;YAC3C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC7B,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;IAEe,QAAQ,CAAC,IAAO,EAAE,EAAK;;YACnC,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACnD,OAAO,IAAI,CAAC;QAChB,CAAC;KAAA;IAEO,0BAA0B,CAAC,MAAc,EAAE,IAAO;QACtD,MAAM,CAAC,cAAc,EAAE,gBAAgB,CAAC,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC/E,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;QAC9E,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC1C,MAAM,CAAC,QAAQ,CAAC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C,CAAC,CAAC,CAAC;YACjC,CAAC,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,SAAS;YAC3B,CAAC,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,UAAU;YAC5B,CAAC,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,WAAW,CAAC;IACtC,CAAC;IAEO,aAAa,CAAC,KAAa,EAAE,SAAiB;QAClD,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;IAC3D,CAAC;CACJ;AAlOD,sDAkOC"}
package/dist/version.txt CHANGED
@@ -1 +1 @@
1
- 8.69.0-20251205-151742
1
+ 8.69.0-20251205-203346
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrewrite/rewrite",
3
- "version": "8.69.0-20251205-151742",
3
+ "version": "8.69.0-20251205-203346",
4
4
  "license": "Moderne Source Available License",
5
5
  "description": "OpenRewrite JavaScript.",
6
6
  "homepage": "https://github.com/openrewrite/rewrite",
@@ -17,6 +17,37 @@
17
17
  import {J} from "../java";
18
18
  import {produce} from "immer";
19
19
 
20
+ /**
21
+ * Gets the effective last whitespace from a Space.
22
+ * When there are comments, the last whitespace is the suffix of the last comment.
23
+ * When there are no comments, it's the whitespace property.
24
+ */
25
+ export function lastWhitespace(space: J.Space): string {
26
+ if (space.comments.length > 0) {
27
+ return space.comments[space.comments.length - 1].suffix;
28
+ }
29
+ return space.whitespace;
30
+ }
31
+
32
+ /**
33
+ * Replaces the effective last whitespace in a Space using a transform function.
34
+ * When there are comments, updates the suffix of the last comment.
35
+ * When there are no comments, updates the whitespace property.
36
+ *
37
+ * @param space The Space to modify (Immer draft)
38
+ * @param transform Function that receives the current last whitespace and returns the new value
39
+ */
40
+ export function replaceLastWhitespace(space: J.Space, transform: (ws: string) => string): J.Space {
41
+ return produce(space, draft => {
42
+ if (draft.comments.length > 0) {
43
+ const lastComment = draft.comments[draft.comments.length - 1];
44
+ lastComment.suffix = transform(lastComment.suffix);
45
+ } else {
46
+ draft.whitespace = transform(draft.whitespace);
47
+ }
48
+ });
49
+ }
50
+
20
51
  /**
21
52
  * Handles element removal from lists while preserving LST formatting.
22
53
  * Automatically applies prefixes from removed elements to the next kept element,
package/src/java/index.ts CHANGED
@@ -18,5 +18,6 @@ export * from "./tree";
18
18
  export * from "./markers";
19
19
  export * from "./visitor";
20
20
  export * from "./type-visitor";
21
+ export * from "./formatting-utils";
21
22
 
22
23
  import "./print";