Skip to content

Commit eab9db1

Browse files
authored
Simplify acorn-optimizer pass mapping. NFC (#22000)
1 parent d3eaa8d commit eab9db1

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

tools/acorn-optimizer.mjs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function hasSideEffects(node) {
270270
// as they appear (like ArrowFunctionExpression). Instead, we do a conservative
271271
// analysis here.
272272

273-
function runJSDCE(ast, aggressive) {
273+
function JSDCE(ast, aggressive) {
274274
function iteration() {
275275
let removed = 0;
276276
const scopes = [{}]; // begin with empty toplevel scope
@@ -457,8 +457,8 @@ function runJSDCE(ast, aggressive) {
457457
}
458458

459459
// Aggressive JSDCE - multiple iterations
460-
function runAJSDCE(ast) {
461-
runJSDCE(ast, /* aggressive= */ true);
460+
function AJSDCE(ast) {
461+
JSDCE(ast, /* aggressive= */ true);
462462
}
463463

464464
function isWasmImportsAssign(node) {
@@ -2000,6 +2000,11 @@ function trace(...args) {
20002000
}
20012001
}
20022002

2003+
function error(...args) {
2004+
console.error(...args);
2005+
throw new Error(...args);
2006+
}
2007+
20032008
// If enabled, output retains parentheses and comments so that the
20042009
// output can further be passed out to Closure.
20052010
const closureFriendly = getArg('--closure-friendly');
@@ -2051,23 +2056,26 @@ try {
20512056
}
20522057

20532058
const registry = {
2054-
JSDCE: runJSDCE,
2055-
AJSDCE: runAJSDCE,
2056-
applyImportAndExportNameChanges: applyImportAndExportNameChanges,
2057-
emitDCEGraph: emitDCEGraph,
2058-
applyDCEGraphRemovals: applyDCEGraphRemovals,
2059-
dump: () => dump(ast),
2060-
littleEndianHeap: littleEndianHeap,
2061-
growableHeap: growableHeap,
2062-
unsignPointers: unsignPointers,
2063-
minifyLocals: minifyLocals,
2064-
asanify: asanify,
2065-
safeHeap: safeHeap,
2066-
minifyGlobals: minifyGlobals,
2059+
JSDCE,
2060+
AJSDCE,
2061+
applyImportAndExportNameChanges,
2062+
emitDCEGraph,
2063+
applyDCEGraphRemovals,
2064+
dump,
2065+
littleEndianHeap,
2066+
growableHeap,
2067+
unsignPointers,
2068+
minifyLocals,
2069+
asanify,
2070+
safeHeap,
2071+
minifyGlobals,
20672072
};
20682073

20692074
passes.forEach((pass) => {
20702075
trace(`running AST pass: ${pass}`);
2076+
if (!(pass in registry)) {
2077+
error(`unknown optimizer pass: ${pass}`);
2078+
}
20712079
registry[pass](ast);
20722080
});
20732081

0 commit comments

Comments
 (0)