MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / acorn_optimizer

Function acorn_optimizer

tools/building.py:395–433  ·  view source on GitHub ↗
(filename, passes, extra_info=None, return_output=False, worker_js=False)

Source from the content-addressed store, hash-verified

393
394# run JS optimizer on some JS, ignoring asm.js contents if any - just run on it all
395def 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
436acorn_optimizer.counter = 0 # type: ignore

Callers 8

minify_wasm_jsFunction · 0.85
metadceFunction · 0.85
little_endian_heapFunction · 0.85
apply_wasm_memory_growthFunction · 0.85
instrument_js_for_asanFunction · 0.85

Calls 7

path_from_rootFunction · 0.85
check_callFunction · 0.85
noteMethod · 0.80
save_intermediateFunction · 0.70
getMethod · 0.65
openFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected