@openrewrite/rewrite 8.68.0-20251127-160522 → 8.68.0-20251127-184755
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.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/javascript/cleanup/index.d.ts +2 -0
- package/dist/javascript/cleanup/index.d.ts.map +1 -0
- package/dist/javascript/cleanup/index.js +21 -0
- package/dist/javascript/cleanup/index.js.map +1 -0
- package/dist/javascript/cleanup/simplify-object-binding-properties.d.ts +18 -0
- package/dist/javascript/cleanup/simplify-object-binding-properties.d.ts.map +1 -0
- package/dist/javascript/cleanup/simplify-object-binding-properties.js +97 -0
- package/dist/javascript/cleanup/simplify-object-binding-properties.js.map +1 -0
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/javascript/cleanup/index.ts +17 -0
- package/src/javascript/cleanup/simplify-object-binding-properties.ts +96 -0
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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 { SimplifyObjectBindingProperties } = 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(SimplifyObjectBindingProperties);
|
|
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":"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@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/javascript/cleanup/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,+BAA+B,EAAC,MAAM,sCAAsC,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.SimplifyObjectBindingProperties = void 0;
|
|
19
|
+
var simplify_object_binding_properties_1 = require("./simplify-object-binding-properties");
|
|
20
|
+
Object.defineProperty(exports, "SimplifyObjectBindingProperties", { enumerable: true, get: function () { return simplify_object_binding_properties_1.SimplifyObjectBindingProperties; } });
|
|
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,2FAAqF;AAA7E,qJAAA,+BAA+B,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Recipe } from "../../recipe";
|
|
2
|
+
import { TreeVisitor } from "../../visitor";
|
|
3
|
+
import { ExecutionContext } from "../../execution";
|
|
4
|
+
/**
|
|
5
|
+
* Simplifies object binding properties where the key and value have the same name.
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* - `{ x: x }` becomes `{ x }`
|
|
9
|
+
* - `{ ref: ref, ...props }` becomes `{ ref, ...props }`
|
|
10
|
+
* - `{ foo: foo, bar: bar }` becomes `{ foo, bar }`
|
|
11
|
+
*/
|
|
12
|
+
export declare class SimplifyObjectBindingProperties extends Recipe {
|
|
13
|
+
name: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
description: string;
|
|
16
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=simplify-object-binding-properties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-object-binding-properties.d.ts","sourceRoot":"","sources":["../../../src/javascript/cleanup/simplify-object-binding-properties.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;;;;;;;GAOG;AACH,qBAAa,+BAAgC,SAAQ,MAAM;IACvD,IAAI,SAA2E;IAC/E,WAAW,SAAwC;IACnD,WAAW,SAAyI;IAE9I,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA0D9D"}
|
|
@@ -0,0 +1,97 @@
|
|
|
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.SimplifyObjectBindingProperties = 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 binding properties where the key and value have the same name.
|
|
35
|
+
*
|
|
36
|
+
* Examples:
|
|
37
|
+
* - `{ x: x }` becomes `{ x }`
|
|
38
|
+
* - `{ ref: ref, ...props }` becomes `{ ref, ...props }`
|
|
39
|
+
* - `{ foo: foo, bar: bar }` becomes `{ foo, bar }`
|
|
40
|
+
*/
|
|
41
|
+
class SimplifyObjectBindingProperties extends recipe_1.Recipe {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.name = "org.openrewrite.javascript.cleanup.simplify-object-binding-properties";
|
|
45
|
+
this.displayName = "Simplify object binding properties";
|
|
46
|
+
this.description = "Simplifies object destructuring patterns where the property name and variable name are the same (e.g., `{ x: x }` becomes `{ x }`).";
|
|
47
|
+
}
|
|
48
|
+
editor() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return new class extends visitor_1.JavaScriptVisitor {
|
|
51
|
+
visitObjectBindingPattern(pattern, p) {
|
|
52
|
+
const _super = Object.create(null, {
|
|
53
|
+
visitObjectBindingPattern: { get: () => super.visitObjectBindingPattern }
|
|
54
|
+
});
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
// First, recursively visit children
|
|
57
|
+
const visited = yield _super.visitObjectBindingPattern.call(this, pattern, p);
|
|
58
|
+
let hasChanges = false;
|
|
59
|
+
// Simplify any properties where key === value
|
|
60
|
+
const simplifiedBindings = visited.bindings.elements.map(right => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const element = right.element;
|
|
63
|
+
// Check if this is a binding element (e.g., { x: x })
|
|
64
|
+
if (element.kind === tree_1.JS.Kind.BindingElement) {
|
|
65
|
+
const binding = element;
|
|
66
|
+
// Check if the property name is an identifier
|
|
67
|
+
if (((_a = binding.propertyName) === null || _a === void 0 ? void 0 : _a.element.kind) === java_1.J.Kind.Identifier) {
|
|
68
|
+
const propName = binding.propertyName.element.simpleName;
|
|
69
|
+
// Check if the binding name is also an identifier with the same name
|
|
70
|
+
if (((_b = binding.name) === null || _b === void 0 ? void 0 : _b.kind) === java_1.J.Kind.Identifier) {
|
|
71
|
+
const bindingName = binding.name.simpleName;
|
|
72
|
+
// If they match, simplify to shorthand syntax
|
|
73
|
+
if (propName === bindingName) {
|
|
74
|
+
hasChanges = true;
|
|
75
|
+
// Remove propertyName and transfer its prefix to the name
|
|
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 the pattern with simplified bindings
|
|
87
|
+
return (0, immer_1.produce)(visited, draft => {
|
|
88
|
+
draft.bindings.elements = simplifiedBindings;
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.SimplifyObjectBindingProperties = SimplifyObjectBindingProperties;
|
|
97
|
+
//# sourceMappingURL=simplify-object-binding-properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simplify-object-binding-properties.js","sourceRoot":"","sources":["../../../src/javascript/cleanup/simplify-object-binding-properties.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,yCAAoC;AAGpC,wCAA6C;AAC7C,qCAA6B;AAC7B,kCAA2B;AAC3B,iCAA8B;AAE9B;;;;;;;GAOG;AACH,MAAa,+BAAgC,SAAQ,eAAM;IAA3D;;QACI,SAAI,GAAG,uEAAuE,CAAC;QAC/E,gBAAW,GAAG,oCAAoC,CAAC;QACnD,gBAAW,GAAG,qIAAqI,CAAC;IA4DxJ,CAAC;IA1DS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,2BAAmC;gBACxC,yBAAyB,CAAC,OAAgC,EAAE,CAAmB;;;;;wBAC3F,oCAAoC;wBACpC,MAAM,OAAO,GAAG,MAAM,OAAM,yBAAyB,YAAC,OAAO,EAAE,CAAC,CAA4B,CAAC;wBAE7F,IAAI,UAAU,GAAG,KAAK,CAAC;wBAEvB,8CAA8C;wBAC9C,MAAM,kBAAkB,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;;4BAC7D,MAAM,OAAO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AC;KAAA;CACJ;AA/DD,0EA+DC"}
|
package/dist/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
8.68.0-20251127-
|
|
1
|
+
8.68.0-20251127-184755
|
package/package.json
CHANGED
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 {SimplifyObjectBindingProperties} = 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(SimplifyObjectBindingProperties);
|
|
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 {SimplifyObjectBindingProperties} from "./simplify-object-binding-properties";
|
|
@@ -0,0 +1,96 @@
|
|
|
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 binding properties where the key and value have the same name.
|
|
27
|
+
*
|
|
28
|
+
* Examples:
|
|
29
|
+
* - `{ x: x }` becomes `{ x }`
|
|
30
|
+
* - `{ ref: ref, ...props }` becomes `{ ref, ...props }`
|
|
31
|
+
* - `{ foo: foo, bar: bar }` becomes `{ foo, bar }`
|
|
32
|
+
*/
|
|
33
|
+
export class SimplifyObjectBindingProperties extends Recipe {
|
|
34
|
+
name = "org.openrewrite.javascript.cleanup.simplify-object-binding-properties";
|
|
35
|
+
displayName = "Simplify object binding properties";
|
|
36
|
+
description = "Simplifies object destructuring patterns where the property name and variable name are the same (e.g., `{ x: x }` becomes `{ x }`).";
|
|
37
|
+
|
|
38
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
39
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
40
|
+
protected async visitObjectBindingPattern(pattern: JS.ObjectBindingPattern, p: ExecutionContext): Promise<J | undefined> {
|
|
41
|
+
// First, recursively visit children
|
|
42
|
+
const visited = await super.visitObjectBindingPattern(pattern, p) as JS.ObjectBindingPattern;
|
|
43
|
+
|
|
44
|
+
let hasChanges = false;
|
|
45
|
+
|
|
46
|
+
// Simplify any properties where key === value
|
|
47
|
+
const simplifiedBindings = visited.bindings.elements.map(right => {
|
|
48
|
+
const element = right.element;
|
|
49
|
+
|
|
50
|
+
// Check if this is a binding element (e.g., { x: x })
|
|
51
|
+
if (element.kind === JS.Kind.BindingElement) {
|
|
52
|
+
const binding = element as JS.BindingElement;
|
|
53
|
+
|
|
54
|
+
// Check if the property name is an identifier
|
|
55
|
+
if (binding.propertyName?.element.kind === J.Kind.Identifier) {
|
|
56
|
+
const propName = (binding.propertyName.element as J.Identifier).simpleName;
|
|
57
|
+
|
|
58
|
+
// Check if the binding name is also an identifier with the same name
|
|
59
|
+
if (binding.name?.kind === J.Kind.Identifier) {
|
|
60
|
+
const bindingName = (binding.name as J.Identifier).simpleName;
|
|
61
|
+
|
|
62
|
+
// If they match, simplify to shorthand syntax
|
|
63
|
+
if (propName === bindingName) {
|
|
64
|
+
hasChanges = true;
|
|
65
|
+
// Remove propertyName and transfer its prefix to the name
|
|
66
|
+
return {
|
|
67
|
+
...right,
|
|
68
|
+
element: {
|
|
69
|
+
...binding,
|
|
70
|
+
propertyName: undefined,
|
|
71
|
+
name: {
|
|
72
|
+
...binding.name,
|
|
73
|
+
prefix: binding.propertyName.element.prefix
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} as J.RightPadded<JS.BindingElement>;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return right;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!hasChanges) {
|
|
86
|
+
return visited;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Return the pattern with simplified bindings
|
|
90
|
+
return produce(visited, draft => {
|
|
91
|
+
draft.bindings.elements = simplifiedBindings;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|