Skip to content

Commit

Permalink
Convert acorn-optimizer to JS module. NFC (emscripten-core#20851)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Dec 6, 2023
1 parent 3482cd0 commit 8b0b7bf
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ jobs:
test_targets: "
other.test_gen_struct_info
other.test_native_call_before_init
other.test_js_optimizer_verbose
other.test_node_unhandled_rejection
other.test_full_js_library*
core2.test_hello_world"
Expand All @@ -768,6 +769,7 @@ jobs:
other.test_gen_struct_info
other.test_native_call_before_init
other.test_node_unhandled_rejection
other.test_js_optimizer_verbose
other.test_min_node_version
other.test_node_emscripten_num_logical_cores
core2.test_pthread_create
Expand Down
2 changes: 1 addition & 1 deletion src/library_getvalue.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var LibraryMemOps = {

#if SAFE_HEAP
// The same as the above two functions, but known to the safeHeap pass
// in tools/acorn-optimizer.js. The heap accesses within these two
// in tools/acorn-optimizer.mjs. The heap accesses within these two
// functions will *not* get re-written.
// Note that we do not use the alias mechanism here since we need separate
// instances of above setValueImpl/getValueImpl functions.
Expand Down
2 changes: 1 addition & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,7 @@ def test_js_optimizer(self, input, passes):
input = test_file(input)
expected_file = os.path.splitext(input)[0] + '-output.js'
# test calling optimizer
js = self.run_process(config.NODE_JS + [path_from_root('tools/acorn-optimizer.js'), input] + passes, stdin=PIPE, stdout=PIPE).stdout
js = self.run_process(config.NODE_JS + [path_from_root('tools/acorn-optimizer.mjs'), input] + passes, stdin=PIPE, stdout=PIPE).stdout
if common.EMTEST_REBASELINE:
write_file(expected_file, js)
else:
Expand Down
2 changes: 1 addition & 1 deletion third_party/terser/terser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6706,7 +6706,7 @@ const _NOINLINE = 0b00000100;
const _KEY = 0b00001000;
const _MANGLEPROP = 0b00010000;

// XXX Emscripten: export TreeWalker for walking through AST in acorn-optimizer.js.
// XXX Emscripten: export TreeWalker for walking through AST in acorn-optimizer.mjs.
exports.TreeWalker = TreeWalker;

/***********************************************************************
Expand Down
8 changes: 3 additions & 5 deletions tools/acorn-optimizer.js → tools/acorn-optimizer.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env node

'use strict';

const acorn = require('acorn');
const terser = require('../third_party/terser/terser');
const fs = require('fs');
import * as acorn from 'acorn';
import * as terser from '../third_party/terser/terser.js';
import * as fs from 'fs';

// Utilities

Expand Down
4 changes: 2 additions & 2 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def js_optimizer(filename, passes):

# run JS optimizer on some JS, ignoring asm.js contents if any - just run on it all
def acorn_optimizer(filename, passes, extra_info=None, return_output=False):
optimizer = path_from_root('tools/acorn-optimizer.js')
optimizer = path_from_root('tools/acorn-optimizer.mjs')
original_filename = filename
if extra_info is not None:
temp_files = shared.get_temp_files()
Expand Down Expand Up @@ -579,7 +579,7 @@ def closure_compiler(filename, advanced=True, extra_closure_args=None):
CLOSURE_EXTERNS += [path_from_root('src/closure-externs/minimal_runtime_worker_externs.js')]

args = ['--compilation_level', 'ADVANCED_OPTIMIZATIONS' if advanced else 'SIMPLE_OPTIMIZATIONS']
# Keep in sync with ecmaVersion in tools/acorn-optimizer.js
# Keep in sync with ecmaVersion in tools/acorn-optimizer.mjs
args += ['--language_in', 'ECMASCRIPT_2021']
# Tell closure not to do any transpiling or inject any polyfills.
# At some point we may want to look into using this as way to convert to ES5 but
Expand Down
6 changes: 3 additions & 3 deletions tools/js_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
temp_files = shared.get_temp_files()


ACORN_OPTIMIZER = path_from_root('tools/acorn-optimizer.js')
ACORN_OPTIMIZER = path_from_root('tools/acorn-optimizer.mjs')

NUM_CHUNKS_PER_CORE = 3
MIN_CHUNK_SIZE = int(os.environ.get('EMCC_JSOPT_MIN_CHUNK_SIZE') or 512 * 1024) # configuring this is just for debugging purposes
Expand Down Expand Up @@ -65,7 +65,7 @@ def split_funcs(js):

class Minifier:
"""minification support. We calculate minification of
globals here, then pass that into the parallel acorn-optimizer.js runners which
globals here, then pass that into the parallel acorn-optimizer.mjs runners which
perform minification of locals.
"""

Expand All @@ -75,7 +75,7 @@ def __init__(self, js):
self.profiling_funcs = False

def minify_shell(self, shell, minify_whitespace):
# Run through acorn-optimizer.js to find and minify the global symbols
# Run through acorn-optimizer.mjs to find and minify the global symbols
# We send it the globals, which it parses at the proper time. JS decides how
# to minify all global names, we receive a dictionary back, which is then
# used by the function processors
Expand Down

0 comments on commit 8b0b7bf

Please sign in to comment.