| 207 | } |
| 208 | |
| 209 | function runOnJsText(js, pretty = false) { |
| 210 | const ast = acorn.parse(js, {ecmaVersion: 2021}); |
| 211 | |
| 212 | optPassRemoveRedundantOperatorNews(ast); |
| 213 | |
| 214 | let progress = true; |
| 215 | while (progress) { |
| 216 | progress = optPassMergeVarDeclarations(ast); |
| 217 | progress = progress || optPassMergeVarInitializationAssignments(ast); |
| 218 | progress = progress || optPassMergeEmptyVarDeclarators(ast); |
| 219 | } |
| 220 | |
| 221 | optPassSimplifyModularizeFunction(ast); |
| 222 | |
| 223 | const terserAst = terser.AST_Node.from_mozilla_ast(ast); |
| 224 | const output = terserAst.print_to_string({ |
| 225 | wrap_func_args: false, |
| 226 | beautify: pretty, |
| 227 | indent_level: pretty ? 2 : 0, |
| 228 | }); |
| 229 | |
| 230 | return output; |
| 231 | } |
| 232 | |
| 233 | function runOnFile(input, pretty = false, output = null) { |
| 234 | let js = fs.readFileSync(input).toString(); |