Skip to content

Commit f239241

Browse files
committed
use for of to iterate
1 parent 76a6db6 commit f239241

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

lib/javascript/prefer-class-properties.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ new Synvert.Rewriter("javascript", "prefer-class-properties", function () {
8484
},
8585
);
8686

87-
functions.forEach((func) => {
87+
for (const func of functions) {
8888
const source = indentCode(
8989
`${this.mutationAdapter.getSource(func.left.name)} = ${this.mutationAdapter.getSource(func.right, {
9090
fixIndent: true,
9191
})}`,
9292
tabSize,
9393
);
9494
insert(`\n\n${source.replace(/function ?/, "").replace(/\) {/, ") => {")}`, { at: "end" });
95-
});
95+
}
9696

97-
arrowFunctions.forEach((arrowFunction) => {
97+
for (const arrowFunction of arrowFunctions) {
9898
const source = indentCode(
9999
`${this.mutationAdapter.getSource(arrowFunction.left.name)} = ${this.mutationAdapter.getSource(
100100
arrowFunction.right,
@@ -103,7 +103,7 @@ new Synvert.Rewriter("javascript", "prefer-class-properties", function () {
103103
tabSize,
104104
);
105105
insert(`\n\n${source}`, { at: "end" });
106-
});
106+
}
107107
});
108108

109109
// handleChange() {}

lib/react/prefer-class-properties.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ new Synvert.Rewriter("react", "prefer-class-properties", () => {
9999
},
100100
);
101101

102-
functions.forEach((func) => {
102+
for (const func of functions) {
103103
const source = indentCode(
104104
`${this.mutationAdapter.getSource(func.left.name)} = ${this.mutationAdapter.getSource(func.right, {
105105
fixIndent: true,
106106
})}`,
107107
tabSize,
108108
);
109109
insert(`\n\n${source.replace(/function ?/, "").replace(/\) {/, ") => {")}`, { at: "end" });
110-
});
110+
}
111111

112-
arrowFunctions.forEach((arrowFunction) => {
112+
for (const arrowFunction of arrowFunctions) {
113113
const source = indentCode(
114114
`${this.mutationAdapter.getSource(arrowFunction.left.name)} = ${this.mutationAdapter.getSource(
115115
arrowFunction.right,
@@ -118,7 +118,7 @@ new Synvert.Rewriter("react", "prefer-class-properties", () => {
118118
tabSize,
119119
);
120120
insert(`\n\n${source}`, { at: "end" });
121-
});
121+
}
122122
});
123123

124124
// handleChange() {}

lib/react/transform-class-components-to-functions.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => {
4242
findNode(
4343
".VariableDeclarationList[declarations.length=1][declarations.0.initializer=.PropertyAccessExpression[expression=this][name=props]]",
4444
() => {
45-
this.currentNode.declarations[0].name.elements.forEach((element) =>
46-
addThisProp(currentFilePath, this.mutationAdapter.getSource(element)),
47-
);
45+
for (const element of this.currentNode.declarations[0].name.elements) {
46+
addThisProp(currentFilePath, this.mutationAdapter.getSource(element));
47+
}
4848
},
4949
);
5050

@@ -55,7 +55,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => {
5555

5656
// state = { key: value };
5757
findNode(".PropertyDeclaration[name=state]", () => {
58-
this.currentNode.initializer.properties.forEach((property) => {
58+
for (const property of this.currentNode.initializer.properties) {
5959
const name = property.name.escapedText;
6060
const value = this.mutationAdapter.getSource(property.initializer);
6161
functionBody.push(
@@ -64,7 +64,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => {
6464
1,
6565
),
6666
);
67-
});
67+
}
6868
});
6969

7070
// foo = () => {}
@@ -84,15 +84,15 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => {
8484
if (lifecycleMethods.length > 0) {
8585
functionBody.push(addLeadingSpaces("// Synvert TODO: convert lifecycle methods to useEffect by yourself"));
8686
setUseEffect(currentFilePath);
87-
lifecycleMethods.forEach((lifecycleMethod) => {
87+
for (const lifecycleMethod of lifecycleMethods) {
8888
const lines = this.mutationAdapter.getSource(lifecycleMethod, { fixIndent: true }).split("\n");
8989
functionBody.push(
9090
indentCode(
9191
lines.map((line) => (line.length > 0 ? "// " + line : "//")).join("\n"),
9292
1,
9393
),
9494
);
95-
});
95+
}
9696
}
9797

9898
// render() {}
@@ -218,9 +218,9 @@ ${functionBody.join("\n")}
218218
() => {
219219
const tabWidth = this.mutationAdapter.getIndent(this.currentNode) / Synvert.Configuration.tabWidth;
220220
const body = [];
221-
this.currentNode.declarations[0].initializer.body.statements.forEach((statement) => {
221+
for (const statement of this.currentNode.declarations[0].initializer.body.statements) {
222222
body.push(this.mutationAdapter.getSource(statement, { fixIndent: true }));
223-
});
223+
}
224224
replaceWith(indentCode(body.join("\n"), tabWidth, { skipFirstLine: true }));
225225
},
226226
);

0 commit comments

Comments
 (0)