Skip to content

Commit 3e2e4cc

Browse files
committed
Prefer for loop to filter/map/foreach
1 parent 3c0f61e commit 3e2e4cc

File tree

1 file changed

+14
-13
lines changed
  • src/transformation/visitors/helpers

1 file changed

+14
-13
lines changed

src/transformation/visitors/helpers/multi.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as ts from "typescript";
22
import * as lua from "../../../LuaAST";
33
import * as helpers from "../../utils/helpers";
4-
import { isNonNull } from "../../../utils";
54
import { TransformationContext } from "../../context";
65
import { transformAssignmentLeftHandSideExpression } from "../binary-expression/assignments";
76
import { transformIdentifier } from "../identifier";
@@ -166,17 +165,19 @@ export function findMultiHelperAssignmentViolations(
166165
context: TransformationContext,
167166
node: ts.ObjectLiteralExpression
168167
): ts.Node[] {
169-
return node.properties
170-
.filter(ts.isShorthandPropertyAssignment)
171-
.map(element => {
172-
const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(element);
173-
if (valueSymbol) {
174-
const declaration = valueSymbol.valueDeclaration;
175-
if (declaration && isMultiFunctionDeclaration(declaration)) {
176-
context.diagnostics.push(invalidMultiFunctionUse(element));
177-
return element;
178-
}
168+
const result: ts.Node[] = [];
169+
170+
for (const element of node.properties) {
171+
if (!ts.isShorthandPropertyAssignment(element)) continue;
172+
const valueSymbol = context.checker.getShorthandAssignmentValueSymbol(element);
173+
if (valueSymbol) {
174+
const declaration = valueSymbol.valueDeclaration;
175+
if (declaration && isMultiFunctionDeclaration(declaration)) {
176+
context.diagnostics.push(invalidMultiFunctionUse(element));
177+
result.push(element);
179178
}
180-
})
181-
.filter(isNonNull);
179+
}
180+
}
181+
182+
return result;
182183
}

0 commit comments

Comments
 (0)