diff --git a/test/test_other.py b/test/test_other.py index 01e4828d25360..fc2507091312b 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -13547,7 +13547,7 @@ def test_clock_nanosleep(self): # Tests the internal test suite of tools/unsafe_optimizations.js def test_unsafe_optimizations(self): - self.run_process(config.NODE_JS_TEST + [path_from_root('tools', 'unsafe_optimizations.js'), '--test']) + self.run_process(config.NODE_JS_TEST + [path_from_root('tools', 'unsafe_optimizations.mjs'), '--test']) @requires_v8 def test_extended_const(self): diff --git a/tools/link.py b/tools/link.py index de7e7972da314..677cba5c9ad1d 100644 --- a/tools/link.py +++ b/tools/link.py @@ -2075,7 +2075,7 @@ def phase_final_emitting(options, state, target, wasm_target): # optimize by Closure, or unoptimalities that were left behind by processing # steps that occurred after Closure. if settings.MINIMAL_RUNTIME == 2 and settings.USE_CLOSURE_COMPILER and settings.DEBUG_LEVEL == 0: - shared.run_js_tool(utils.path_from_root('tools/unsafe_optimizations.js'), [final_js, '-o', final_js], cwd=utils.path_from_root('.')) + shared.run_js_tool(utils.path_from_root('tools/unsafe_optimizations.mjs'), [final_js, '-o', final_js], cwd=utils.path_from_root('.')) save_intermediate('unsafe-optimizations') # Finally, rerun Closure compile with simple optimizations. It will be able # to further minify the code. (n.b. it would not be safe to run in advanced @@ -2083,7 +2083,7 @@ def phase_final_emitting(options, state, target, wasm_target): final_js = building.closure_compiler(final_js, advanced=False, extra_closure_args=options.closure_args) # Run unsafe_optimizations.js once more. This allows the cleanup of newly # unused things that closure compiler leaves behind (e.g `new Float64Array(x)`). - shared.run_js_tool(utils.path_from_root('tools/unsafe_optimizations.js'), [final_js, '-o', final_js], cwd=utils.path_from_root('.')) + shared.run_js_tool(utils.path_from_root('tools/unsafe_optimizations.mjs'), [final_js, '-o', final_js], cwd=utils.path_from_root('.')) save_intermediate('unsafe-optimizations2') fix_es6_import_statements(final_js) diff --git a/tools/unsafe_optimizations.js b/tools/unsafe_optimizations.mjs old mode 100644 new mode 100755 similarity index 98% rename from tools/unsafe_optimizations.js rename to tools/unsafe_optimizations.mjs index 67d1d67a2dfa0..f2738a7ffddca --- a/tools/unsafe_optimizations.js +++ b/tools/unsafe_optimizations.mjs @@ -3,11 +3,9 @@ /** Implements a set of potentially unsafe JavaScript AST optimizations for aggressive code size optimizations. Enabled when building with -sMINIMAL_RUNTIME=2 linker flag. */ -'use strict'; - -const acorn = require('acorn'); -const fs = require('fs'); -const terser = require('../third_party/terser/terser'); +import * as fs from 'fs'; +import * as acorn from 'acorn'; +import * as terser from '../third_party/terser/terser.js'; // Starting at the AST node 'root', calls the given callback function 'func' on all children and grandchildren of 'root' // that are of any of the type contained in array 'types'.