@openrewrite/rewrite 8.68.0-20251127-160522 → 8.68.0-20251127-190342

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AAGtB,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAStE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,OAAO,CAAC;AAGtB,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAYtE"}
package/dist/index.js CHANGED
@@ -62,11 +62,13 @@ function activate(registry) {
62
62
  const { OrderImports } = yield import("./recipe/index.js");
63
63
  const { ModernizeOctalEscapeSequences, ModernizeOctalLiterals, RemoveDuplicateObjectKeys } = yield import("./javascript/migrate/es6/index.js");
64
64
  const { ExportAssignmentToExportDefault } = yield import("./javascript/migrate/typescript/index.js");
65
+ const { UseObjectPropertyShorthand } = yield import("./javascript/cleanup/index.js");
65
66
  registry.register(ExportAssignmentToExportDefault);
66
67
  registry.register(OrderImports);
67
68
  registry.register(ModernizeOctalEscapeSequences);
68
69
  registry.register(ModernizeOctalLiterals);
69
70
  registry.register(RemoveDuplicateObjectKeys);
71
+ registry.register(UseObjectPropertyShorthand);
70
72
  });
71
73
  }
72
74
  rpc_1.RpcCodecs.registerCodec(markers_1.MarkersKind.ParseExceptionResult, {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,4BASC;AA7CD;;;;;;;;;;;;;;GAcG;AACH,+BAA+D;AAC/D,iCAAsD;AACtD,uCAA4D;AAG5D,+CAA6B;AAC7B,8CAA4B;AAC5B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAC1B,2CAAyB;AACzB,gDAA8B;AAC9B,kDAAgC;AAChC,yCAAuB;AACvB,yCAAuB;AACvB,2CAAyB;AACzB,wCAAsB;AAEtB,uCAAuC;AACvC,SAAsB,QAAQ,CAAC,QAAwB;;QACnD,MAAM,EAAC,YAAY,EAAC,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;QACzD,MAAM,EAAC,6BAA6B,EAAE,sBAAsB,EAAE,yBAAyB,EAAC,GAAG,MAAM,MAAM,CAAC,mCAAmC,CAAC,CAAC;QAC7I,MAAM,EAAC,+BAA+B,EAAC,GAAG,MAAM,MA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AAC;YAC5D,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAChD,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAClD,OAAO,IAAA,mBAAW,EAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;KAAA;CACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { UseObjectPropertyShorthand } from "./use-object-property-shorthand";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/javascript/cleanup/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,0BAA0B,EAAC,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 the original author or authors.
4
+ * <p>
5
+ * Licensed under the Moderne Source Available License (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * <p>
9
+ * https://docs.moderne.io/licensing/moderne-source-available-license
10
+ * <p>
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.UseObjectPropertyShorthand = void 0;
19
+ var use_object_property_shorthand_1 = require("./use-object-property-shorthand");
20
+ Object.defineProperty(exports, "UseObjectPropertyShorthand", { enumerable: true, get: function () { return use_object_property_shorthand_1.UseObjectPropertyShorthand; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/javascript/cleanup/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iFAA2E;AAAnE,2IAAA,0BAA0B,OAAA"}
@@ -0,0 +1,22 @@
1
+ import { Recipe } from "../../recipe";
2
+ import { TreeVisitor } from "../../visitor";
3
+ import { ExecutionContext } from "../../execution";
4
+ /**
5
+ * Simplifies object properties where the key and value have the same name,
6
+ * in both destructuring patterns and object literals.
7
+ *
8
+ * Destructuring examples:
9
+ * - `const { x: x } = obj` becomes `const { x } = obj`
10
+ * - `function({ ref: ref, ...props })` becomes `function({ ref, ...props })`
11
+ *
12
+ * Object literal examples:
13
+ * - `{ x: x }` becomes `{ x }`
14
+ * - `{ foo: foo, bar: bar }` becomes `{ foo, bar }`
15
+ */
16
+ export declare class UseObjectPropertyShorthand extends Recipe {
17
+ name: string;
18
+ displayName: string;
19
+ description: string;
20
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
21
+ }
22
+ //# sourceMappingURL=use-object-property-shorthand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-object-property-shorthand.d.ts","sourceRoot":"","sources":["../../../src/javascript/cleanup/use-object-property-shorthand.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAMjD;;;;;;;;;;;GAWG;AACH,qBAAa,0BAA2B,SAAQ,MAAM;IAClD,IAAI,SAAsE;IAC1E,WAAW,SAAmC;IAC9C,WAAW,SAA+L;IAEpM,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAgH9D"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 the original author or authors.
4
+ * <p>
5
+ * Licensed under the Moderne Source Available License (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * <p>
9
+ * https://docs.moderne.io/licensing/moderne-source-available-license
10
+ * <p>
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.UseObjectPropertyShorthand = void 0;
28
+ const recipe_1 = require("../../recipe");
29
+ const visitor_1 = require("../visitor");
30
+ const java_1 = require("../../java");
31
+ const tree_1 = require("../tree");
32
+ const immer_1 = require("immer");
33
+ /**
34
+ * Simplifies object properties where the key and value have the same name,
35
+ * in both destructuring patterns and object literals.
36
+ *
37
+ * Destructuring examples:
38
+ * - `const { x: x } = obj` becomes `const { x } = obj`
39
+ * - `function({ ref: ref, ...props })` becomes `function({ ref, ...props })`
40
+ *
41
+ * Object literal examples:
42
+ * - `{ x: x }` becomes `{ x }`
43
+ * - `{ foo: foo, bar: bar }` becomes `{ foo, bar }`
44
+ */
45
+ class UseObjectPropertyShorthand extends recipe_1.Recipe {
46
+ constructor() {
47
+ super(...arguments);
48
+ this.name = "org.openrewrite.javascript.cleanup.use-object-property-shorthand";
49
+ this.displayName = "Use object property shorthand";
50
+ this.description = "Simplifies object properties where the property name and value/variable name are the same (e.g., `{ x: x }` becomes `{ x }`). Applies to both destructuring patterns and object literals.";
51
+ }
52
+ editor() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ return new class extends visitor_1.JavaScriptVisitor {
55
+ /**
56
+ * Handle object binding patterns (destructuring): const { x: x } = obj
57
+ */
58
+ visitObjectBindingPattern(pattern, p) {
59
+ const _super = Object.create(null, {
60
+ visitObjectBindingPattern: { get: () => super.visitObjectBindingPattern }
61
+ });
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const visited = yield _super.visitObjectBindingPattern.call(this, pattern, p);
64
+ let hasChanges = false;
65
+ const simplifiedBindings = visited.bindings.elements.map(right => {
66
+ var _a, _b;
67
+ const element = right.element;
68
+ if (element.kind === tree_1.JS.Kind.BindingElement) {
69
+ const binding = element;
70
+ if (((_a = binding.propertyName) === null || _a === void 0 ? void 0 : _a.element.kind) === java_1.J.Kind.Identifier) {
71
+ const propName = binding.propertyName.element.simpleName;
72
+ if (((_b = binding.name) === null || _b === void 0 ? void 0 : _b.kind) === java_1.J.Kind.Identifier) {
73
+ const bindingName = binding.name.simpleName;
74
+ if (propName === bindingName) {
75
+ hasChanges = true;
76
+ return Object.assign(Object.assign({}, right), { element: Object.assign(Object.assign({}, binding), { propertyName: undefined, name: Object.assign(Object.assign({}, binding.name), { prefix: binding.propertyName.element.prefix }) }) });
77
+ }
78
+ }
79
+ }
80
+ }
81
+ return right;
82
+ });
83
+ if (!hasChanges) {
84
+ return visited;
85
+ }
86
+ return (0, immer_1.produce)(visited, draft => {
87
+ draft.bindings.elements = simplifiedBindings;
88
+ });
89
+ });
90
+ }
91
+ /**
92
+ * Handle object literals: { x: x }
93
+ * Object literals are represented as J.NewClass with a body containing JS.PropertyAssignment statements.
94
+ */
95
+ visitNewClass(newClass, ctx) {
96
+ const _super = Object.create(null, {
97
+ visitNewClass: { get: () => super.visitNewClass }
98
+ });
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ var _a;
101
+ const visited = yield _super.visitNewClass.call(this, newClass, ctx);
102
+ // Only process object literals (NewClass with body but no class or arguments)
103
+ if (!visited.body || visited.class || (((_a = visited.arguments) === null || _a === void 0 ? void 0 : _a.elements) && visited.arguments.elements.length > 0)) {
104
+ return visited;
105
+ }
106
+ const statements = visited.body.statements;
107
+ if (!statements || statements.length === 0) {
108
+ return visited;
109
+ }
110
+ let hasChanges = false;
111
+ const simplifiedStatements = statements.map(stmt => {
112
+ var _a;
113
+ if (stmt.element.kind === tree_1.JS.Kind.PropertyAssignment) {
114
+ const prop = stmt.element;
115
+ // Check if the property name is an identifier
116
+ if (prop.name.element.kind === java_1.J.Kind.Identifier) {
117
+ const propName = prop.name.element.simpleName;
118
+ // Check if the initializer is also an identifier with the same name
119
+ if (((_a = prop.initializer) === null || _a === void 0 ? void 0 : _a.kind) === java_1.J.Kind.Identifier) {
120
+ const initName = prop.initializer.simpleName;
121
+ if (propName === initName) {
122
+ hasChanges = true;
123
+ // Remove the initializer to use shorthand syntax
124
+ return Object.assign(Object.assign({}, stmt), { element: Object.assign(Object.assign({}, prop), { initializer: undefined }) });
125
+ }
126
+ }
127
+ }
128
+ }
129
+ return stmt;
130
+ });
131
+ if (!hasChanges) {
132
+ return visited;
133
+ }
134
+ return (0, immer_1.produce)(visited, draft => {
135
+ draft.body.statements = simplifiedStatements;
136
+ });
137
+ });
138
+ }
139
+ };
140
+ });
141
+ }
142
+ }
143
+ exports.UseObjectPropertyShorthand = UseObjectPropertyShorthand;
144
+ //# sourceMappingURL=use-object-property-shorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-object-property-shorthand.js","sourceRoot":"","sources":["../../../src/javascript/cleanup/use-object-property-shorthand.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,yCAAoC;AAGpC,wCAA6C;AAC7C,qCAA6B;AAC7B,kCAA2B;AAC3B,iCAA8B;AAE9B;;;;;;;;;;;GAWG;AACH,MAAa,0BAA2B,SAAQ,eAAM;IAAtD;;QACI,SAAI,GAAG,kEAAkE,CAAC;QAC1E,gBAAW,GAAG,+BAA+B,CAAC;QAC9C,gB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AM,QAAQ,GAAI,IAAI,CAAC,IAAI,CAAC,OAAwB,CAAC,UAAU,CAAC;oCAEhE,oEAAoE;oCACpE,IAAI,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,MAAK,QAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;wCAC/C,MAAM,QAAQ,GAAI,IAAI,CAAC,WAA4B,CAAC,UAAU,CAAC;wCAE/D,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;4CACxB,UAAU,GAAG,IAAI,CAAC;4CAClB,iDAAiD;4CACjD,OAAO,gCACA,IAAI,KACP,OAAO,kCACA,IAAI,KACP,WAAW,EAAE,SAAS,MAEW,CAAC;wCAC9C,CAAC;oCACL,CAAC;gCACL,CAAC;4BACL,CAAC;4BAED,OAAO,IAAI,CAAC;wBAChB,CAAC,CAAC,CAAC;wBAEH,IAAI,CAAC,UAAU,EAAE,CAAC;4BACd,OAAO,OAAO,CAAC;wBACnB,CAAC;wBAED,OAAO,IAAA,eAAO,EAAC,OAAO,EAAE,KAAK,CAAC,EAAE;4BAC5B,KAAK,CAAC,IAAK,CAAC,UAAU,GAAG,oBAAoB,CAAC;wBAClD,CAAC,CAAC,CAAC;oBACP,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AArHD,gEAqHC"}
package/dist/version.txt CHANGED
@@ -1 +1 @@
1
- 8.68.0-20251127-160522
1
+ 8.68.0-20251127-190342
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openrewrite/rewrite",
3
- "version": "8.68.0-20251127-160522",
3
+ "version": "8.68.0-20251127-190342",
4
4
  "license": "Moderne Source Available License",
