Skip to content

Commit 32d30c0

Browse files
Refactoring, rename ObjectBindingDeclarations to ObjectBindingPattern (#5626)
1 parent 5323765 commit 32d30c0

File tree

13 files changed

+110
-110
lines changed

13 files changed

+110
-110
lines changed

rewrite-javascript/rewrite/src/javascript/comparator.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,79 +1151,79 @@ export class JavaScriptComparatorVisitor extends JavaScriptVisitor<J> {
11511151
}
11521152

11531153
/**
1154-
* Overrides the visitObjectBindingDeclarations method to compare object binding declarations.
1154+
* Overrides the visitObjectBindingPattern method to compare object binding declarations.
11551155
*
1156-
* @param objectBindingDeclarations The object binding declarations to visit
1156+
* @param objectBindingPattern The object binding declarations to visit
11571157
* @param other The other object binding declarations to compare with
11581158
* @returns The visited object binding declarations, or undefined if the visit was aborted
11591159
*/
1160-
override async visitObjectBindingDeclarations(objectBindingDeclarations: JS.ObjectBindingDeclarations, other: J): Promise<J | undefined> {
1161-
if (!this.match || other.kind !== JS.Kind.ObjectBindingDeclarations) {
1160+
override async visitObjectBindingPattern(objectBindingPattern: JS.ObjectBindingPattern, other: J): Promise<J | undefined> {
1161+
if (!this.match || other.kind !== JS.Kind.ObjectBindingPattern) {
11621162
this.abort();
1163-
return objectBindingDeclarations;
1163+
return objectBindingPattern;
11641164
}
11651165

1166-
const otherObjectBindingDeclarations = other as JS.ObjectBindingDeclarations;
1166+
const otherObjectBindingPattern = other as JS.ObjectBindingPattern;
11671167

11681168
// Compare leading annotations
1169-
if (objectBindingDeclarations.leadingAnnotations.length !== otherObjectBindingDeclarations.leadingAnnotations.length) {
1169+
if (objectBindingPattern.leadingAnnotations.length !== otherObjectBindingPattern.leadingAnnotations.length) {
11701170
this.abort();
1171-
return objectBindingDeclarations;
1171+
return objectBindingPattern;
11721172
}
11731173

11741174
// Visit leading annotations in lock step
1175-
for (let i = 0; i < objectBindingDeclarations.leadingAnnotations.length; i++) {
1176-
await this.visit(objectBindingDeclarations.leadingAnnotations[i], otherObjectBindingDeclarations.leadingAnnotations[i]);
1177-
if (!this.match) return objectBindingDeclarations;
1175+
for (let i = 0; i < objectBindingPattern.leadingAnnotations.length; i++) {
1176+
await this.visit(objectBindingPattern.leadingAnnotations[i], otherObjectBindingPattern.leadingAnnotations[i]);
1177+
if (!this.match) return objectBindingPattern;
11781178
}
11791179

11801180
// Compare modifiers
1181-
if (objectBindingDeclarations.modifiers.length !== otherObjectBindingDeclarations.modifiers.length) {
1181+
if (objectBindingPattern.modifiers.length !== otherObjectBindingPattern.modifiers.length) {
11821182
this.abort();
1183-
return objectBindingDeclarations;
1183+
return objectBindingPattern;
11841184
}
11851185

11861186
// Visit modifiers in lock step
1187-
for (let i = 0; i < objectBindingDeclarations.modifiers.length; i++) {
1188-
await this.visit(objectBindingDeclarations.modifiers[i], otherObjectBindingDeclarations.modifiers[i]);
1189-
if (!this.match) return objectBindingDeclarations;
1187+
for (let i = 0; i < objectBindingPattern.modifiers.length; i++) {
1188+
await this.visit(objectBindingPattern.modifiers[i], otherObjectBindingPattern.modifiers[i]);
1189+
if (!this.match) return objectBindingPattern;
11901190
}
11911191

11921192
// Compare type expression
1193-
if (!!objectBindingDeclarations.typeExpression !== !!otherObjectBindingDeclarations.typeExpression) {
1193+
if (!!objectBindingPattern.typeExpression !== !!otherObjectBindingPattern.typeExpression) {
11941194
this.abort();
1195-
return objectBindingDeclarations;
1195+
return objectBindingPattern;
11961196
}
11971197

1198-
if (objectBindingDeclarations.typeExpression) {
1199-
await this.visit(objectBindingDeclarations.typeExpression, otherObjectBindingDeclarations.typeExpression!);
1200-
if (!this.match) return objectBindingDeclarations;
1198+
if (objectBindingPattern.typeExpression) {
1199+
await this.visit(objectBindingPattern.typeExpression, otherObjectBindingPattern.typeExpression!);
1200+
if (!this.match) return objectBindingPattern;
12011201
}
12021202

12031203
// Compare bindings
1204-
if (objectBindingDeclarations.bindings.elements.length !== otherObjectBindingDeclarations.bindings.elements.length) {
1204+
if (objectBindingPattern.bindings.elements.length !== otherObjectBindingPattern.bindings.elements.length) {
12051205
this.abort();
1206-
return objectBindingDeclarations;
1206+
return objectBindingPattern;
12071207
}
12081208

12091209
// Visit bindings in lock step
1210-
for (let i = 0; i < objectBindingDeclarations.bindings.elements.length; i++) {
1211-
await this.visit(objectBindingDeclarations.bindings.elements[i].element,
1212-
otherObjectBindingDeclarations.bindings.elements[i].element);
1213-
if (!this.match) return objectBindingDeclarations;
1210+
for (let i = 0; i < objectBindingPattern.bindings.elements.length; i++) {
1211+
await this.visit(objectBindingPattern.bindings.elements[i].element,
1212+
otherObjectBindingPattern.bindings.elements[i].element);
1213+
if (!this.match) return objectBindingPattern;
12141214
}
12151215

12161216
// Compare initializer
1217-
if (!!objectBindingDeclarations.initializer !== !!otherObjectBindingDeclarations.initializer) {
1217+
if (!!objectBindingPattern.initializer !== !!otherObjectBindingPattern.initializer) {
12181218
this.abort();
1219-
return objectBindingDeclarations;
1219+
return objectBindingPattern;
12201220
}
12211221

1222-
if (objectBindingDeclarations.initializer) {
1223-
await this.visit(objectBindingDeclarations.initializer.element, otherObjectBindingDeclarations.initializer!.element);
1222+
if (objectBindingPattern.initializer) {
1223+
await this.visit(objectBindingPattern.initializer.element, otherObjectBindingPattern.initializer!.element);
12241224
}
12251225

1226-
return objectBindingDeclarations;
1226+
return objectBindingPattern;
12271227
}
12281228

12291229
/**

rewrite-javascript/rewrite/src/javascript/parser-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const is_expressions: string[] = [
119119
JS.Kind.MappedType,
120120
JS.Kind.NamedExports,
121121
JS.Kind.NamedImports,
122-
JS.Kind.ObjectBindingDeclarations,
122+
JS.Kind.ObjectBindingPattern,
123123
JS.Kind.SatisfiesExpression,
124124
JS.Kind.TaggedTemplateExpression,
125125
JS.Kind.TemplateExpression,

rewrite-javascript/rewrite/src/javascript/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,9 +1652,9 @@ export class JavaScriptParserVisitor {
16521652
};
16531653
}
16541654

1655-
visitObjectBindingPattern(node: ts.ObjectBindingPattern): JS.ObjectBindingDeclarations {
1655+
visitObjectBindingPattern(node: ts.ObjectBindingPattern): JS.ObjectBindingPattern {
16561656
return {
1657-
kind: JS.Kind.ObjectBindingDeclarations,
1657+
kind: JS.Kind.ObjectBindingPattern,
16581658
id: randomId(),
16591659
prefix: this.prefix(node),
16601660
markers: emptyMarkers,

rewrite-javascript/rewrite/src/javascript/print.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,18 +1094,18 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
10941094
return mappedTypeParameter;
10951095
}
10961096

1097-
override async visitObjectBindingDeclarations(objectBindingDeclarations: JS.ObjectBindingDeclarations, p: PrintOutputCapture): Promise<J | undefined> {
1098-
await this.beforeSyntax(objectBindingDeclarations, p);
1099-
await this.visitNodes(objectBindingDeclarations.leadingAnnotations, p);
1100-
for (const m of objectBindingDeclarations.modifiers) {
1097+
override async visitObjectBindingPattern(objectBindingPattern: JS.ObjectBindingPattern, p: PrintOutputCapture): Promise<J | undefined> {
1098+
await this.beforeSyntax(objectBindingPattern, p);
1099+
await this.visitNodes(objectBindingPattern.leadingAnnotations, p);
1100+
for (const m of objectBindingPattern.modifiers) {
11011101
await this.visitModifier(m, p);
11021102
}
11031103

1104-
objectBindingDeclarations.typeExpression && await this.visit(objectBindingDeclarations.typeExpression, p);
1105-
await this.visitContainerLocal("{", objectBindingDeclarations.bindings, ",", "}", p);
1106-
objectBindingDeclarations.initializer && await this.visitLeftPaddedLocal("=", objectBindingDeclarations.initializer, p);
1107-
await this.afterSyntax(objectBindingDeclarations, p);
1108-
return objectBindingDeclarations;
1104+
objectBindingPattern.typeExpression && await this.visit(objectBindingPattern.typeExpression, p);
1105+
await this.visitContainerLocal("{", objectBindingPattern.bindings, ",", "}", p);
1106+
objectBindingPattern.initializer && await this.visitLeftPaddedLocal("=", objectBindingPattern.initializer, p);
1107+
await this.afterSyntax(objectBindingPattern, p);
1108+
return objectBindingPattern;
11091109
}
11101110

11111111
override async visitTaggedTemplateExpression(taggedTemplateExpression: JS.TaggedTemplateExpression, p: PrintOutputCapture): Promise<J | undefined> {

rewrite-javascript/rewrite/src/javascript/rpc.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ class JavaScriptSender extends JavaScriptVisitor<RpcSendQueue> {
212212
return mappedTypeParameter;
213213
}
214214

215-
override async visitObjectBindingDeclarations(objectBindingDeclarations: JS.ObjectBindingDeclarations, q: RpcSendQueue): Promise<J | undefined> {
216-
await q.getAndSendList(objectBindingDeclarations, el => el.leadingAnnotations, el => el.id, el => this.visit(el, q));
217-
await q.getAndSendList(objectBindingDeclarations, el => el.modifiers, el => el.id, el => this.visit(el, q));
218-
await q.getAndSend(objectBindingDeclarations, el => el.typeExpression, el => this.visit(el, q));
219-
await q.getAndSend(objectBindingDeclarations, el => el.bindings, el => this.visitContainer(el, q));
220-
await q.getAndSend(objectBindingDeclarations, el => el.initializer, el => this.visitLeftPadded(el, q));
221-
return objectBindingDeclarations;
215+
override async visitObjectBindingPattern(objectBindingPattern: JS.ObjectBindingPattern, q: RpcSendQueue): Promise<J | undefined> {
216+
await q.getAndSendList(objectBindingPattern, el => el.leadingAnnotations, el => el.id, el => this.visit(el, q));
217+
await q.getAndSendList(objectBindingPattern, el => el.modifiers, el => el.id, el => this.visit(el, q));
218+
await q.getAndSend(objectBindingPattern, el => el.typeExpression, el => this.visit(el, q));
219+
await q.getAndSend(objectBindingPattern, el => el.bindings, el => this.visitContainer(el, q));
220+
await q.getAndSend(objectBindingPattern, el => el.initializer, el => this.visitLeftPadded(el, q));
221+
return objectBindingPattern;
222222
}
223223

224224
override async visitPropertyAssignment(propertyAssignment: JS.PropertyAssignment, q: RpcSendQueue): Promise<J | undefined> {
@@ -755,8 +755,8 @@ class JavaScriptReceiver extends JavaScriptVisitor<RpcReceiveQueue> {
755755
return finishDraft(draft);
756756
}
757757

758-
override async visitObjectBindingDeclarations(objectBindingDeclarations: JS.ObjectBindingDeclarations, q: RpcReceiveQueue): Promise<J | undefined> {
759-
const draft = createDraft(objectBindingDeclarations);
758+
override async visitObjectBindingPattern(objectBindingPattern: JS.ObjectBindingPattern, q: RpcReceiveQueue): Promise<J | undefined> {
759+
const draft = createDraft(objectBindingPattern);
760760
draft.leadingAnnotations = await q.receiveListDefined(draft.leadingAnnotations, el => this.visitDefined<J.Annotation>(el, q));
761761
draft.modifiers = await q.receiveListDefined(draft.modifiers, el => this.visitDefined<J.Modifier>(el, q));
762762
draft.typeExpression = await q.receive(draft.typeExpression, el => this.visitDefined<TypeTree>(el, q));

rewrite-javascript/rewrite/src/javascript/tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export namespace JS {
7373
NamedExports: "org.openrewrite.javascript.tree.JS$NamedExports",
7474
NamedImports: "org.openrewrite.javascript.tree.JS$NamedImports",
7575
NamespaceDeclaration: "org.openrewrite.javascript.tree.JS$NamespaceDeclaration",
76-
ObjectBindingDeclarations: "org.openrewrite.javascript.tree.JS$ObjectBindingDeclarations",
76+
ObjectBindingPattern: "org.openrewrite.javascript.tree.JS$ObjectBindingPattern",
7777
PropertyAssignment: "org.openrewrite.javascript.tree.JS$PropertyAssignment",
7878
SatisfiesExpression: "org.openrewrite.javascript.tree.JS$SatisfiesExpression",
7979
ScopedVariableDeclarations: "org.openrewrite.javascript.tree.JS$ScopedVariableDeclarations",
@@ -373,8 +373,8 @@ export namespace JS {
373373
* Represents object destructuring patterns.
374374
* @example const { a, b } = obj;
375375
*/
376-
export interface ObjectBindingDeclarations extends JS, Expression, TypedTree, VariableDeclarator {
377-
readonly kind: typeof Kind.ObjectBindingDeclarations;
376+
export interface ObjectBindingPattern extends JS, Expression, TypedTree, VariableDeclarator {
377+
readonly kind: typeof Kind.ObjectBindingPattern;
378378
readonly leadingAnnotations: J.Annotation[];
379379
readonly modifiers: J.Modifier[];
380380
readonly typeExpression?: TypeTree;

rewrite-javascript/rewrite/src/javascript/visitor.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,19 @@ export class JavaScriptVisitor<P> extends JavaVisitor<P> {
400400
});
401401
}
402402

403-
protected async visitObjectBindingDeclarations(objectBindingDeclarations: JS.ObjectBindingDeclarations, p: P): Promise<J | undefined> {
404-
const expression = await this.visitExpression(objectBindingDeclarations, p);
405-
if (!expression?.kind || expression.kind !== JS.Kind.ObjectBindingDeclarations) {
403+
protected async visitObjectBindingPattern(objectBindingPattern: JS.ObjectBindingPattern, p: P): Promise<J | undefined> {
404+
const expression = await this.visitExpression(objectBindingPattern, p);
405+
if (!expression?.kind || expression.kind !== JS.Kind.ObjectBindingPattern) {
406406
return expression;
407407
}
408-
objectBindingDeclarations = expression as JS.ObjectBindingDeclarations;
408+
objectBindingPattern = expression as JS.ObjectBindingPattern;
409409

410-
return this.produceJavaScript<JS.ObjectBindingDeclarations>(objectBindingDeclarations, p, async draft => {
411-
draft.leadingAnnotations = await mapAsync(objectBindingDeclarations.leadingAnnotations, item => this.visitDefined<J.Annotation>(item, p));
412-
draft.modifiers = await mapAsync(objectBindingDeclarations.modifiers, item => this.visitDefined<J.Modifier>(item, p));
413-
draft.typeExpression = objectBindingDeclarations.typeExpression && await this.visitDefined<TypedTree>(objectBindingDeclarations.typeExpression, p);
414-
draft.bindings = await this.visitContainer(objectBindingDeclarations.bindings, p);
415-
draft.initializer = objectBindingDeclarations.initializer && await this.visitLeftPadded(objectBindingDeclarations.initializer, p);
410+
return this.produceJavaScript<JS.ObjectBindingPattern>(objectBindingPattern, p, async draft => {
411+
draft.leadingAnnotations = await mapAsync(objectBindingPattern.leadingAnnotations, item => this.visitDefined<J.Annotation>(item, p));
412+
draft.modifiers = await mapAsync(objectBindingPattern.modifiers, item => this.visitDefined<J.Modifier>(item, p));
413+
draft.typeExpression = objectBindingPattern.typeExpression && await this.visitDefined<TypedTree>(objectBindingPattern.typeExpression, p);
414+
draft.bindings = await this.visitContainer(objectBindingPattern.bindings, p);
415+
draft.initializer = objectBindingPattern.initializer && await this.visitLeftPadded(objectBindingPattern.initializer, p);
416416
});
417417
}
418418

@@ -937,8 +937,8 @@ export class JavaScriptVisitor<P> extends JavaVisitor<P> {
937937
return this.visitKeysRemapping(tree as unknown as JS.MappedType.KeysRemapping, p);
938938
case JS.Kind.MappedTypeParameter:
939939
return this.visitMappedTypeParameter(tree as unknown as JS.MappedType.Parameter, p);
940-
case JS.Kind.ObjectBindingDeclarations:
941-
return this.visitObjectBindingDeclarations(tree as unknown as JS.ObjectBindingDeclarations, p);
940+
case JS.Kind.ObjectBindingPattern:
941+
return this.visitObjectBindingPattern(tree as unknown as JS.ObjectBindingPattern, p);
942942
case JS.Kind.PropertyAssignment:
943943
return this.visitPropertyAssignment(tree as unknown as JS.PropertyAssignment, p);
944944
case JS.Kind.SatisfiesExpression:

rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptIsoVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public J.IntersectionType visitIntersectionType(J.IntersectionType intersectionT
218218
}
219219

220220
@Override
221-
public JS.ObjectBindingDeclarations visitObjectBindingDeclarations(JS.ObjectBindingDeclarations objectBindingDeclarations, P p) {
222-
return (JS.ObjectBindingDeclarations) super.visitObjectBindingDeclarations(objectBindingDeclarations, p);
221+
public JS.ObjectBindingPattern visitObjectBindingPattern(JS.ObjectBindingPattern objectBindingPattern, P p) {
222+
return (JS.ObjectBindingPattern) super.visitObjectBindingPattern(objectBindingPattern, p);
223223
}
224224

225225
@Override

rewrite-javascript/src/main/java/org/openrewrite/javascript/JavaScriptVisitor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,15 @@ public J visitMappedTypeParameter(JS.MappedType.Parameter parameter, P p) {
388388
return m;
389389
}
390390

391-
public J visitObjectBindingDeclarations(JS.ObjectBindingDeclarations objectBindingDeclarations, P p) {
392-
JS.ObjectBindingDeclarations o = objectBindingDeclarations;
391+
public J visitObjectBindingPattern(JS.ObjectBindingPattern objectBindingPattern, P p) {
392+
JS.ObjectBindingPattern o = objectBindingPattern;
393393
o = o.withPrefix(visitSpace(o.getPrefix(), JsSpace.Location.OBJECT_BINDING_DECLARATIONS_PREFIX, p));
394394
o = o.withMarkers(visitMarkers(o.getMarkers(), p));
395395
Expression temp = (Expression) visitExpression(o, p);
396-
if (!(temp instanceof JS.ObjectBindingDeclarations)) {
396+
if (!(temp instanceof JS.ObjectBindingPattern)) {
397397
return temp;
398398
} else {
399-
o = (JS.ObjectBindingDeclarations) temp;
399+
o = (JS.ObjectBindingPattern) temp;
400400
}
401401
o = o.withLeadingAnnotations(requireNonNull(ListUtils.map(o.getLeadingAnnotations(), a -> visitAndCast(a, p))));
402402
o = o.withModifiers(requireNonNull(ListUtils.map(o.getModifiers(), e -> visitAndCast(e, p))));

rewrite-javascript/src/main/java/org/openrewrite/javascript/internal/rpc/JavaScriptReceiver.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ public J visitMappedTypeParameter(JS.MappedType.Parameter mappedTypeParameter, R
247247
}
248248

249249
@Override
250-
public J visitObjectBindingDeclarations(JS.ObjectBindingDeclarations objectBindingDeclarations, RpcReceiveQueue q) {
251-
return objectBindingDeclarations
252-
.withLeadingAnnotations(q.receiveList(objectBindingDeclarations.getLeadingAnnotations(), annot -> (J.Annotation) visitNonNull(annot, q)))
253-
.withModifiers(q.receiveList(objectBindingDeclarations.getModifiers(), mod -> (J.Modifier) visitNonNull(mod, q)))
254-
.withTypeExpression(q.receive(objectBindingDeclarations.getTypeExpression(), tree -> (TypeTree) visitNonNull(tree, q)))
255-
.getPadding().withBindings(q.receive(objectBindingDeclarations.getPadding().getBindings(), el -> visitContainer(el, q)))
256-
.getPadding().withInitializer(q.receive(objectBindingDeclarations.getPadding().getInitializer(), el -> visitLeftPadded(el, q)));
250+
public J visitObjectBindingPattern(JS.ObjectBindingPattern objectBindingPattern, RpcReceiveQueue q) {
251+
return objectBindingPattern
252+
.withLeadingAnnotations(q.receiveList(objectBindingPattern.getLeadingAnnotations(), annot -> (J.Annotation) visitNonNull(annot, q)))
253+
.withModifiers(q.receiveList(objectBindingPattern.getModifiers(), mod -> (J.Modifier) visitNonNull(mod, q)))
254+
.withTypeExpression(q.receive(objectBindingPattern.getTypeExpression(), tree -> (TypeTree) visitNonNull(tree, q)))
255+
.getPadding().withBindings(q.receive(objectBindingPattern.getPadding().getBindings(), el -> visitContainer(el, q)))
256+
.getPadding().withInitializer(q.receive(objectBindingPattern.getPadding().getInitializer(), el -> visitLeftPadded(el, q)));
257257
}
258258

259259
@Override

0 commit comments

Comments
 (0)