Skip to content

Commit

Permalink
chore(code-gen): prefer Object.keys over Object.entries
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkdev98 committed Jun 4, 2023
1 parent 99d9968 commit 63f71b0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/code-gen/src/database/erd.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function databaseERDWriteModel(generateContext, file, model) {
const relations = modelRelationGetOwn(model);
const relationKeys = relations.map((it) => it.ownKey);

for (const [key, field] of Object.entries(model.keys)) {
for (const key of Object.keys(model.keys)) {
const field = model.keys[key];
const type =
field.type === "reference"
? structureResolveReference(generateContext.structure, field).type
Expand Down
3 changes: 2 additions & 1 deletion packages/code-gen/src/database/js-postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ export function jsPostgresGenerateInsert(
fileWrite(file, `str.push("(");`);
fileBlockEnd(file);

for (const [key, field] of Object.entries(model.keys)) {
for (const key of Object.keys(model.keys)) {
const field = model.keys[key];
const hasSqlDefault = referenceUtilsGetProperty(generateContext, field, [
"sql",
"hasDefaultValue",
Expand Down
3 changes: 2 additions & 1 deletion packages/code-gen/src/database/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ function databasePostgresWriteModelDDL(generateContext, file, model) {

let hasWrittenALine = false;

for (const [key, field] of Object.entries(model.keys)) {
for (const key of Object.keys(model.keys)) {
const field = model.keys[key];
if (hasWrittenALine) {
fileWrite(file, ",");
} else {
Expand Down
9 changes: 6 additions & 3 deletions packages/code-gen/src/router/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export function routerGenerator(generateContext) {

const nameMap = new Map();

for (const [group, routes] of Object.entries(routesPerGroup)) {
for (const group of Object.keys(routesPerGroup)) {
const routes = routesPerGroup[group];
const file = targetCustomSwitch(
{
jsKoa: jsKoaGetControllerFile,
Expand All @@ -111,11 +112,13 @@ export function routerGenerator(generateContext) {
};

const result = {};
for (const [prefix, type] of Object.entries(types)) {
if (!type) {
for (const prefix of Object.keys(types)) {
if (!types[prefix]) {
continue;
}

const type = types[prefix];

const specificTargets =
prefix === "response"
? typeTargets
Expand Down
12 changes: 6 additions & 6 deletions packages/code-gen/src/router/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ function routeMatcherChildren(file, trie, { matchPathIndex, paramsOnMatch }) {
`if (matchPath.length === ${matchPathIndex + segments.length})`,
);

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

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

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

delete paramsOnMatch[child.paramName ?? ""];
} else if (child.prio === "WILDCARD") {
for (const [key, index] of Object.entries(paramsOnMatch)) {
fileWrite(file, `params.${key} = matchPath[${index}];`);
for (const key of Object.keys(paramsOnMatch)) {
fileWrite(file, `params.${key} = matchPath[${paramsOnMatch[key]}];`);
}
fileWrite(
file,
Expand Down
3 changes: 2 additions & 1 deletion packages/code-gen/src/router/js-koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ export function jsKoaBuildRouterFile(file, routesPerGroup, contextNamesMap) {
fileWrite(file, `const routes = {`);
fileContextSetIndent(file, 1);

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

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

Expand Down

0 comments on commit 63f71b0

Please sign in to comment.