5
5
  "description": "OpenRewrite JavaScript.",
6
6
  "homepage": "https://github.com/openrewrite/rewrite",
package/src/index.ts CHANGED
@@ -38,11 +38,14 @@ export async function activate(registry: RecipeRegistry): Promise<void> {
38
38
  const {OrderImports} = await import("./recipe/index.js");
39
39
  const {ModernizeOctalEscapeSequences, ModernizeOctalLiterals, RemoveDuplicateObjectKeys} = await import("./javascript/migrate/es6/index.js");
40
40
  const {ExportAssignmentToExportDefault} = await import("./javascript/migrate/typescript/index.js");
41
+ const {UseObjectPropertyShorthand} = await import("./javascript/cleanup/index.js");
42
+
41
43
  registry.register(ExportAssignmentToExportDefault);
42
44
  registry.register(OrderImports);
43
45
  registry.register(ModernizeOctalEscapeSequences);
44
46
  registry.register(ModernizeOctalLiterals);
45
47
  registry.register(RemoveDuplicateObjectKeys);
48
+ registry.register(UseObjectPropertyShorthand);
46
49
  }
47
50
 
48
51
  RpcCodecs.registerCodec(MarkersKind.ParseExceptionResult, {
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2025 the original author or authors.
3
+ * <p>
4
+ * Licensed under the Moderne Source Available License (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * <p>
8
+ * https://docs.moderne.io/licensing/moderne-source-available-license
9
+ * <p>
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export {UseObjectPropertyShorthand} from "./use-object-property-shorthand";
@@ -0,0 +1,154 @@
1
+ /*
2
+ * Copyright 2025 the original author or authors.
3
+ * <p>
4
+ * Licensed under the Moderne Source Available License (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * <p>
8
+ * https://docs.moderne.io/licensing/moderne-source-available-license
9
+ * <p>
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {Recipe} from "../../recipe";
18
+ import {TreeVisitor} from "../../visitor";
19
+ import {ExecutionContext} from "../../execution";
20
+ import {JavaScriptVisitor} from "../visitor";
21
+ import {J} from "../../java";
22
+ import {JS} from "../tree";
23
+ import {produce} from "immer";
24
+
25
+ /**
26
+ * Simplifies object properties where the key and value have the same name,
27
+ * in both destructuring patterns and object literals.
28
+ *
29
+ * Destructuring examples:
30
+ * - `const { x: x } = obj` becomes `const { x } = obj`
31
+ * - `function({ ref: ref, ...props })` becomes `function({ ref, ...props })`
32
+ *
33
+ * Object literal examples:
34
+ * - `{ x: x }` becomes `{ x }`
35
+ * - `{ foo: foo, bar: bar }` becomes `{ foo, bar }`
36
+ */
37
+ export class UseObjectPropertyShorthand extends Recipe {
38
+ name = "org.openrewrite.javascript.cleanup.use-object-property-shorthand";
39
+ displayName = "Use object property shorthand";
40
+ description = "Simplifies object properties where the property name and value/variable name are the same (e.g., `{ x: x }` becomes `{ x }`). Applies to both destructuring patterns and object literals.";
41
+
42
+ async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
43
+ return new class extends JavaScriptVisitor<ExecutionContext> {
44
+
45
+ /**
46
+ * Handle object binding patterns (destructuring): const { x: x } = obj
47
+ */
48
+ protected async visitObjectBindingPattern(pattern: JS.ObjectBindingPattern, p: ExecutionContext): Promise<J | undefined> {
49
+ const visited = await super.visitObjectBindingPattern(pattern, p) as JS.ObjectBindingPattern;
50
+
51
+ let hasChanges = false;
52
+
53
+ const simplifiedBindings = visited.bindings.elements.map(right => {
54
+ const element = right.element;
55
+
56
+ if (element.kind === JS.Kind.BindingElement) {
57
+ const binding = element as JS.BindingElement;
58
+
59
+ if (binding.propertyName?.element.kind === J.Kind.Identifier) {
60
+ const propName = (binding.propertyName.element as J.Identifier).simpleName;
61
+
62
+ if (binding.name?.kind === J.Kind.Identifier) {
63
+ const bindingName = (binding.name as J.Identifier).simpleName;
64
+
65
+ if (propName === bindingName) {
66
+ hasChanges = true;
67
+ return {
68
+ ...right,
69
+ element: {
70
+ ...binding,
71
+ propertyName: undefined,
72
+ name: {
73
+ ...binding.name,
74
+ prefix: binding.propertyName.element.prefix
75
+ }
76
+ }
77
+ } as J.RightPadded<JS.BindingElement>;
78
+ }
79
+ }
80
+ }
81
+ }
82
+
83
+ return right;
84
+ });
85
+
86
+ if (!hasChanges) {
87
+ return visited;
88
+ }
89
+
90
+ return produce(visited, draft => {
91
+ draft.bindings.elements = simplifiedBindings;
92
+ });
93
+ }
94
+
95
+ /**
96
+ * Handle object literals: { x: x }
97
+ * Object literals are represented as J.NewClass with a body containing JS.PropertyAssignment statements.
98
+ */
99
+ protected async visitNewClass(newClass: J.NewClass, ctx: ExecutionContext): Promise<J | undefined> {
100
+ const visited = await super.visitNewClass(newClass, ctx) as J.NewClass;
101
+
102
+ // Only process object literals (NewClass with body but no class or arguments)
103
+ if (!visited.body || visited.class || (visited.arguments?.elements && visited.arguments.elements.length > 0)) {
104
+ return visited;
105
+ }
106
+
107
+ const statements = visited.body.statements;
108
+ if (!statements || statements.length === 0) {
109
+ return visited;
110
+ }
111
+
112
+ let hasChanges = false;
113
+
114
+ const simplifiedStatements = statements.map(stmt => {
115
+ if (stmt.element.kind === JS.Kind.PropertyAssignment) {
116
+ const prop = stmt.element as JS.PropertyAssignment;
117
+
118
+ // Check if the property name is an identifier
119
+ if (prop.name.element.kind === J.Kind.Identifier) {
120
+ const propName = (prop.name.element as J.Identifier).simpleName;
121
+
122
+ // Check if the initializer is also an identifier with the same name
123
+ if (prop.initializer?.kind === J.Kind.Identifier) {
124
+ const initName = (prop.initializer as J.Identifier).simpleName;
125
+
126
+ if (propName === initName) {
127
+ hasChanges = true;
128
+ // Remove the initializer to use shorthand syntax
129
+ return {
130
+ ...stmt,
131
+ element: {
132
+ ...prop,
133
+ initializer: undefined
134
+ }
135
+ } as J.RightPadded<JS.PropertyAssignment>;
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ return stmt;
142
+ });
143
+
144
+ if (!hasChanges) {
145
+ return visited;
146
+ }
147
+
148
+ return produce(visited, draft => {
149
+ draft.body!.statements = simplifiedStatements;
150
+ });
151
+ }
152
+ };
153
+ }
154
+ }