Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert unsafe_optimizations.js to mjs. NFC #21504

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2075,15 +2075,15 @@ 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
# mode)
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)
Expand Down
8 changes: 3 additions & 5 deletions tools/unsafe_optimizations.js → tools/unsafe_optimizations.mjs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
Loading