Skip to content

Commit

Permalink
Convert unsafe_optimizations.js to mjs. NFC (#21504)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Mar 11, 2024
1 parent 2ba2078 commit 8b94b9e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
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

0 comments on commit 8b94b9e

Please sign in to comment.