Skip to content

Commit 48dcf17

Browse files
authored
Cleanup tools/acorn-optimizer.js. NFC (#17387)
1 parent 8c3fe4d commit 48dcf17

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

tools/acorn-optimizer.js

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ function visitChildren(node, c) {
4949
}
5050
return false;
5151
}
52-
for (const key in node) {
52+
for (const child of Object.values(node)) {
5353
// Check for a child.
54-
if (Object.prototype.hasOwnProperty.call(node, key)) {
55-
const child = node[key];
56-
if (!maybeChild(child)) {
57-
// Check for an array of children.
58-
if (Array.isArray(child)) {
59-
child.forEach(maybeChild);
60-
}
54+
if (!maybeChild(child)) {
55+
// Check for an array of children.
56+
if (Array.isArray(child)) {
57+
child.forEach(maybeChild);
6158
}
6259
}
6360
}
@@ -429,14 +426,11 @@ function runJSDCE(ast, aggressive) {
429426
assert(scopes.length === 0);
430427

431428
const names = {};
432-
for (const name in scope) {
433-
if (Object.prototype.hasOwnProperty.call(scope, name)) {
434-
const data = scope[name];
435-
if (data.def && !data.use) {
436-
assert(!data.param); // can't be
437-
// this is eliminateable!
438-
names[name] = 0;
439-
}
429+
for (const [name, data] of Object.entries(scope)) {
430+
if (data.def && !data.use) {
431+
assert(!data.param); // can't be
432+
// this is eliminateable!
433+
names[name] = 0;
440434
}
441435
}
442436
cleanUp(ast, names);
@@ -797,26 +791,24 @@ function emitDCEGraph(ast) {
797791
return 'emcc$' + what + '$' + name;
798792
}
799793
const infos = {}; // the graph name of the item => info for it
800-
imports.forEach((import_) =>{
794+
for (const import_ of imports) {
801795
const name = getGraphName(import_, 'import');
802796
const info = infos[name] = {
803797
name: name,
804798
import: ['env', import_],
805799
reaches: {},
806800
};
807-
if (Object.prototype.hasOwnProperty.call(nameToGraphName, import_)) {
801+
if (nameToGraphName.hasOwnProperty(import_)) {
808802
info.reaches[nameToGraphName[import_]] = 1;
809803
} // otherwise, it's a number, ignore
810-
});
811-
for (const e in exportNameToGraphName) {
812-
if (Object.prototype.hasOwnProperty.call(exportNameToGraphName, e)) {
813-
const name = exportNameToGraphName[e];
814-
infos[name] = {
815-
name: name,
816-
export: e,
817-
reaches: {},
818-
};
819-
}
804+
}
805+
for (const [e, name] of Object.entries(exportNameToGraphName)) {
806+
const name = exportNameToGraphName[e];
807+
infos[name] = {
808+
name: name,
809+
export: e,
810+
reaches: {},
811+
};
820812
}
821813
// a function that handles a node we visit, in either a defun or
822814
// the toplevel scope (in which case the second param is not provided)
@@ -826,12 +818,12 @@ function emitDCEGraph(ast) {
826818
let reached;
827819
if (node.type === 'Identifier') {
828820
const name = node.name;
829-
if (Object.prototype.hasOwnProperty.call(nameToGraphName, name)) {
821+
if (nameToGraphName.hasOwnProperty(name)) {
830822
reached = nameToGraphName[name];
831823
}
832824
} else if (isModuleUse(node)) {
833825
const name = getAsmOrModuleUseName(node);
834-
if (Object.prototype.hasOwnProperty.call(modulePropertyToGraphName, name)) {
826+
if (modulePropertyToGraphName.hasOwnProperty(name)) {
835827
reached = modulePropertyToGraphName[name];
836828
}
837829
} else if (isStaticDynCall(node)) {
@@ -842,7 +834,7 @@ function emitDCEGraph(ast) {
842834
} else if (isAsmUse(node)) {
843835
// any remaining asm uses are always rooted in any case
844836
const name = getAsmOrModuleUseName(node);
845-
if (Object.prototype.hasOwnProperty.call(exportNameToGraphName, name)) {
837+
if (exportNameToGraphName.hasOwnProperty(name)) {
846838
infos[exportNameToGraphName[name]].root = true;
847839
}
848840
return;
@@ -885,10 +877,8 @@ function emitDCEGraph(ast) {
885877
// sort for determinism
886878
function sortedNamesFromMap(map) {
887879
const names = [];
888-
for (const name in map) {
889-
if (Object.prototype.hasOwnProperty.call(map, name)) {
890-
names.push(name);
891-
}
880+
for (const name of Object.keys(map)) {
881+
names.push(name);
892882
}
893883
names.sort();
894884
return names;

0 commit comments

Comments
 (0)