Skip to content

Commit

Permalink
Simplify / DRY.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfuzz committed Oct 1, 2024
1 parent 080e3c3 commit b52424b
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/util/export/BaseValueVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,31 +434,24 @@ export class BaseValueVisitor {
const isArray = Array.isArray(result);
const promNames = [];

for (const name of Object.getOwnPropertyNames(node)) {
if (!(isArray && (name === 'length'))) {
const got = this.#visitNode(node[name]);
if (got.ok === null) {
promNames.push(name);
result[name] = got.promise;
} else if (got.ok) {
result[name] = got.result;
} else {
throw got.error;
const addResults = (iter) => {
for (const name of iter) {
if (!(isArray && (name === 'length'))) {
const got = this.#visitNode(node[name]);
if (got.ok === null) {
promNames.push(name);
result[name] = got.promise;
} else if (got.ok) {
result[name] = got.result;
} else {
throw got.error;
}
}
}
}
};

for (const name of Object.getOwnPropertySymbols(node)) {
const got = this.#visitNode(node[name]);
if (got.ok === null) {
promNames.push(name);
result[name] = got.promise;
} else if (got.ok) {
result[name] = got.result;
} else {
throw got.error;
}
}
addResults(Object.getOwnPropertyNames(node));
addResults(Object.getOwnPropertySymbols(node));

if (promNames.length === 0) {
return result;
Expand Down

0 comments on commit b52424b

Please sign in to comment.