(filename, passes, extra_info=None, return_output=False, worker_js=False)
| 393 | |
| 394 | # run JS optimizer on some JS, ignoring asm.js contents if any - just run on it all |
| 395 | def acorn_optimizer(filename, passes, extra_info=None, return_output=False, worker_js=False): |
| 396 | optimizer = path_from_root('tools/acorn-optimizer.mjs') |
| 397 | original_filename = filename |
| 398 | if extra_info is not None and not shared.SKIP_SUBPROCS: |
| 399 | temp_files = shared.get_temp_files() |
| 400 | temp = temp_files.get('.js', prefix='emcc_acorn_info_').name |
| 401 | shutil.copyfile(filename, temp) |
| 402 | with open(temp, 'a', encoding='utf-8') as f: |
| 403 | f.write('// EXTRA_INFO: ' + json.dumps(extra_info)) |
| 404 | filename = temp |
| 405 | cmd = [*config.NODE_JS, optimizer, filename, *passes] |
| 406 | if not worker_js: |
| 407 | # Keep JS code comments intact through the acorn optimization pass so that |
| 408 | # JSDoc comments will be carried over to a later Closure run. |
| 409 | if settings.MAYBE_CLOSURE_COMPILER: |
| 410 | cmd += ['--closure-friendly'] |
| 411 | if settings.EXPORT_ES6: |
| 412 | cmd += ['--export-es6'] |
| 413 | if settings.VERBOSE: |
| 414 | cmd += ['--verbose'] |
| 415 | if return_output: |
| 416 | if shared.SKIP_SUBPROCS: |
| 417 | shared.print_compiler_stage(cmd) |
| 418 | return '' |
| 419 | return check_call(cmd, stdout=PIPE).stdout |
| 420 | |
| 421 | acorn_optimizer.counter += 1 |
| 422 | basename = utils.unsuffixed(original_filename) |
| 423 | if '.jso' in basename: |
| 424 | basename = utils.unsuffixed(basename) |
| 425 | output_file = basename + '.jso%d.js' % acorn_optimizer.counter |
| 426 | shared.get_temp_files().note(output_file) |
| 427 | cmd += ['-o', output_file] |
| 428 | if shared.SKIP_SUBPROCS: |
| 429 | shared.print_compiler_stage(cmd) |
| 430 | return output_file |
| 431 | check_call(cmd) |
| 432 | save_intermediate(output_file, '%s.js' % passes[0]) |
| 433 | return output_file |
| 434 | |
| 435 | |
| 436 | acorn_optimizer.counter = 0 # type: ignore |
no test coverage detected