Skip to content

Commit 63f71b0

Browse files
committed
chore(code-gen): prefer Object.keys over Object.entries
1 parent 99d9968 commit 63f71b0

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

packages/code-gen/src/database/erd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ function databaseERDWriteModel(generateContext, file, model) {
5555
const relations = modelRelationGetOwn(model);
5656
const relationKeys = relations.map((it) => it.ownKey);
5757

58-
for (const [key, field] of Object.entries(model.keys)) {
58+
for (const key of Object.keys(model.keys)) {
59+
const field = model.keys[key];
5960
const type =
6061
field.type === "reference"
6162
? structureResolveReference(generateContext.structure, field).type

packages/code-gen/src/database/js-postgres.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ export function jsPostgresGenerateInsert(
668668
fileWrite(file, `str.push("(");`);
669669
fileBlockEnd(file);
670670

671-
for (const [key, field] of Object.entries(model.keys)) {
671+
for (const key of Object.keys(model.keys)) {
672+
const field = model.keys[key];
672673
const hasSqlDefault = referenceUtilsGetProperty(generateContext, field, [
673674
"sql",
674675
"hasDefaultValue",

packages/code-gen/src/database/postgres.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function databasePostgresWriteModelDDL(generateContext, file, model) {
9797

9898
let hasWrittenALine = false;
9999

100-
for (const [key, field] of Object.entries(model.keys)) {
100+
for (const key of Object.keys(model.keys)) {
101+
const field = model.keys[key];
101102
if (hasWrittenALine) {
102103
fileWrite(file, ",");
103104
} else {

packages/code-gen/src/router/generator.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export function routerGenerator(generateContext) {
8484

8585
const nameMap = new Map();
8686

87-
for (const [group, routes] of Object.entries(routesPerGroup)) {
87+
for (const group of Object.keys(routesPerGroup)) {
88+
const routes = routesPerGroup[group];
8889
const file = targetCustomSwitch(
8990
{
9091
jsKoa: jsKoaGetControllerFile,
@@ -111,11 +112,13 @@ export function routerGenerator(generateContext) {
111112
};
112113

113114
const result = {};
114-
for (const [prefix, type] of Object.entries(types)) {
115-
if (!type) {
115+
for (const prefix of Object.keys(types)) {
116+
if (!types[prefix]) {
116117
continue;
117118
}
118119

120+
const type = types[prefix];
121+
119122
const specificTargets =
120123
prefix === "response"
121124
? typeTargets

packages/code-gen/src/router/javascript.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ function routeMatcherChildren(file, trie, { matchPathIndex, paramsOnMatch }) {
106106
`if (matchPath.length === ${matchPathIndex + segments.length})`,
107107
);
108108

109-
for (const [key, index] of Object.entries(paramsOnMatch)) {
110-
fileWrite(file, `params.${key} = matchPath[${index}];`);
109+
for (const key of Object.keys(paramsOnMatch)) {
110+
fileWrite(file, `params.${key} = matchPath[${paramsOnMatch[key]}];`);
111111
}
112112
fileWrite(
113113
file,
@@ -134,8 +134,8 @@ function routeMatcherChildren(file, trie, { matchPathIndex, paramsOnMatch }) {
134134

135135
fileBlockStart(file, `(matchPath.length === ${matchPathIndex + 1})`);
136136

137-
for (const [key, index] of Object.entries(paramsOnMatch)) {
138-
fileWrite(file, `params.${key} = matchPath[${index}];`);
137+
for (const key of Object.keys(paramsOnMatch)) {
138+
fileWrite(file, `params.${key} = matchPath[${paramsOnMatch[key]}];`);
139139
}
140140
fileWrite(
141141
file,
@@ -151,8 +151,8 @@ function routeMatcherChildren(file, trie, { matchPathIndex, paramsOnMatch }) {
151151

152152
delete paramsOnMatch[child.paramName ?? ""];
153153
} else if (child.prio === "WILDCARD") {
154-
for (const [key, index] of Object.entries(paramsOnMatch)) {
155-
fileWrite(file, `params.${key} = matchPath[${index}];`);
154+
for (const key of Object.keys(paramsOnMatch)) {
155+
fileWrite(file, `params.${key} = matchPath[${paramsOnMatch[key]}];`);
156156
}
157157
fileWrite(
158158
file,

packages/code-gen/src/router/js-koa.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,11 @@ export function jsKoaBuildRouterFile(file, routesPerGroup, contextNamesMap) {
258258
fileWrite(file, `const routes = {`);
259259
fileContextSetIndent(file, 1);
260260

261-
for (const [group, routes] of Object.entries(routesPerGroup)) {
261+
for (const group of Object.keys(routesPerGroup)) {
262262
fileWrite(file, `${group}: {`);
263263
fileContextSetIndent(file, 1);
264264

265+
const routes = routesPerGroup[group];
265266
for (const route of routes) {
266267
const contextNames = contextNamesMap.get(route) ?? {};
267268

0 commit comments

Comments
 (0)