Skip to content

Commit 196aa2d

Browse files
authored
Convert compiler.js to JS module. NFC. (#20861)
1 parent 6fe2510 commit 196aa2d

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

src/compiler.js renamed to src/compiler.mjs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
// LLVM => JavaScript compiler, main entry point
99

10-
const fs = require('fs');
11-
globalThis.vm = require('vm');
12-
globalThis.assert = require('assert');
13-
globalThis.nodePath = require('path');
10+
import * as fs from 'fs';
11+
import * as path from 'path';
12+
import * as vm from 'vm';
13+
import * as url from 'url';
14+
import assert from 'assert';
15+
16+
globalThis.vm = vm;
17+
globalThis.assert = assert;
18+
globalThis.nodePath = path;
1419

1520
globalThis.print = (x) => {
1621
process.stdout.write(x + '\n');
@@ -22,9 +27,10 @@ globalThis.printErr = (x) => {
2227

2328
function find(filename) {
2429
assert(filename);
25-
const prefixes = [__dirname, process.cwd()];
30+
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
31+
const prefixes = [dirname, process.cwd()];
2632
for (let i = 0; i < prefixes.length; ++i) {
27-
const combined = nodePath.join(prefixes[i], filename);
33+
const combined = path.join(prefixes[i], filename);
2834
if (fs.existsSync(combined)) {
2935
return combined;
3036
}
@@ -96,7 +102,7 @@ if (!STRICT) {
96102
// Main
97103
// ===============================
98104

99-
B = new Benchmarker();
105+
const B = new Benchmarker();
100106

101107
try {
102108
runJSify();

src/utility.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function isPowerOfTwo(x) {
233233
}
234234

235235
/** @constructor */
236-
function Benchmarker() {
236+
globalThis.Benchmarker = function() {
237237
const totals = {};
238238
const ids = [];
239239
const lastTime = 0;

tools/emscripten.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def compile_javascript(symbols_only=False):
190190
args = [settings_file]
191191
if symbols_only:
192192
args += ['--symbols-only']
193-
out = shared.run_js_tool(path_from_root('src/compiler.js'),
193+
out = shared.run_js_tool(path_from_root('src/compiler.mjs'),
194194
args, stdout=subprocess.PIPE, stderr=stderr_file,
195195
cwd=path_from_root('src'), env=env, encoding='utf-8')
196196
if symbols_only:

tools/link.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def generate_js_sym_info():
241241
# mode of the js compiler that would generate a list of all possible symbols
242242
# that could be checked in.
243243
_, forwarded_data = emscripten.compile_javascript(symbols_only=True)
244-
# When running in symbols_only mode compiler.js outputs a flat list of C symbols.
244+
# When running in symbols_only mode compiler.mjs outputs a flat list of C symbols.
245245
return json.loads(forwarded_data)
246246

247247

tools/maint/gen_sig_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def extract_sig_info(sig_info, extra_settings=None, extra_cflags=None, cxx=False
314314
settings.update(extra_settings)
315315
with tempfiles.get_file('.json') as settings_json:
316316
utils.write_file(settings_json, json.dumps(settings))
317-
output = shared.run_js_tool(utils.path_from_root('src/compiler.js'),
317+
output = shared.run_js_tool(utils.path_from_root('src/compiler.mjs'),
318318
['--symbols-only', settings_json],
319319
stdout=subprocess.PIPE, cwd=utils.path_from_root())
320320
symbols = json.loads(output)['deps'].keys()

tools/toolchain_profiler.results_template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
ret.concat([out]);
218218
}
219219
return ret;
220-
} else if (startsWith(basename, 'compiler.js')) {
220+
} else if (startsWith(basename, 'compiler.mjs')) {
221221
var posParams = findPositionalParams(cmdLine, []);
222222
var interestingParams = [];
223223
for(var i = 1; i < posParams.length; ++i) {

0 commit comments

Comments
 (0)